diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 1bd39b795..000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,43 +0,0 @@ -module.exports = { - root: true, - env: { - node: true, - es2020: true, - commonjs: true, - es6: true, - jquery: false, - jest: true, - jasmine: false - }, - extends: [ - "eslint:recommended", - "plugin:security/recommended-legacy", - "plugin:prettier/recommended" - ], - parserOptions: { - sourceType: "module", - ecmaVersion: "2023" - }, - plugins: ["node", "promise", "security"], - rules: { - "no-var": ["error"], - "no-console": ["error"], - "no-unused-vars": ["warn"], - "no-trailing-spaces": ["error"], - "security/detect-object-injection": ["off"], - "security/detect-non-literal-require": ["off"], - "security/detect-non-literal-fs-filename": ["off"], - "no-process-exit": ["off"], - "node/no-unpublished-require": 0 - }, - ignorePatterns: ["benchmark/test.js", "test/typescript/hello-world/out/*.js"], - overrides: [ - { - files: ["runner-esm.mjs"], - parserOptions: { - sourceType: "module", - ecmaVersion: "2020" // needed to allow import.meta - } - } - ] -}; diff --git a/benchmark/.eslintrc.js b/benchmark/.eslintrc.js deleted file mode 100644 index ed25d7aae..000000000 --- a/benchmark/.eslintrc.js +++ /dev/null @@ -1,18 +0,0 @@ -module.exports = { - env: { - node: true, - commonjs: true, - es6: true - }, - extends: ["eslint:recommended"], - parserOptions: { - sourceType: "module", - ecmaVersion: 2018 - }, - rules: { - "no-var": ["warn"], - "no-console": ["off"], - "no-unused-vars": ["off"], - "security/detect-possible-timing-attacks": ["off"] - } -}; diff --git a/benchmark/memleak-test.js b/benchmark/memleak-test.js index fe730e0c6..8a649dac5 100644 --- a/benchmark/memleak-test.js +++ b/benchmark/memleak-test.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; const kleur = require("kleur"); diff --git a/benchmark/perf-runner.js b/benchmark/perf-runner.js index 3da14ae95..1cdb8adac 100644 --- a/benchmark/perf-runner.js +++ b/benchmark/perf-runner.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console, no-unused-vars */ - "use strict"; const fs = require("fs"); diff --git a/benchmark/suites/serializers.js b/benchmark/suites/serializers.js index 4f279d5ae..90819fd2a 100644 --- a/benchmark/suites/serializers.js +++ b/benchmark/suites/serializers.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ "use strict"; const ServiceBroker = require("../../src/service-broker"); diff --git a/benchmark/suites/throughput.js b/benchmark/suites/throughput.js index 36e841378..f8dd29bd3 100644 --- a/benchmark/suites/throughput.js +++ b/benchmark/suites/throughput.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; const kleur = require("kleur"); diff --git a/benchmark/test.js b/benchmark/test.js deleted file mode 100644 index b6d9c8a56..000000000 --- a/benchmark/test.js +++ /dev/null @@ -1,38 +0,0 @@ -// @ts-nocheck -/* eslint-disable */ - -/** - * Call with - * $ node --trace_opt --trace_deopt --allow-natives-syntax test.js - */ - -//Function that contains the pattern to be inspected (using an `eval` statement) -function exampleFunction() { - return 3; - //eval(''); -} - -function printStatus(fn) { - const res = %GetOptimizationStatus(fn); - switch(res) { - case 1: console.log("Function is optimized"); break; - case 2: console.log("Function is not optimized"); break; - case 3: console.log("Function is always optimized"); break; - case 4: console.log("Function is never optimized"); break; - case 6: console.log("Function is maybe deoptimized"); break; - case 7: console.log("Function is optimized by TurboFan"); break; - default: console.log("Unknown optimization status", res); break; - } -} - -//Fill type-info -exampleFunction(); -// 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic -exampleFunction(); - -%OptimizeFunctionOnNextCall(exampleFunction); -//The next call -exampleFunction(); - -//Check -printStatus(exampleFunction); diff --git a/dev/.eslintrc.js b/dev/.eslintrc.js deleted file mode 100644 index 16cb8983f..000000000 --- a/dev/.eslintrc.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - env: { - node: true, - commonjs: true, - es6: true - }, - extends: ["eslint:recommended", "plugin:security/recommended", "plugin:prettier/recommended"], - parserOptions: { - sourceType: "module", - ecmaVersion: 2023 - }, - rules: { - "no-var": ["warn"], - "no-console": ["off"], - "no-unused-vars": ["off"], - "security/detect-possible-timing-attacks": ["off"], - "security/detect-non-literal-fs-filename": ["off"] - } -}; diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 000000000..85c091279 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,70 @@ +const js = require("@eslint/js"); +const globals = require("globals"); +const pluginSecurity = require('eslint-plugin-security'); + +/** @type {import('eslint').Linter.FlatConfig[]} */ +module.exports = [ + js.configs.recommended, + pluginSecurity.configs.recommended, + //"plugin:security/recommended-legacy", + //"plugin:prettier/recommended", + { + files: ["**/*.js", "**/*.mjs"], + languageOptions: { + parserOptions: { + sourceType: "module", + ecmaVersion: 2023 + }, + globals: { + ...globals.node, + ...globals.es2020, + ...globals.commonjs, + ...globals.es6, + ...globals.jquery, + ...globals.jest, + ...globals.jasmine, + process: "readonly", + fetch: "readonly" + } + }, + // plugins: ["node", "security"], + rules: { + "no-var": ["error"], + "no-console": ["error"], + "no-unused-vars": ["warn"], + "no-trailing-spaces": ["error"], + "security/detect-object-injection": ["off"], + "security/detect-non-literal-require": ["off"], + "security/detect-non-literal-fs-filename": ["off"], + "no-process-exit": ["off"], + "node/no-unpublished-require": 0 + }, + ignores: ["benchmark/test.js", "test/typescript/hello-world/out/*.js"], + }, { + files: ["test/typescript/hello-world/out/*.js"], + languageOptions: { + globals: { + exports: "readonly", + require: "readonly", + __dirname: "readonly", + console: "readonly", + process: "readonly", + } + }, + rules: { + "no-unused-vars": ["off"] + } + }, { + files: ["test/**/*.js"], + rules: { + "no-console": ["off"], + "no-unused-vars": ["off"] + } + }, { + files: ["dev/**/*.js", "benchmark/**/*.js", "examples/**/*.js"], + rules: { + "no-console": ["off"], + "no-unused-vars": ["off"] + } + } +]; diff --git a/examples/.eslintrc.js b/examples/.eslintrc.js deleted file mode 100644 index 8bb657cf8..000000000 --- a/examples/.eslintrc.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - env: { - node: true, - commonjs: true, - es6: true - }, - extends: ["eslint:recommended"], - parserOptions: { - sourceType: "module", - ecmaVersion: 2018 - }, - rules: { - "no-var": ["warn"], - "no-console": ["off"], - "no-unused-vars": ["off"], - "no-mixed-spaces-and-tabs": ["off"], - "security/detect-possible-timing-attacks": ["off"] - } -}; diff --git a/examples/client-server/client.js b/examples/client-server/client.js index 437cda588..2fe4055d4 100644 --- a/examples/client-server/client.js +++ b/examples/client-server/client.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ "use strict"; let _ = require("lodash"); diff --git a/examples/loadtest/client.js b/examples/loadtest/client.js index eca5dde4e..4dab060c1 100644 --- a/examples/loadtest/client.js +++ b/examples/loadtest/client.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; let { times, random, padStart } = require("lodash"); diff --git a/examples/loadtest/clients.js b/examples/loadtest/clients.js index 4b52b0a03..10d6b9ce5 100644 --- a/examples/loadtest/clients.js +++ b/examples/loadtest/clients.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; const os = require("os"), diff --git a/examples/loadtest/local.js b/examples/loadtest/local.js index 4e14f1084..ddac32ff9 100644 --- a/examples/loadtest/local.js +++ b/examples/loadtest/local.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; let random = require("lodash/random"); diff --git a/examples/loadtest/nats.js b/examples/loadtest/nats.js index ad4d42112..bd164b66d 100644 --- a/examples/loadtest/nats.js +++ b/examples/loadtest/nats.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - let nc1 = require("nats").connect(); let nc2 = require("nats").connect(); diff --git a/examples/loadtest/server.js b/examples/loadtest/server.js index 80259ecef..be894cb90 100644 --- a/examples/loadtest/server.js +++ b/examples/loadtest/server.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; let ServiceBroker = require("../../src/service-broker"); diff --git a/examples/middlewares/index.js b/examples/middlewares/index.js index 6b24b6d19..5439ea729 100644 --- a/examples/middlewares/index.js +++ b/examples/middlewares/index.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; let path = require("path"); diff --git a/examples/multi-nodes/master.js b/examples/multi-nodes/master.js index f748e1a67..d2a19739c 100644 --- a/examples/multi-nodes/master.js +++ b/examples/multi-nodes/master.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; const path = require("path"); diff --git a/examples/multi-nodes/node-controller.service.js b/examples/multi-nodes/node-controller.service.js index 7be3ea7e7..00e9fc44a 100644 --- a/examples/multi-nodes/node-controller.service.js +++ b/examples/multi-nodes/node-controller.service.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - const _ = require("lodash"); const kleur = require("kleur"); const cluster = require("cluster"); diff --git a/examples/multi-nodes/node.js b/examples/multi-nodes/node.js index 47d226895..ab23b8936 100644 --- a/examples/multi-nodes/node.js +++ b/examples/multi-nodes/node.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; const _ = require("lodash"); diff --git a/examples/opentelemetry/index.js b/examples/opentelemetry/index.js index 1cfd6e969..539cea10e 100644 --- a/examples/opentelemetry/index.js +++ b/examples/opentelemetry/index.js @@ -1,5 +1,3 @@ -/* eslint-disable no-console */ - "use strict"; // Instead use `-r ./tracing.js` // require("./tracing"); diff --git a/package.json b/package.json index 44cdeab03..ae662f568 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ "deps": "ncu -i --format group", "postdeps": "npm run lint:lock && npm test", "dev": "nodemon dev/index.js", - "lint": "eslint --ext=.js benchmark bin examples src test", - "lint:fix": "eslint --fix --ext=.js benchmark bin examples src test", + "lint": "eslint benchmark bin examples src test", + "lint:fix": "eslint --fix benchmark bin examples src test", "lint:lock": "lockfile-lint --path package-lock.json --type npm --validate-https --allowed-hosts npm", "perf": "nodemon --allow-natives-syntax benchmark/perf-runner.js", "pperf": "node --inspect --expose-gc benchmark/perf-runner.js", diff --git a/src/loggers/formatted.js b/src/loggers/formatted.js index 8200e77fc..41a389bbf 100644 --- a/src/loggers/formatted.js +++ b/src/loggers/formatted.js @@ -4,8 +4,6 @@ * MIT Licensed */ -/* eslint-disable no-console */ - "use strict"; const BaseLogger = require("./base"); diff --git a/src/runner-esm.mjs b/src/runner-esm.mjs index cd099288c..e0e02fd38 100644 --- a/src/runner-esm.mjs +++ b/src/runner-esm.mjs @@ -118,7 +118,7 @@ export default class MoleculerRunner { if (this.flags.envfile) dotenv.config({ path: this.flags.envfile }); else dotenv.config(); - } catch (err) { + } catch { throw new Error( "The 'dotenv' package is missing! Please install it with 'npm install dotenv --save' command." ); @@ -216,7 +216,7 @@ export default class MoleculerRunner { try { return require.resolve(configPath, resolveOptions); - } catch (_) { + } catch { return null; } } @@ -320,7 +320,7 @@ export default class MoleculerRunner { isDirectory(p) { try { return fs.lstatSync(p).isDirectory(); - } catch (_) { + } catch { // ignore } return false; @@ -335,7 +335,7 @@ export default class MoleculerRunner { isServiceFile(p) { try { return !fs.lstatSync(p).isDirectory(); - } catch (_) { + } catch { // ignore } return false; diff --git a/src/runner.js b/src/runner.js index 2d98d1c13..c0841098d 100644 --- a/src/runner.js +++ b/src/runner.js @@ -128,7 +128,7 @@ class MoleculerRunner { if (this.flags.envfile) dotenv.config({ path: this.flags.envfile }); else dotenv.config(); - } catch (err) { + } catch { throw new Error( "The 'dotenv' package is missing! Please install it with 'npm install dotenv --save' command." ); @@ -227,7 +227,7 @@ class MoleculerRunner { try { return require.resolve(configPath, resolveOptions); - } catch (_) { + } catch { return null; } } @@ -331,7 +331,7 @@ class MoleculerRunner { isDirectory(p) { try { return fs.lstatSync(p).isDirectory(); - } catch (_) { + } catch { // ignore } return false; @@ -346,7 +346,7 @@ class MoleculerRunner { isServiceFile(p) { try { return !fs.lstatSync(p).isDirectory(); - } catch (_) { + } catch { // ignore } return false; diff --git a/src/transit.js b/src/transit.js index 8e3bf8eb0..4e66c51c9 100644 --- a/src/transit.js +++ b/src/transit.js @@ -496,7 +496,6 @@ class Transit { let stream; if (payload.stream !== undefined) { stream = this._handleIncomingRequestStream(payload); - // eslint-disable-next-line security/detect-possible-timing-attacks if (stream === null) return this.Promise.resolve(); } diff --git a/test/.eslintrc.js b/test/.eslintrc.js deleted file mode 100644 index cc0baa2f4..000000000 --- a/test/.eslintrc.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - rules: { - "no-unused-vars": ["off"] - } -}; diff --git a/test/e2e/utils.js b/test/e2e/utils.js index cb1eb2d05..940b923e6 100644 --- a/test/e2e/utils.js +++ b/test/e2e/utils.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ const _ = require("lodash"); const kleur = require("kleur"); const fs = require("fs"); diff --git a/test/integration/tracing.spec.js b/test/integration/tracing.spec.js index 7ea3b6f6b..b7076c24f 100644 --- a/test/integration/tracing.spec.js +++ b/test/integration/tracing.spec.js @@ -82,7 +82,7 @@ describe("Test Tracing feature with actions", () => { await Promise.all( posts.map(async post => { const author = await ctx.call("users.get", { id: post.author }); - post.author = author; //eslint-disable-line + post.author = author; return post; }) ); diff --git a/test/leak-detection/index.spc.js b/test/leak-detection/index.spc.js index 6c7bb493c..fe21d8a01 100644 --- a/test/leak-detection/index.spc.js +++ b/test/leak-detection/index.spc.js @@ -62,7 +62,7 @@ describe("Moleculer memory leak test", () => { memwatch.gc(); const diff = hd.end(); - if (diff.change.size_bytes >= ACCEPTABLE_LIMIT) console.log("Diff:", diff); // eslint-disable-line no-console + if (diff.change.size_bytes >= ACCEPTABLE_LIMIT) console.log("Diff:", diff); expect(diff.change.size_bytes).toBeLessThan(ACCEPTABLE_LIMIT); } diff --git a/test/leak-detection/self-check.spc.js b/test/leak-detection/self-check.spc.js index dc128222e..ddf38d507 100644 --- a/test/leak-detection/self-check.spc.js +++ b/test/leak-detection/self-check.spc.js @@ -16,7 +16,7 @@ describe("leak detector", function () { if (iterations >= 10) { memwatch.gc(); const diff = hd.end(); - console.log(diff); // eslint-disable-line no-console + console.log(diff); expect(diff.change.size_bytes).toBeGreaterThan(50 * 1024 * 1024); clearInterval(interval); return done(); diff --git a/test/unit/loggers/console.spec.js b/test/unit/loggers/console.spec.js index 997fdf42f..3a6252c92 100644 --- a/test/unit/loggers/console.spec.js +++ b/test/unit/loggers/console.spec.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ "use strict"; const kleur = require("kleur"); diff --git a/test/unit/loggers/formatted.spec.js b/test/unit/loggers/formatted.spec.js index 92d110a19..792417e6c 100644 --- a/test/unit/loggers/formatted.spec.js +++ b/test/unit/loggers/formatted.spec.js @@ -1,4 +1,3 @@ -/* eslint-disable no-console */ "use strict"; const kleur = require("kleur"); diff --git a/test/unit/middlewares/tracing.spec.js b/test/unit/middlewares/tracing.spec.js index f7b13b3d6..bfc34caa3 100644 --- a/test/unit/middlewares/tracing.spec.js +++ b/test/unit/middlewares/tracing.spec.js @@ -1503,9 +1503,7 @@ describe("Test TracingMiddleware localEvent", () => { await newHandler(ctx); - // eslint-disable-next-line ctx.params.a = 10; - // eslint-disable-next-line ctx.meta.user.age = 35; expect(ctx.startSpan).toHaveBeenCalledTimes(1); diff --git a/test/unit/service-broker.spec.js b/test/unit/service-broker.spec.js index acd6c6f79..b987f02a7 100644 --- a/test/unit/service-broker.spec.js +++ b/test/unit/service-broker.spec.js @@ -1,4 +1,3 @@ -/*eslint-disable no-console */ "use strict"; const kleur = require("kleur"); diff --git a/test/unit/service.spec.js b/test/unit/service.spec.js index a307f418c..a9ee89ab8 100644 --- a/test/unit/service.spec.js +++ b/test/unit/service.spec.js @@ -58,7 +58,6 @@ describe("Test Service class", () => { it("should throw error if name is empty", () => { Service.prototype.applyMixins.mockClear(); expect(() => { - /* eslint-disable-next-line no-console */ console.error = jest.fn(); svc.parseServiceSchema({}); }).toThrowError( diff --git a/test/unit/utils.js b/test/unit/utils.js index 6c1bcd4be..76ae7dfa1 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -1,4 +1,3 @@ -/*eslint-disable no-console */ "use strict"; module.exports = {