diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index ea8464b..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "env": { - "node": true, - "commonjs": false, - "es6": true, - "mocha": true - }, - "extends": "eslint:recommended", - "rules": { - "comma-dangle": 0, - "no-unused-vars": "warn", - "no-unexpected-multiline": "warn", - "no-console": 1, - "quotes": [ - "error", - "single" - ], - "semi": [ - "error", - "always" - ] - }, - "parserOptions": { - "ecmaVersion": 2022, - "sourceType": "module", - "ecmaFeatures": { - "experimentalObjectRestSpread": true - } - } -} \ No newline at end of file diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..29ac66d --- /dev/null +++ b/eslint.config.js @@ -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 + } + } + } +]; \ No newline at end of file diff --git a/package.json b/package.json index b03a6d1..6ebd044 100644 --- a/package.json +++ b/package.json @@ -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" @@ -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" }, diff --git a/src/lib/remote.js b/src/lib/remote.js index 7f9db62..1615858 100644 --- a/src/lib/remote.js +++ b/src/lib/remote.js @@ -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; } } @@ -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); } diff --git a/src/lib/snapshot.js b/src/lib/snapshot.js index 17d9a11..fe84a40 100644 --- a/src/lib/snapshot.js +++ b/src/lib/snapshot.js @@ -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}`); } }; diff --git a/src/lib/utils/payloadReader.js b/src/lib/utils/payloadReader.js index 65f1cde..9f9255f 100644 --- a/src/lib/utils/payloadReader.js +++ b/src/lib/utils/payloadReader.js @@ -1,15 +1,17 @@ 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; }, []); } @@ -17,7 +19,7 @@ export function payloadReader(payload) { export function parseJSON(str) { try { return JSON.parse(str); - } catch (e) { + } catch { return undefined; } } \ No newline at end of file diff --git a/src/lib/utils/timed-match/index.js b/src/lib/utils/timed-match/index.js index 751dc7b..d1137fe 100644 --- a/src/lib/utils/timed-match/index.js +++ b/src/lib/utils/timed-match/index.js @@ -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; @@ -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, diff --git a/test/helper/utils.js b/test/helper/utils.js index 250ecb9..11ae4c7 100644 --- a/test/helper/utils.js +++ b/test/helper/utils.js @@ -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)); } diff --git a/test/playground/index.js b/test/playground/index.js index 21a8b8c..48019e6 100644 --- a/test/playground/index.js +++ b/test/playground/index.js @@ -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';