From 814421de8ce64a6b0f7f310f0eae9e6c1c56b3fb Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 20 Dec 2024 13:00:08 +0100 Subject: [PATCH 1/2] tools: fix `require-common-first` lint rule from subfolder --- test/addons/esm/test-esm.mjs | 1 - test/parallel/test-eslint-require-common-first.js | 6 ++++++ tools/eslint-rules/require-common-first.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test/addons/esm/test-esm.mjs b/test/addons/esm/test-esm.mjs index fd2ab14c501cd4..8635d7fc49f684 100644 --- a/test/addons/esm/test-esm.mjs +++ b/test/addons/esm/test-esm.mjs @@ -4,7 +4,6 @@ * the ESM loader or the CJS loader. */ -// eslint-disable-next-line node-core/require-common-first import { buildType } from '../../common/index.mjs'; import assert from 'node:assert'; import { createRequire } from 'node:module'; diff --git a/test/parallel/test-eslint-require-common-first.js b/test/parallel/test-eslint-require-common-first.js index ef19f95b97d635..f14771f4a7b1e7 100644 --- a/test/parallel/test-eslint-require-common-first.js +++ b/test/parallel/test-eslint-require-common-first.js @@ -20,6 +20,12 @@ new RuleTester({ code: 'require("common")\n' + 'require("assert")' }, + { + code: 'import "../../../../common/index.mjs";', + languageOptions: { + sourceType: 'module', + }, + } ], invalid: [ { diff --git a/tools/eslint-rules/require-common-first.js b/tools/eslint-rules/require-common-first.js index 2bfe146086e577..5a8980d5d1c71b 100644 --- a/tools/eslint-rules/require-common-first.js +++ b/tools/eslint-rules/require-common-first.js @@ -22,7 +22,7 @@ module.exports = { * @returns {string} module name */ function getModuleName(str) { - if (str === '../common/index.mjs') { + if (str.startsWith('../') && str.endsWith('/common/index.mjs')) { return 'common'; } From 393cf729f0417cf17ce611163204b1c74a3df8c5 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 20 Dec 2024 13:06:00 +0100 Subject: [PATCH 2/2] fixup! tools: fix `require-common-first` lint rule from subfolder --- test/parallel/test-eslint-require-common-first.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-eslint-require-common-first.js b/test/parallel/test-eslint-require-common-first.js index f14771f4a7b1e7..d7980cebedbfb8 100644 --- a/test/parallel/test-eslint-require-common-first.js +++ b/test/parallel/test-eslint-require-common-first.js @@ -25,7 +25,7 @@ new RuleTester({ languageOptions: { sourceType: 'module', }, - } + }, ], invalid: [ {