From a4f336fdd4607d830bc7b6bb8ea5c4628a33f759 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 22 Dec 2024 19:44:20 +0100 Subject: [PATCH] tools: fix `require-common-first` lint rule from subfolder PR-URL: https://github.com/nodejs/node/pull/56325 Reviewed-By: Luigi Pinca Reviewed-By: LiviaMedeiros --- 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..d7980cebedbfb8 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'; }