tools: allow RegExp in required-modules eslint rule · nodejs/node@1365683 · GitHub
Skip to content

Commit 1365683

Browse files
richardlautargos
authored andcommitted
tools: allow RegExp in required-modules eslint rule
PR-URL: #27647 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 140b44f commit 1365683

3 files changed

Lines changed: 39 additions & 23 deletions

File tree

test/.eslintrc.yaml

Lines changed: 3 additions & 1 deletion

test/parallel/test-eslint-required-modules.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,38 @@ new RuleTester().run('required-modules', rule, {
1313
valid: [
1414
{
1515
code: 'require("common")',
16-
options: ['common']
16+
options: [{ common: 'common' }]
1717
},
1818
{
1919
code: 'foo',
2020
options: []
2121
},
22+
{
23+
code: 'require("common")',
24+
options: [{ common: 'common(/index\\.(m)?js)?$' }]
25+
},
26+
{
27+
code: 'require("common/index.js")',
28+
options: [{ common: 'common(/index\\.(m)?js)?$' }]
29+
},
2230
],
2331
invalid: [
2432
{
2533
code: 'foo',
26-
options: ['common'],
34+
options: [{ common: 'common' }],
2735
errors: [{ message: 'Mandatory module "common" must be loaded.' }]
2836
},
37+
{
38+
code: 'require("common/fixtures.js")',
39+
options: [{ common: 'common(/index\\.(m)?js)?$' }],
40+
errors: [{
41+
message:
42+
'Mandatory module "common" must be loaded.'
43+
}]
44+
},
2945
{
3046
code: 'require("somethingElse")',
31-
options: ['common'],
47+
options: [{ common: 'common' }],
3248
errors: [{ message: 'Mandatory module "common" must be loaded.' }]
3349
}
3450
]

tools/eslint-rules/required-modules.js

Lines changed: 17 additions & 19 deletions

0 commit comments

Comments
 (0)