Skip to content

Commit

Permalink
chore: migrated eslint to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki committed Aug 20, 2024
1 parent bfe8c71 commit 490cefe
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 48 deletions.
30 changes: 0 additions & 30 deletions .eslintrc.json

This file was deleted.

24 changes: 24 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import js from '@eslint/js';
import globals from 'globals';

export default [
{
...js.configs.recommended,
files: ['src/**/*.js']
},
{
files: ['src/**/*.js'],
rules: {
quotes: ['error', 'single'],
semi: ['error', 'always'],
curly: ['error', 'multi-line'],
},
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: {
...globals.node
}
}
}
];
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
],
"license": "MIT",
"scripts": {
"lint": "eslint ./src/ --ext .js",
"test-local": "mocha",
"lint": "eslint ./src/**/*.js ./test/**/*.js",
"test": "npm run coverage \"./test/**/*.test.js\"",
"coverage": "c8 --include='src/**/*.js' mocha",
"play": "node ./test/playground/index.js"
Expand All @@ -31,12 +30,12 @@
],
"devDependencies": {
"@babel/eslint-parser": "^7.25.1",
"@typescript-eslint/eslint-plugin": "^8.0.1",
"@typescript-eslint/parser": "^8.0.1",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"c8": "^10.1.2",
"chai": "^5.1.1",
"eslint": "^8.57.0",
"mocha": "^10.7.0",
"eslint": "^9.9.0",
"mocha": "^10.7.3",
"mocha-sonarqube-reporter": "^1.0.2",
"sinon": "^18.0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions src/lib/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function checkAPIHealth(url) {
try {
const response = await FetchFacade.fetch(`${url}/check`, { method: 'get', agent: httpClient });
return response.status == 200;
} catch (e) {
} catch {
return false;
}
}
Expand Down Expand Up @@ -116,8 +116,9 @@ export async function checkSwitchers(switcherKeys) {
}

const json = response.json();
if (json.not_found.length)
if (json.not_found.length) {
throw new CheckSwitcherError(json.not_found);
}
} catch (e) {
throw new CriteriaError(e.errno ? getConnectivityError(e.errno) : e.message);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const loadDomain = (snapshotLocation, environment) => {

const dataJSON = dataBuffer.toString();
return JSON.parse(dataJSON);
} catch (e) {
} catch {
throw new Error(`Something went wrong: It was not possible to load the file at ${snapshotLocation}`);
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/lib/utils/payloadReader.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
export function payloadReader(payload) {
let payloadRead = payload + '' === payload || payload || 0;
if (Array.isArray(payloadRead))
if (Array.isArray(payloadRead)) {
return payloadRead.flatMap(p => payloadReader(p));
}

return Object.keys(payloadRead)
.flatMap(field => [field, ...payloadReader(payload[field])
.map(nestedField => `${field}.${nestedField}`)])
.filter(field => isNaN(Number(field)))
.reduce((acc, curr) => {
if (!acc.includes(curr))
if (!acc.includes(curr)) {
acc.push(curr);
}
return acc;
}, []);
}

export function parseJSON(str) {
try {
return JSON.parse(str);
} catch (e) {
} catch {
return undefined;
}
}
6 changes: 4 additions & 2 deletions src/lib/utils/timed-match/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ export default class TimedMatch {
let result = false;
let timer, resolveListener;

if (this._isBlackListed({ values, input }))
if (this._isBlackListed({ values, input })) {
return false;
}

const matchPromise = new Promise((resolve) => {
resolveListener = resolve;
Expand Down Expand Up @@ -123,8 +124,9 @@ export default class TimedMatch {
this._worker.kill();
this._worker = this._createChildProcess();

if (this._blacklisted.length == this._maxBlackListed)
if (this._blacklisted.length == this._maxBlackListed) {
this._blacklisted.splice(0, 1);
}

this._blacklisted.push({
res: values,
Expand Down
1 change: 0 additions & 1 deletion test/helper/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'node:fs';

/* eslint-disable no-console */
export function given(fetchStub, order, expect) {
fetchStub.onCall(order).returns(Promise.resolve(expect));
}
Expand Down
3 changes: 0 additions & 3 deletions test/playground/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* eslint-disable no-unused-vars */
/* eslint-disable no-console */

import { Client } from '../../switcher-client.js';
import { sleep } from '../helper/utils.js';

Expand Down

0 comments on commit 490cefe

Please sign in to comment.