Skip to content

Commit c9cee63

Browse files
Trotttargos
authored andcommitted
test,tools: refactor custom ESLint for readability
Refactor the test and the source for the `lowercase-name-for-primitive` custom ESLint rule for readability. PR-URL: #21134 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent 4b9817b commit c9cee63

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

test/parallel/test-eslint-lowercase-name-for-primitive.js

+13-25
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,33 @@ common.skipIfEslintMissing();
77
const RuleTester = require('../../tools/node_modules/eslint').RuleTester;
88
const rule = require('../../tools/eslint-rules/lowercase-name-for-primitive');
99

10-
const valid = [
11-
'string',
12-
'number',
13-
'boolean',
14-
'null',
15-
'undefined'
16-
];
17-
1810
new RuleTester().run('lowercase-name-for-primitive', rule, {
1911
valid: [
2012
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "a", ["string", "number"])',
21-
...valid.map((name) =>
22-
`new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "${name}")`
23-
)
13+
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "string")',
14+
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "number")',
15+
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "boolean")',
16+
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "null")',
17+
'new errors.TypeError("ERR_INVALID_ARG_TYPE", "name", "undefined")',
2418
],
2519
invalid: [
2620
{
27-
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
28-
'\'Number\')',
21+
code: "new errors.TypeError('ERR_INVALID_ARG_TYPE', 'a', 'Number')",
2922
errors: [{ message: 'primitive should use lowercase: Number' }],
30-
output: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
31-
'\'number\')'
23+
output: "new errors.TypeError('ERR_INVALID_ARG_TYPE', 'a', 'number')",
3224
},
3325
{
34-
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
35-
'\'STRING\')',
26+
code: "new errors.TypeError('ERR_INVALID_ARG_TYPE', 'a', 'STRING')",
3627
errors: [{ message: 'primitive should use lowercase: STRING' }],
37-
output: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
38-
'\'string\')'
28+
output: "new errors.TypeError('ERR_INVALID_ARG_TYPE', 'a', 'string')",
3929
},
4030
{
41-
code: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
42-
'[\'String\', \'Number\']) ',
31+
code: "new e.TypeError('ERR_INVALID_ARG_TYPE', a, ['String','Number'])",
4332
errors: [
4433
{ message: 'primitive should use lowercase: String' },
45-
{ message: 'primitive should use lowercase: Number' }
34+
{ message: 'primitive should use lowercase: Number' },
4635
],
47-
output: 'new errors.TypeError(\'ERR_INVALID_ARG_TYPE\', \'a\', ' +
48-
'[\'string\', \'number\']) '
49-
}
36+
output: "new e.TypeError('ERR_INVALID_ARG_TYPE', a, ['string','number'])",
37+
},
5038
]
5139
});

tools/eslint-rules/lowercase-name-for-primitive.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
const astSelector = 'NewExpression[callee.property.name="TypeError"]' +
1313
'[arguments.0.value="ERR_INVALID_ARG_TYPE"]';
1414

15-
const primitives = [
16-
'number', 'string', 'boolean', 'null', 'undefined'
17-
];
15+
const primitives = [ 'number', 'string', 'boolean', 'null', 'undefined' ];
1816

1917
module.exports = function(context) {
2018
function checkNamesArgument(node) {

0 commit comments

Comments
 (0)