Skip to content

Commit

Permalink
test: add lint rule to enforce trailing commas
Browse files Browse the repository at this point in the history
Only activated on some subfolders to minimize the diff, ideally this
rule would be applied gradually to the entire codebase in follow-up
commits.

PR-URL: nodejs#45468
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jiawen Geng <[email protected]>
  • Loading branch information
aduh95 authored and marco-ippolito committed Nov 23, 2022
1 parent 7f960e7 commit c32bad8
Show file tree
Hide file tree
Showing 22 changed files with 130 additions and 102 deletions.
28 changes: 28 additions & 0 deletions test/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rules:
multiline-comment-style: [error, separate-lines]
prefer-const: error
symbol-description: off
comma-dangle: [error, always-multiline]

no-restricted-syntax:
# Config copied from .eslintrc.js
Expand Down Expand Up @@ -68,3 +69,30 @@ rules:
# Global scoped methods and vars
globals:
WebAssembly: false

overrides:
- files:
- addons/*/*.js
- async-hooks/*.js
- common/*.js
- es-module/*.js
- es-module/*.mjs
- internet/*.js
- js-native-api/*/*.js
- known_issues/*.js
- message/*.js
- node-api/*/*.js
- parallel/*.js
- parallel/*.mjs
- pseudo-tty/*.js
- pummel/*.js
- sequential/*.js
- sequential/*.mjs
rules:
comma-dangle: [error, {
arrays: always-multiline,
exports: only-multiline,
functions: only-multiline,
imports: only-multiline,
objects: only-multiline,
}]
8 changes: 4 additions & 4 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,20 @@ expectWarning('DeprecationWarning', [

expectWarning('DeprecationWarning', {
DEP0XXX: 'Foobar is deprecated',
DEP0XX2: 'Baz is also deprecated'
DEP0XX2: 'Baz is also deprecated',
});

expectWarning({
DeprecationWarning: {
DEP0XXX: 'Foobar is deprecated',
DEP0XX1: 'Baz is also deprecated'
DEP0XX1: 'Baz is also deprecated',
},
Warning: [
['Multiple array entries are fine', 'SpecialWarningCode'],
['No code is also fine'],
],
SingleEntry: ['This will also work', 'WarningCode'],
SingleString: 'Single string entries without code will also work'
SingleString: 'Single string entries without code will also work',
});
```

Expand Down Expand Up @@ -720,7 +720,7 @@ validateSnapshotNodes('TLSWRAP', [
{ name: 'enc_out' },
{ name: 'enc_in' },
{ name: 'TLSWrap' },
]
],
},
]);
```
Expand Down
4 changes: 2 additions & 2 deletions test/common/wpt/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const resource = new ResourceLoader(workerData.wptPath);
global.self = global;
global.GLOBAL = {
isWindow() { return false; },
isShadowRealm() { return false; }
isShadowRealm() { return false; },
};
global.require = require;

Expand All @@ -25,7 +25,7 @@ if (workerData.initScript) {
}

runInThisContext(workerData.harness.code, {
filename: workerData.harness.filename
filename: workerData.harness.filename,
});

// eslint-disable-next-line no-undef
Expand Down
4 changes: 2 additions & 2 deletions test/doctool/test-apilinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fs.readdirSync(apilinks).forEach((fixture) => {
execFileSync(
process.execPath,
[script, outputPath, input],
{ encoding: 'utf-8' }
{ encoding: 'utf-8' },
);

const expectedLinks = JSON.parse(expectedContent);
Expand All @@ -38,6 +38,6 @@ fs.readdirSync(apilinks).forEach((fixture) => {

assert.strictEqual(
Object.keys(actualLinks).length, 0,
`unexpected links returned ${JSON.stringify(actualLinks)}`
`unexpected links returned ${JSON.stringify(actualLinks)}`,
);
});
4 changes: 2 additions & 2 deletions test/doctool/test-deprecation-codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const script = path.join(
'..',
'tools',
'doc',
'deprecationCodes.mjs'
'deprecationCodes.mjs',
);

const mdPath = path.join(
Expand All @@ -19,7 +19,7 @@ const mdPath = path.join(
'..',
'doc',
'api',
'deprecations.md'
'deprecations.md',
);

const cp = spawn(process.execPath, [script, mdPath], { encoding: 'utf-8', stdio: 'inherit' });
Expand Down
10 changes: 5 additions & 5 deletions test/doctool/test-doctool-html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
const testLinksMapper = {
'foo': {
'command line options': 'cli.html#cli-options',
'web server': 'example.html'
}
'web server': 'example.html',
},
};

function toHTML({ input, filename, nodeVersion, versions }) {
Expand Down Expand Up @@ -58,7 +58,7 @@ const testData = [
'id="foo_static_method_buffer_from_array"></a></h4>' +
'<ul><li><code>array</code><a ' +
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
'Reference/Global_Objects/Array" class="type">&#x3C;Array></a></li></ul>'
'Reference/Global_Objects/Array" class="type">&#x3C;Array></a></li></ul>',
},
{
file: fixtures.path('doc_with_yaml.md'),
Expand Down Expand Up @@ -99,7 +99,7 @@ const testData = [
'" id="something">#</a></span>' +
'<a aria-hidden="true" class="legacy" id="foo_something"></a></h3>' +
'<!-- This is not a metadata comment --> ' +
'<p>Describe <code>Something</code> in more detail here. </p></section>'
'<p>Describe <code>Something</code> in more detail here. </p></section>',
},
{
file: fixtures.path('sample_document.md'),
Expand Down Expand Up @@ -129,7 +129,7 @@ const testData = [
'<h3>See also<span><a class="mark"' +
'href="#see-also" id="see-also">#</a></span><a aria-hidden="true"' +
'class="legacy" id="foo_see_also"></a></h3><p>Check' +
'out also<a href="https://nodejs.org/">this guide</a></p></section>'
'out also<a href="https://nodejs.org/">this guide</a></p></section>',
},
{
file: fixtures.path('document_with_special_heading.md'),
Expand Down
64 changes: 32 additions & 32 deletions test/doctool/test-doctool-json.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const testData = [
desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
'<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
type: 'module',
displayName: 'Seussian Rhymes'
displayName: 'Seussian Rhymes',
}],
type: 'module',
displayName: 'Sample Markdown'
}]
}
displayName: 'Sample Markdown',
}],
},
},
{
file: fixtures.path('order_of_end_tags_5873.md'),
Expand All @@ -68,18 +68,18 @@ const testData = [
params: [{
textRaw: '`array` {Array}',
name: 'array',
type: 'Array'
}]
type: 'Array',
}],
},
]
],
}],
type: 'module',
displayName: 'Subsection'
displayName: 'Subsection',
}],
type: 'module',
displayName: 'Title'
}]
}
displayName: 'Title',
}],
},
},
{
file: fixtures.path('doc_with_yaml.md'),
Expand All @@ -96,12 +96,12 @@ const testData = [
name: 'foobar',
meta: {
added: ['v1.0.0'],
changes: []
changes: [],
},
desc: '<p>Describe <code>Foobar</code> in more detail ' +
'here.</p>',
type: 'module',
displayName: 'Foobar'
displayName: 'Foobar',
},
{
textRaw: 'Foobar II',
Expand All @@ -113,40 +113,40 @@ const testData = [
'pr-url': 'https://github.com/nodejs/node/pull/3276',
'description': 'The `error` parameter can now be ' +
'an arrow function.' },
]
],
},
desc: '<p>Describe <code>Foobar II</code> in more detail ' +
'here. fg(1)</p>',
type: 'module',
displayName: 'Foobar II'
displayName: 'Foobar II',
},
{
textRaw: 'Deprecated thingy',
name: 'deprecated_thingy',
meta: {
added: ['v1.0.0'],
deprecated: ['v2.0.0'],
changes: []
changes: [],
},
desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
'detail here. fg(1p)</p>',
type: 'module',
displayName: 'Deprecated thingy'
displayName: 'Deprecated thingy',
},
{
textRaw: 'Something',
name: 'something',
desc: '<!-- This is not a metadata comment -->\n<p>' +
'Describe <code>Something</code> in more detail here.</p>',
type: 'module',
displayName: 'Something'
displayName: 'Something',
},
],
type: 'module',
displayName: 'Sample Markdown with YAML info'
displayName: 'Sample Markdown with YAML info',
},
]
}
],
},
},
{
file: fixtures.path('doc_with_backticks_in_headings.md'),
Expand All @@ -160,61 +160,61 @@ const testData = [
properties: [
{
name: 'fullName',
textRaw: '`Fqhqwhgads.fullName`'
textRaw: '`Fqhqwhgads.fullName`',
},
],
classMethods: [
{
name: 'again',
signatures: [
{
params: []
params: [],
},
],
textRaw: 'Static method: `Fhqwhgads.again()`',
type: 'classMethod'
type: 'classMethod',
},
],
classes: [
{
textRaw: 'Class: `ComeOn`',
type: 'class',
name: 'ComeOn'
name: 'ComeOn',
},
],
ctors: [
{
name: 'Fhqwhgads',
signatures: [
{
params: []
params: [],
},
],
textRaw: 'Constructor: `new Fhqwhgads()`',
type: 'ctor'
type: 'ctor',
},
],
methods: [
{
textRaw: '`everybody.to(limit)`',
type: 'method',
name: 'to',
signatures: [{ params: [] }]
signatures: [{ params: [] }],
},
],
events: [
{
textRaw: "Event: `'FHQWHfest'`",
type: 'event',
name: 'FHQWHfest',
params: []
params: [],
},
],
type: 'module',
displayName: 'Fhqwhgads'
displayName: 'Fhqwhgads',
},
]
}
],
},
},
];

Expand Down
6 changes: 3 additions & 3 deletions test/doctool/test-make-doc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const actualDocs = allDocs.filter(
(name) => {
const extension = path.extname(name);
return extension === '.html' || extension === '.json';
}
},
);

for (const name of actualDocs) {
if (name.startsWith('all.')) continue;

assert.ok(
allMD.includes(name.replace(/\.\w+$/, '.md')),
`Unexpected output: out/doc/api/${name}, remove and rerun.`
`Unexpected output: out/doc/api/${name}, remove and rerun.`,
);
}

Expand Down Expand Up @@ -66,6 +66,6 @@ for (const actualDoc of actualDocs) {
assert.notStrictEqual(
fs.statSync(new URL(`./${actualDoc}`, apiURL)).size,
0,
`${actualDoc} is empty`
`${actualDoc} is empty`,
);
}
4 changes: 2 additions & 2 deletions test/report/test-report-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ if (!common.isWindows) {
process.report.signal = 'foo';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: foo'
message: 'Unknown signal: foo',
});
assert.throws(() => {
process.report.signal = 'sigusr1';
}, {
code: 'ERR_UNKNOWN_SIGNAL',
message: 'Unknown signal: sigusr1 (signals must use all capital letters)'
message: 'Unknown signal: sigusr1 (signals must use all capital letters)',
});
assert.strictEqual(process.report.signal, 'SIGUSR2');
process.report.signal = 'SIGUSR1';
Expand Down
2 changes: 1 addition & 1 deletion test/report/test-report-uncaught-exception-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const child = childProcess.spawn(process.execPath, [
__filename,
'child',
], {
cwd: tmpdir.path
cwd: tmpdir.path,
});
child.on('exit', common.mustCall((code) => {
assert.strictEqual(code, 1);
Expand Down
Loading

0 comments on commit c32bad8

Please sign in to comment.