Skip to content

Commit a4f336f

Browse files
committed
tools: fix require-common-first lint rule from subfolder
PR-URL: #56325 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]>
1 parent 0ec2ed0 commit a4f336f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

test/addons/esm/test-esm.mjs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* the ESM loader or the CJS loader.
55
*/
66

7-
// eslint-disable-next-line node-core/require-common-first
87
import { buildType } from '../../common/index.mjs';
98
import assert from 'node:assert';
109
import { createRequire } from 'node:module';

test/parallel/test-eslint-require-common-first.js

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ new RuleTester({
2020
code: 'require("common")\n' +
2121
'require("assert")'
2222
},
23+
{
24+
code: 'import "../../../../common/index.mjs";',
25+
languageOptions: {
26+
sourceType: 'module',
27+
},
28+
},
2329
],
2430
invalid: [
2531
{

tools/eslint-rules/require-common-first.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
* @returns {string} module name
2323
*/
2424
function getModuleName(str) {
25-
if (str === '../common/index.mjs') {
25+
if (str.startsWith('../') && str.endsWith('/common/index.mjs')) {
2626
return 'common';
2727
}
2828

0 commit comments

Comments
 (0)