From 0d07749463b505fee76fbcde72ed6f1dce89a912 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:37:28 +0000 Subject: [PATCH 1/2] Bump eslint from 8.57.1 to 9.12.0 Bumps [eslint](https://github.com/eslint/eslint) from 8.57.1 to 9.12.0. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md) - [Commits](https://github.com/eslint/eslint/compare/v8.57.1...v9.12.0) --- updated-dependencies: - dependency-name: eslint dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9501f7e..06c98f1 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "devDependencies": { "child-process-promise": "^2.2.1", "dot-only-hunter": "^1.0.3", - "eslint": "^8.25.0", + "eslint": "^9.12.0", "eslint-config-airbnb-base": "^15.0.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-import": "^2.26.0", From b0e0507c65381af54a71ff2c1954774b7ef00e9b Mon Sep 17 00:00:00 2001 From: Ram Hershberg Date: Mon, 21 Oct 2024 17:29:58 +0300 Subject: [PATCH 2/2] Migrate to eslint v9 configuration file and remove airbnb config. New `eslint.config.mjs` generated using `npx @eslint/migrate-config .eslintrc` and then tweaked a little. --- .eslintignore | 18 -------- .eslintrc | 17 ------- eslint.config.mjs | 82 +++++++++++++++++++++++++++++++++ package.json | 9 ++-- src/modules/consumer.js | 3 -- src/modules/hooks/base_hooks.js | 2 +- src/modules/message-parsers.js | 12 ++--- src/modules/producer.js | 6 +-- test/disconnect-spec.js | 4 +- test/producer-consumer-spec.js | 4 +- test/rpc-spec.js | 2 +- 11 files changed, 98 insertions(+), 61 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc create mode 100644 eslint.config.mjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index b3daca5..0000000 --- a/.eslintignore +++ /dev/null @@ -1,18 +0,0 @@ -/bin/** -/build/** -/coverage/** -/docs/** -/jsdoc/** -/templates/** -/tests/bench/** -/tests/fixtures/** -/tests/performance/** -/tmp/** -/public/** -/node_modules/** -/lib-cov/** -/.grunt/** -/.sonar/** -/logs/** -/.idea/** -/samples/** diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index a9b9e8c..0000000 --- a/.eslintrc +++ /dev/null @@ -1,17 +0,0 @@ -{ - "extends": ["eslint-config-airbnb-base", "eslint-config-prettier"], - "env": { - "node": true, - "mocha": true, - "es6": true, - "mongo": true - }, - "rules": { - "no-await-in-loop": 0, - "comma-dangle": 0, - "max-classes-per-file": 0, - "max-len": ["error", { "code": 190, "ignoreComments": true, "ignoreUrls": true }], - "no-underscore-dangle": [1, { "allow": ["_config", "_connection", "_maxListeners"], "allowAfterThis": true }], - "no-return-await": "off" - } -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..f07ba83 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,82 @@ +import globals from 'globals'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import js from '@eslint/js'; +import { FlatCompat } from '@eslint/eslintrc'; + +// eslint-disable-next-line no-underscore-dangle +const __filename = fileURLToPath(import.meta.url); +// eslint-disable-next-line no-underscore-dangle +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all, +}); + +export default [ + { + ignores: [ + 'bin/**/*', + 'build/**/*', + 'coverage/**/*', + 'docs/**/*', + 'jsdoc/**/*', + 'templates/**/*', + 'tests/bench/**/*', + 'tests/fixtures/**/*', + 'tests/performance/**/*', + 'tmp/**/*', + 'public/**/*', + 'node_modules/**/*', + 'lib-cov/**/*', + '.grunt/**/*', + '.sonar/**/*', + 'logs/**/*', + '.idea/**/*', + 'samples/**/*', + ], + }, + ...compat.extends('eslint-config-prettier'), + { + languageOptions: { + globals: { + ...globals.node, + ...globals.mocha, + ...globals.mongo, + }, + }, + + rules: { + 'no-await-in-loop': 0, + 'comma-dangle': 0, + 'max-classes-per-file': 0, + + 'max-len': [ + 'error', + { + code: 190, + ignoreComments: true, + ignoreUrls: true, + }, + ], + + 'no-underscore-dangle': [ + 1, + { + allow: ['_config', '_connection', '_maxListeners'], + allowAfterThis: true, + }, + ], + + 'no-return-await': 'off', + 'no-console': 'error', + 'no-param-reassign': 'error', + 'global-require': 'error', + 'no-unused-expressions': 'error', + 'no-sequences': 'error', + 'prefer-rest-params': 'error', + 'func-names': ['error', 'as-needed'], + }, + }, +]; diff --git a/package.json b/package.json index 06c98f1..c5e57cf 100644 --- a/package.json +++ b/package.json @@ -40,12 +40,13 @@ "serialize-error": "^8.0.1" }, "devDependencies": { + "@eslint/js": "^9.13.0", "child-process-promise": "^2.2.1", "dot-only-hunter": "^1.0.3", - "eslint": "^9.12.0", - "eslint-config-airbnb-base": "^15.0.0", - "eslint-config-prettier": "^9.0.0", - "eslint-plugin-import": "^2.26.0", + "eslint": "^9.13.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-import": "^2.31.0", + "globals": "^15.11.0", "mocha": "^10.0.0", "nyc": "^17.0.0", "prettier": "^3.0.0", diff --git a/src/modules/consumer.js b/src/modules/consumer.js index 3904c2e..69e977d 100644 --- a/src/modules/consumer.js +++ b/src/modules/consumer.js @@ -274,7 +274,4 @@ class Consumer { } } -/* eslint no-unused-expressions: "off" */ -/* eslint no-sequences: "off" */ -/* eslint arrow-body-style: "off" */ module.exports = Consumer; diff --git a/src/modules/hooks/base_hooks.js b/src/modules/hooks/base_hooks.js index a630c18..8b893f6 100644 --- a/src/modules/hooks/base_hooks.js +++ b/src/modules/hooks/base_hooks.js @@ -103,7 +103,7 @@ module.exports = class BaseHooks { const hookPromises = []; // This rule intends to restrict it for arrays, but this is a Set which doesn't have a '.map' function to use instead. - // eslint-disable-next-line no-restricted-syntax + for (const callback of callbacks) { hookPromises.push(runHook(source, eventName, payload, callback)); } diff --git a/src/modules/message-parsers.js b/src/modules/message-parsers.js index b40ffe3..d7cc05d 100644 --- a/src/modules/message-parsers.js +++ b/src/modules/message-parsers.js @@ -33,19 +33,19 @@ module.exports.in = (msg) => { * @param {object} options amqp.node message options object * @return {Buffer} node.js Buffer object, sent by amqp.node */ -/* eslint no-param-reassign: "off" */ module.exports.out = (content, options) => { + let parsedContent = content; const falsie = [undefined, null]; if (!falsie.includes(content) && typeof content !== 'string') { - if (content.error instanceof Error) { - content.error = serializeError(content.error); + if (parsedContent.error instanceof Error) { + parsedContent.error = serializeError(parsedContent.error); } // if content is not a string, we JSONify it (JSON.parse can handle numbers, etc. so we can skip all the checks) - content = JSON.stringify(content); + parsedContent = JSON.stringify(parsedContent); options.contentType = 'application/json'; - } else if (falsie.includes(content)) { + } else if (falsie.includes(parsedContent)) { return Buffer.from([]); } - return Buffer.from(content, 'utf-8'); + return Buffer.from(parsedContent, 'utf-8'); }; diff --git a/src/modules/producer.js b/src/modules/producer.js index 7b59148..372161f 100644 --- a/src/modules/producer.js +++ b/src/modules/producer.js @@ -205,7 +205,6 @@ class Producer { * @param {object} options message options (persistent, durable, rpc, etc.) * @return {Promise} checkRpc response */ - /* eslint prefer-rest-params: off */ produce(queue, msg, options) { return this.publish(queue, msg, options); } @@ -217,7 +216,6 @@ class Producer { * @param {object} options message options (persistent, durable, rpc, etc.) * @return {Promise} checkRpc response */ - /* eslint no-param-reassign: "off" */ async publish(queue, msg, options) { // default options are persistent and durable because we do not want to miss any outgoing message // unless user specify it @@ -236,6 +234,7 @@ class Producer { async _sendToQueue(queue, message, settings, currentRetryNumber) { // undefined can't be serialized/buffered :p if (!message) { + // eslint-disable-next-line no-param-reassign message = null; } @@ -311,7 +310,4 @@ class Producer { } } -/* eslint no-unused-expressions: "off" */ -/* eslint no-sequences: "off" */ -/* eslint arrow-body-style: "off" */ module.exports = Producer; diff --git a/test/disconnect-spec.js b/test/disconnect-spec.js index 95086da..9244338 100644 --- a/test/disconnect-spec.js +++ b/test/disconnect-spec.js @@ -5,9 +5,7 @@ const docker = require('./docker'); const arnavmqConfigurator = require('../src/index'); const utils = require('../src/modules/utils'); -/* eslint func-names: "off" */ -/* eslint prefer-arrow-callback: "off" */ -describe('disconnections', function () { +describe('disconnections', () => { let arnavmq; beforeEach(() => { diff --git a/test/producer-consumer-spec.js b/test/producer-consumer-spec.js index fcc52d6..b0507e6 100644 --- a/test/producer-consumer-spec.js +++ b/test/producer-consumer-spec.js @@ -25,9 +25,7 @@ function createFakeChannel() { }; } -/* eslint func-names: "off" */ -/* eslint prefer-arrow-callback: "off" */ -describe('producer/consumer', function () { +describe('producer/consumer', () => { const sandbox = sinon.createSandbox(); afterEach(() => sandbox.restore()); diff --git a/test/rpc-spec.js b/test/rpc-spec.js index dc235cc..69dce8e 100644 --- a/test/rpc-spec.js +++ b/test/rpc-spec.js @@ -56,7 +56,7 @@ describe('Producer/Consumer RPC messaging:', () => { done(error); } // delete the replyTo so we don't return rpc to client - delete properties.replyTo; // eslint-disable-line + delete properties.replyTo; }) .then(() => arnavmq.producer