Skip to content

Commit

Permalink
fix: Solve reported SonarCloud issues
Browse files Browse the repository at this point in the history
Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek committed Apr 2, 2024
1 parent da696ec commit 8793ffb
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 23 deletions.
12 changes: 6 additions & 6 deletions packages/extester/src/suite/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ export class VSRunner {
const newSegments = dest.split(path.sep);

let found = false;
for (let i = 0; i < segments.length; i++) {
for (let segment of segments) {
if (!found) {
found = segments[i] === dir.base;
found = segment === dir.base;
} else {
newSegments.push(segments[i]);
newSegments.push(segment);
}
}
return path.join(dir.root, ...newSegments);
Expand All @@ -132,9 +132,9 @@ export class VSRunner {
let file = config;
if (!config) {
file = path.resolve('.')
for (let i = 0; i < defaultFiles.length; i++) {
if (fs.existsSync(path.join(file, defaultFiles[i]))) {
file = path.join(file, defaultFiles[i]);
for (let defFile of defaultFiles) {
if (fs.existsSync(path.join(file, defFile))) {
file = path.join(file, defFile);
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/extester/src/util/driverUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ export class DriverUtil {
const command = `${this.getChromeDriverBinaryPath(version)} -v`;
return new Promise<string>((resolve, reject) => {
child_process.exec(command, (err, stdout) => {
if (err) return reject(err);
if (err) {
return reject(new Error(err.message));
}
resolve(stdout.split(' ')[1]);
});
});
Expand Down
11 changes: 8 additions & 3 deletions packages/extester/src/util/unpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ export class Unpack {
src: input.toString(),
dest: target.toString()
}, (err: string | Error | null) => {
err ? reject(err) : resolve();
if(err) {
const errWho = err instanceof Error ? err : new Error(err);
reject(errWho);
} else {
resolve()
}
});
}
else if (input.toString().endsWith('.zip')) {
fs.mkdirpSync(target.toString());
if(process.platform === 'darwin' || process.platform === 'linux') {
exec(`cd ${target} && unzip -qo ${input.toString()}`, (err) => {
if (err) {
reject(err);
reject(new Error(err.message));
} else {
resolve();
}
Expand All @@ -27,7 +32,7 @@ export class Unpack {
else {
exec(`cd ${target} && tar -xvf ${input.toString()}`, (err) => {
if (err) {
reject(err);
reject(new Error(err.message));
} else {
resolve();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/page-objects/src/components/AbstractElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Locators } from "../locators/locators";
*/
export abstract class AbstractElement extends WebElement {

public static ctlKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL;
public static readonly ctlKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL;
protected static driver: WebDriver;
protected static locators: Locators;
protected static versionInfo: { version: string, browser: string };
Expand Down
2 changes: 1 addition & 1 deletion packages/page-objects/src/components/bottomBar/Views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class TerminalView extends ChannelView {
return;
}

const matches = name.match(/.*(\d+).?\s.*/);
const matches = /.*(\d+).?\s.*/.exec(name);
if (matches === null || !matches[1]) {
throw new Error(`Channel ${name} not found`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ContentAssist extends Menu {
if (await item.getLabel() === name) {
return item;
}
lastItem = lastItem ? lastItem : (await item.getAttribute('data-last-element')) === 'true';
lastItem = lastItem || (await item.getAttribute('data-last-element')) === 'true';
}
if (!lastItem) {
await scrollable.sendKeys(Key.PAGE_DOWN);
Expand Down
8 changes: 4 additions & 4 deletions packages/page-objects/src/components/editor/SettingsEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ export class ComboSetting extends Setting {

async setValue(value: string): Promise<void> {
const rows = await this.getOptions();
for (let i = 0; i < rows.length; i++) {
if ((await rows[i].getAttribute('class')).indexOf('disabled') < 0) {
const text = await (await rows[i].findElement(SettingsEditor.locators.SettingsEditor.comboOption)).getText();
for (let row of rows) {
if ((await row.getAttribute('class')).indexOf('disabled') < 0) {
const text = await (await row.findElement(SettingsEditor.locators.SettingsEditor.comboOption)).getText();
if (value === text) {
return await rows[i].click();
return await row.click();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/page-objects/src/components/editor/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class TextEditor extends Editor {
let actions = this.getDriver().actions();
await actions.clear();
actions.keyDown(Key.SHIFT);
for (let i = 0; i < text.length; i++) {
for (const _i of text) {
actions = actions.sendKeys(Key.RIGHT);
}
actions = actions.keyUp(Key.SHIFT);
Expand Down
4 changes: 2 additions & 2 deletions packages/page-objects/src/components/editor/WebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class WebViewBase extends Editor {
const containers = await this.getDriver().wait(until.elementsLocated(WebViewBase.locators.WebView.container(await reference.getAttribute(WebViewBase.locators.WebView.attribute))), 5000);

return await containers[0].getDriver().wait(async () => {
for (let index = 0; index < containers.length; index++) {
const tries = await containers[index].findElements(WebViewBase.locators.WebView.iframe);
for (let container of containers) {
const tries = await container.findElements(WebViewBase.locators.WebView.iframe);
if (tries.length > 0) {
return tries[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export abstract class Input extends AbstractElement {
*/
async toggleAllQuickPicks(state: boolean): Promise<void> {
const checkboxes = await this.findElements(Input.locators.Input.quickPickSelectAll);
if (checkboxes.length < 0) {
if (!checkboxes) {
return;
}
if (!await checkboxes[0].isSelected()) {
Expand Down
4 changes: 2 additions & 2 deletions packages/page-objects/src/locators/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export class LocatorLoader {
.sort(compareVersions).reverse();
}

for (let i = 0; i < versions.length; i++) {
const diff = require(path.join(this.baseFolder, versions[i])).diff as LocatorDiff;
for (let version of versions) {
const diff = require(path.join(this.baseFolder, version)).diff as LocatorDiff;

const newLocators: Merge<Locators, PartialDeep<Locators>> = mergeLocators(this.locators, diff);
this.locators = newLocators as RequiredDeep<Merge<Locators, PartialDeep<Locators>>>;
Expand Down

0 comments on commit 8793ffb

Please sign in to comment.