Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9cee63

Browse filesBrowse 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 <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 4b9817b commit c9cee63
Copy full SHA for c9cee63

File tree

Expand file treeCollapse file tree

2 files changed

+14
-28
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-28
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-eslint-lowercase-name-for-primitive.js
+13-25Lines changed: 13 additions & 25 deletions
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
});
Collapse file

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

Copy file name to clipboardExpand all lines: tools/eslint-rules/lowercase-name-for-primitive.js
+1-3Lines changed: 1 addition & 3 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.