Skip to content

Commit 958d4ba

Browse files
committed
sonar cleanup
1 parent b2bad8d commit 958d4ba

15 files changed

+61
-78
lines changed

electron/app/js/fsUtils.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,15 @@ async function removeDirectoryRecursively(directoryToDelete) {
5555
exists(directoryToDelete)
5656
.then(doesExist => {
5757
if (doesExist) {
58-
fsPromises.rm(directoryToDelete, {
59-
force: true,
60-
recursive: true
61-
})
62-
.then(() => {
63-
exists(directoryToDelete).then(stillExists => {
64-
if (!stillExists) {
65-
resolve(!stillExists);
66-
} else {
67-
reject(`Failed to completely remove directory ${directoryToDelete}`);
68-
}
69-
}).catch(err => reject(err));
58+
fsPromises.rm(directoryToDelete, { force: true, recursive: true }).then(() => {
59+
exists(directoryToDelete).then(stillExists => {
60+
if (!stillExists) {
61+
resolve(true);
62+
} else {
63+
reject(`Failed to completely remove directory ${directoryToDelete}`);
64+
}
7065
}).catch(err => reject(err));
66+
}).catch(err => reject(err));
7167
} else {
7268
resolve(false);
7369
}

electron/app/js/project.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,9 @@ function _addOpenProject(targetWindow, file, pending, credentialManager) {
732732
// assign project file to window if none is assigned, or file path changes.
733733
// avoid unnecessary reassignments in order to keep credential manager between saves.
734734
function _assignProjectFile(targetWindow, projectFile) {
735-
const openProject = openProjects.get(targetWindow);
736-
const oldFile = openProject ? openProject.projectDirectory + '|' + openProject.projectFile : '';
737-
const newFile = path.resolve(path.dirname(projectFile)) + '|' + path.basename(projectFile);
735+
const existingProject = openProjects.get(targetWindow);
736+
const oldFile = existingProject ? `${existingProject.projectDirectory}|${existingProject.projectFile}` : '';
737+
const newFile = `${path.resolve(path.dirname(projectFile))}|${path.basename(projectFile)}`;
738738
if (newFile !== oldFile) {
739739
_addOpenProject(targetWindow, projectFile, false);
740740
}

electron/app/js/wktApp.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,16 @@ class WktApp {
7474
throw new Error(`Failed to read version file ${versionFilePath}: ${errorUtils.getErrorMessage(err)}`);
7575
}
7676

77-
let version;
77+
let buildVersion;
7878
if (!contents) {
79-
version = defaultVersion;
79+
buildVersion = defaultVersion;
8080
} else if (contents.startsWith('-')) {
8181
// dev build so concatenate the app version with the qualifier from the file
82-
version = `${defaultVersion}${contents.trim()}`;
82+
buildVersion = `${defaultVersion}${contents.trim()}`;
8383
} else {
8484
return contents.trim();
8585
}
86-
return version;
86+
return buildVersion;
8787
}
8888
}
8989

electron/app/js/wktLogging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function _getLogFileMaxFiles(fileLogConfig) {
284284

285285
function _getMustacheVariables(text) {
286286
const mustacheVariables = [];
287-
const mustacheRegex = /{{([a-zA-Z0-9\\_\\-\\.]+)}}/g;
287+
const mustacheRegex = /{{([a-zA-Z0-9_.-]+)}}/g;
288288

289289
if (text) {
290290
let match = mustacheRegex.exec(text);

electron/app/test/wktApp-test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ describe('WKT App tests', () => {
4646
const WktMode = proxyquire('../js/wktMode', { electron: electronStub });
4747

4848
function getDefaultVersionNumber() {
49-
const packageJsonFileName = path.normalize(path.join(__dirname, '..', '..', 'package.json'));
50-
const packageJson = require(packageJsonFileName);
5149
const wktuiVersionFileName = path.normalize(path.join(__dirname, '..', '..', '..', 'WKTUI_VERSION.txt'));
5250
const qualifier = readFileSync(wktuiVersionFileName, { encoding: 'utf8'});
5351
return `${packageJson.version}${qualifier.trim()}`;

electron/build/notarize.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function getAppId(context) {
6161
}
6262

6363
exports.default = async function notarizing(context) {
64-
const { electronPlatformName, appOutDir } = context;
64+
const { electronPlatformName } = context;
6565
if (electronPlatformName !== 'darwin' || process.env.CSC_IDENTITY_AUTO_DISCOVERY === 'false') {
6666
return;
6767
}

webui/scripts/hooks/after_build.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const sourceDirectories = [
2626
const targetDirectory = path.normalize(path.join(__dirname, '..', '..', '..', 'electron', 'app'));
2727

2828
module.exports = function (configObj) {
29-
return new Promise(async (resolve, reject) => {
29+
return new Promise(async (resolve) => {
3030
console.log("Running after_build hook.");
3131
console.log('Purging unnecessary files created by the build...');
3232
for (const purgeLocation of purgeLocations) {
@@ -38,7 +38,7 @@ module.exports = function (configObj) {
3838
// Write the webui.json file that contains data
3939
// that the electron side needs during startup.
4040
//
41-
const webuiJsonCreated = await generateWebuiJsonFile(webuiJsonDirectory);
41+
const webuiJsonCreated = await generateWebuiJsonFile();
4242
if (webuiJsonCreated) {
4343
await moveFileToDirectory(webuiJsonFile, targetDirectory);
4444
}
@@ -59,19 +59,19 @@ module.exports = function (configObj) {
5959
async function copyDirectoryRecursively(source, target) {
6060
let files = []
6161

62-
let targetDirectory = path.join(target, path.basename(source));
63-
if (!fs.existsSync(targetDirectory)) {
64-
await mkdir(targetDirectory);
62+
let _targetDirectory = path.join(target, path.basename(source));
63+
if (!fs.existsSync(_targetDirectory)) {
64+
await mkdir(_targetDirectory);
6565
}
6666

6767
if (await isDirectory(source)) {
6868
files = await readdir(source);
6969
for (const file of files) {
7070
const currentSource = path.join(source, file);
7171
if (await isDirectory(currentSource)) {
72-
await copyDirectoryRecursively(currentSource, targetDirectory);
72+
await copyDirectoryRecursively(currentSource, _targetDirectory);
7373
} else {
74-
await moveFileToDirectory(currentSource, targetDirectory);
74+
await moveFileToDirectory(currentSource, _targetDirectory);
7575
}
7676
}
7777
} else {
@@ -87,8 +87,8 @@ async function moveFileToDirectory(source, target) {
8787
await rename(source, targetFile);
8888
}
8989

90-
async function isDirectory(path) {
91-
const result = await fsPromises.lstat(path).catch(err => {
90+
async function isDirectory(testPath) {
91+
const result = await fsPromises.lstat(testPath).catch(err => {
9292
if (err.code === 'ENOENT') {
9393
return false;
9494
}
@@ -108,7 +108,7 @@ async function generateWebuiJsonFile() {
108108
await mkdir(targetDirectory);
109109
}
110110

111-
return new Promise((resolve, reject) => {
111+
return new Promise((resolve) => {
112112
fsPromises.writeFile(webuiJsonFile, JSON.stringify(contents, null, 2), {
113113
encoding: 'utf8',
114114
mode: 0o644

webui/src/js/utils/ingress-resource-generator.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,27 +138,15 @@ define(['models/wkt-project', 'js-yaml'],
138138
}
139139

140140
isSSLTerminateAtIngress(item) {
141-
if (item && item['tlsOption'] === 'ssl_terminate_ingress') {
142-
return true;
143-
} else {
144-
return false;
145-
}
141+
return (item && item['tlsOption'] === 'ssl_terminate_ingress');
146142
}
147143

148144
isSSLPassThrough(item) {
149-
if (item && item['tlsOption'] === 'ssl_passthrough') {
150-
return true;
151-
} else {
152-
return false;
153-
}
145+
return (item && item['tlsOption'] === 'ssl_passthrough');
154146
}
155147

156148
isPlainHTTP(item) {
157-
if (item && item['tlsOption'] === 'plain') {
158-
return true;
159-
} else {
160-
return false;
161-
}
149+
return (item && item['tlsOption'] === 'plain');
162150
}
163151

164152
createTraefikMiddlewaresAsYaml(item) {

webui/src/js/utils/observable-properties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ define(['knockout', 'utils/common-utilities', 'utils/validation-helper', 'utils/
693693
}
694694

695695
function escape(s) {
696-
return /[,;\n\s]/.test(s) ? `"${s}"` : s;
696+
return /[,;\s]/.test(s) ? `"${s}"` : s;
697697
}
698698

699699
function arrayToString(array) {

webui/src/js/utils/validation-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,15 +369,15 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
369369
}
370370
}
371371

372-
const K8S_MEMORY_REGEX = /^[1-9]\d*((E|P|T|G|M|K)i?)?$/;
372+
const K8S_MEMORY_REGEX = /^[1-9]\d*([EPTGMK]i?)?$/;
373373
const K8S_MEMORY_HELP_URL = 'https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-memory';
374374
function _validateK8sMemoryValue(value) {
375375
if (value && !K8S_MEMORY_REGEX.test(value)) {
376376
throw new Error(i18n.t('validation-helper-k8s-memory-error', { value: value, url: K8S_MEMORY_HELP_URL }));
377377
}
378378
}
379379

380-
const JAVA_MEMORY_REGEX = /^[1-9]\d*(k|K|m|M|g|G)?$/;
380+
const JAVA_MEMORY_REGEX = /^[1-9]\d*[kKmMgG]?$/;
381381
const JAVA_MEMORY_HELP_URL = 'https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html#BABDJJFI';
382382
function _validateJavaMemoryValue(value) {
383383
if (value && !JAVA_MEMORY_REGEX.test(value)) {

webui/src/js/viewModels/route-edit-dialog.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
122122
return nextIndex;
123123
});
124124

125-
const annotations = this.route.annotations;
126-
if (annotations) {
127-
Object.keys(annotations).forEach(key => {
125+
const routeAnnotations = this.route.annotations;
126+
if (routeAnnotations) {
127+
Object.keys(routeAnnotations).forEach(key => {
128128
const nextUid = getAnnotationUid(this.nextAnnotationIndex());
129-
const annotation = {uid: nextUid, key: key, value: annotations[key]};
129+
const annotation = {uid: nextUid, key: key, value: routeAnnotations[key]};
130130
this.annotations.addNewItem(annotation);
131131
});
132132
}
@@ -177,16 +177,16 @@ function(accUtils, ko, i18n, project, viewHelper, ArrayDataProvider, BufferingDa
177177
return Object.entries(one).sort().toString() !== Object.entries(two).sort().toString();
178178
}
179179

180-
function addOrDeleteAnnotation(annotations, addAction, key, value, deleteKey) {
180+
function addOrDeleteAnnotation(currentAnnotations, addAction, key, value, deleteKey) {
181181
if (addAction) {
182-
annotations[key] = value;
182+
currentAnnotations[key] = value;
183183
} else {
184-
if (key in annotations) {
185-
delete annotations[key];
184+
if (key in currentAnnotations) {
185+
delete currentAnnotations[key];
186186
}
187187
}
188-
if (deleteKey in annotations) {
189-
delete annotations[deleteKey];
188+
if (deleteKey in currentAnnotations) {
189+
delete currentAnnotations[deleteKey];
190190
}
191191
}
192192

webui/src/test/model-page-test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,27 @@ describe('model-page', function () {
4040
parentRouter: {
4141
createChildRouter: function() {
4242
return {
43-
sync: function() {},
44-
go: function() {}
43+
sync: function() { /* This is intentionally empty */ },
44+
go: function() { /* This is intentionally empty */ }
4545
};
4646
}
4747
}
4848
};
4949

50-
function ModuleRouterAdapterStub() {
51-
}
50+
function ModuleRouterAdapterStub() { /* This is intentionally empty */ }
5251

5352
beforeEach(function () {
5453
viewModel = new ModelPageImpl(args, accUtilsStub, ko, i18next, ModuleRouterAdapterStub, ArrayDataProviderStub);
5554
});
5655

5756
function getEntry(array, key, value) {
58-
for (let i = 0; i < array.length; i++) {
59-
if (array[i][key] === value) return array[i];
57+
let result = undefined;
58+
for (const item of array) {
59+
if (item[key] === value) {
60+
result = item;
61+
}
6062
}
61-
return undefined;
63+
return result;
6264
}
6365

6466
function entry(array, key, value) {

webui/src/test/observable-properties-test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ describe('observable-properties-support', function () {
779779
it('looks to Oracle JET like an observable array', function () {
780780
expect(typeof property.observable).to.equal('function');
781781
expect(!!property.observable.subscribe).to.equal(true);
782-
expect(!(property.observable['destroyAll'] === undefined)).to.equal(true);
782+
expect(property.observable['destroyAll'] !== undefined).to.equal(true);
783783
});
784784

785785
it('initially is not changed', function () {
@@ -955,11 +955,11 @@ describe('observable-properties-support', function () {
955955
});
956956

957957
it('when value set, is marked changed', function() {
958-
const property = utils.createArrayProperty(['foo', 'bar', 'baz']);
958+
const _property = utils.createArrayProperty(['foo', 'bar', 'baz']);
959959

960-
property.value = NEW_DATA;
960+
_property.value = NEW_DATA;
961961

962-
expect(property.isChanged()).to.be.true;
962+
expect(_property.isChanged()).to.be.true;
963963
});
964964

965965
it('when value changed, value to persist matches it', function() {
@@ -1119,14 +1119,13 @@ describe('observable-properties-support', function () {
11191119
name: utils.createProperty('fred'),
11201120
friends: utils.createArrayProperty(['joe']),
11211121
size: utils.createProperty(7),
1122-
eventual: utils.createProperty(() => new Promise((resolve) => resolve('Yay!'))),
1122+
eventual: utils.createProperty(() => Promise.resolve('Yay!')),
11231123
ignore: utils.createProperty(() => {
11241124
throw new Error('called initializer');
11251125
}),
11261126
execs: utils.createListProperty(['name', 'title'])
11271127
.withDefaultValue([{name: 'George', title: 'POTUS'}, {name: 'John', title: 'VEEP'}]),
1128-
doIt: function () {
1129-
}
1128+
doIt: function () { /* This is intentionally empty */ }
11301129
};
11311130
});
11321131

webui/src/test/window-stub.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ const os = require('os');
1111

1212
class WindowStub {
1313
constructor() {
14+
// This is intentionally empty
1415
}
1516

16-
trial() {}
17+
trial() { /* This is intentionally empty */ }
1718

1819
static install(jsDom) {
1920
this._isWindows = false;

webui/src/test/wkt-project-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ describe('wkt-project', function () {
1919
requirejs(['models/wkt-project'],
2020
function (module) {
2121
project = module;
22-
project.updateModels = () => {
23-
};
22+
project.updateModels = () => { /* This is intentionally empty */ };
2423
done();
2524
});
2625
});

0 commit comments

Comments
 (0)