Skip to content

Commit 1277ffc

Browse files
aduh95ruyadorno
authored andcommitted
test: add lint rule to enforce trailing commas
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: #45468 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
1 parent 62ef1eb commit 1277ffc

22 files changed

+130
-102
lines changed

test/.eslintrc.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rules:
88
multiline-comment-style: [error, separate-lines]
99
prefer-const: error
1010
symbol-description: off
11+
comma-dangle: [error, always-multiline]
1112

1213
no-restricted-syntax:
1314
# Config copied from .eslintrc.js
@@ -68,3 +69,30 @@ rules:
6869
# Global scoped methods and vars
6970
globals:
7071
WebAssembly: false
72+
73+
overrides:
74+
- files:
75+
- addons/*/*.js
76+
- async-hooks/*.js
77+
- common/*.js
78+
- es-module/*.js
79+
- es-module/*.mjs
80+
- internet/*.js
81+
- js-native-api/*/*.js
82+
- known_issues/*.js
83+
- message/*.js
84+
- node-api/*/*.js
85+
- parallel/*.js
86+
- parallel/*.mjs
87+
- pseudo-tty/*.js
88+
- pummel/*.js
89+
- sequential/*.js
90+
- sequential/*.mjs
91+
rules:
92+
comma-dangle: [error, {
93+
arrays: always-multiline,
94+
exports: only-multiline,
95+
functions: only-multiline,
96+
imports: only-multiline,
97+
objects: only-multiline,
98+
}]

test/common/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,20 @@ expectWarning('DeprecationWarning', [
110110

111111
expectWarning('DeprecationWarning', {
112112
DEP0XXX: 'Foobar is deprecated',
113-
DEP0XX2: 'Baz is also deprecated'
113+
DEP0XX2: 'Baz is also deprecated',
114114
});
115115

116116
expectWarning({
117117
DeprecationWarning: {
118118
DEP0XXX: 'Foobar is deprecated',
119-
DEP0XX1: 'Baz is also deprecated'
119+
DEP0XX1: 'Baz is also deprecated',
120120
},
121121
Warning: [
122122
['Multiple array entries are fine', 'SpecialWarningCode'],
123123
['No code is also fine'],
124124
],
125125
SingleEntry: ['This will also work', 'WarningCode'],
126-
SingleString: 'Single string entries without code will also work'
126+
SingleString: 'Single string entries without code will also work',
127127
});
128128
```
129129

@@ -720,7 +720,7 @@ validateSnapshotNodes('TLSWRAP', [
720720
{ name: 'enc_out' },
721721
{ name: 'enc_in' },
722722
{ name: 'TLSWrap' },
723-
]
723+
],
724724
},
725725
]);
726726
```

test/common/wpt/worker.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const resource = new ResourceLoader(workerData.wptPath);
99
global.self = global;
1010
global.GLOBAL = {
1111
isWindow() { return false; },
12-
isShadowRealm() { return false; }
12+
isShadowRealm() { return false; },
1313
};
1414
global.require = require;
1515

@@ -25,7 +25,7 @@ if (workerData.initScript) {
2525
}
2626

2727
runInThisContext(workerData.harness.code, {
28-
filename: workerData.harness.filename
28+
filename: workerData.harness.filename,
2929
});
3030

3131
// eslint-disable-next-line no-undef

test/doctool/test-apilinks.mjs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fs.readdirSync(apilinks).forEach((fixture) => {
2323
execFileSync(
2424
process.execPath,
2525
[script, outputPath, input],
26-
{ encoding: 'utf-8' }
26+
{ encoding: 'utf-8' },
2727
);
2828

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

3939
assert.strictEqual(
4040
Object.keys(actualLinks).length, 0,
41-
`unexpected links returned ${JSON.stringify(actualLinks)}`
41+
`unexpected links returned ${JSON.stringify(actualLinks)}`,
4242
);
4343
});

test/doctool/test-deprecation-codes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const script = path.join(
1010
'..',
1111
'tools',
1212
'doc',
13-
'deprecationCodes.mjs'
13+
'deprecationCodes.mjs',
1414
);
1515

1616
const mdPath = path.join(
@@ -19,7 +19,7 @@ const mdPath = path.join(
1919
'..',
2020
'doc',
2121
'api',
22-
'deprecations.md'
22+
'deprecations.md',
2323
);
2424

2525
const cp = spawn(process.execPath, [script, mdPath], { encoding: 'utf-8', stdio: 'inherit' });

test/doctool/test-doctool-html.mjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import {
2323
const testLinksMapper = {
2424
'foo': {
2525
'command line options': 'cli.html#cli-options',
26-
'web server': 'example.html'
27-
}
26+
'web server': 'example.html',
27+
},
2828
};
2929

3030
function toHTML({ input, filename, nodeVersion, versions }) {
@@ -58,7 +58,7 @@ const testData = [
5858
'id="foo_static_method_buffer_from_array"></a></h4>' +
5959
'<ul><li><code>array</code><a ' +
6060
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
61-
'Reference/Global_Objects/Array" class="type">&#x3C;Array></a></li></ul>'
61+
'Reference/Global_Objects/Array" class="type">&#x3C;Array></a></li></ul>',
6262
},
6363
{
6464
file: fixtures.path('doc_with_yaml.md'),
@@ -99,7 +99,7 @@ const testData = [
9999
'" id="something">#</a></span>' +
100100
'<a aria-hidden="true" class="legacy" id="foo_something"></a></h3>' +
101101
'<!-- This is not a metadata comment --> ' +
102-
'<p>Describe <code>Something</code> in more detail here. </p></section>'
102+
'<p>Describe <code>Something</code> in more detail here. </p></section>',
103103
},
104104
{
105105
file: fixtures.path('sample_document.md'),
@@ -129,7 +129,7 @@ const testData = [
129129
'<h3>See also<span><a class="mark"' +
130130
'href="#see-also" id="see-also">#</a></span><a aria-hidden="true"' +
131131
'class="legacy" id="foo_see_also"></a></h3><p>Check' +
132-
'out also<a href="https://nodejs.org/">this guide</a></p></section>'
132+
'out also<a href="https://nodejs.org/">this guide</a></p></section>',
133133
},
134134
{
135135
file: fixtures.path('document_with_special_heading.md'),

test/doctool/test-doctool-json.mjs

+32-32
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ const testData = [
4141
desc: '<ol>\n<li>fish</li>\n<li>fish</li>\n</ol>\n' +
4242
'<ul>\n<li>Red fish</li>\n<li>Blue fish</li>\n</ul>',
4343
type: 'module',
44-
displayName: 'Seussian Rhymes'
44+
displayName: 'Seussian Rhymes',
4545
}],
4646
type: 'module',
47-
displayName: 'Sample Markdown'
48-
}]
49-
}
47+
displayName: 'Sample Markdown',
48+
}],
49+
},
5050
},
5151
{
5252
file: fixtures.path('order_of_end_tags_5873.md'),
@@ -68,18 +68,18 @@ const testData = [
6868
params: [{
6969
textRaw: '`array` {Array}',
7070
name: 'array',
71-
type: 'Array'
72-
}]
71+
type: 'Array',
72+
}],
7373
},
74-
]
74+
],
7575
}],
7676
type: 'module',
77-
displayName: 'Subsection'
77+
displayName: 'Subsection',
7878
}],
7979
type: 'module',
80-
displayName: 'Title'
81-
}]
82-
}
80+
displayName: 'Title',
81+
}],
82+
},
8383
},
8484
{
8585
file: fixtures.path('doc_with_yaml.md'),
@@ -96,12 +96,12 @@ const testData = [
9696
name: 'foobar',
9797
meta: {
9898
added: ['v1.0.0'],
99-
changes: []
99+
changes: [],
100100
},
101101
desc: '<p>Describe <code>Foobar</code> in more detail ' +
102102
'here.</p>',
103103
type: 'module',
104-
displayName: 'Foobar'
104+
displayName: 'Foobar',
105105
},
106106
{
107107
textRaw: 'Foobar II',
@@ -113,40 +113,40 @@ const testData = [
113113
'pr-url': 'https://github.com/nodejs/node/pull/3276',
114114
'description': 'The `error` parameter can now be ' +
115115
'an arrow function.' },
116-
]
116+
],
117117
},
118118
desc: '<p>Describe <code>Foobar II</code> in more detail ' +
119119
'here. fg(1)</p>',
120120
type: 'module',
121-
displayName: 'Foobar II'
121+
displayName: 'Foobar II',
122122
},
123123
{
124124
textRaw: 'Deprecated thingy',
125125
name: 'deprecated_thingy',
126126
meta: {
127127
added: ['v1.0.0'],
128128
deprecated: ['v2.0.0'],
129-
changes: []
129+
changes: [],
130130
},
131131
desc: '<p>Describe <code>Deprecated thingy</code> in more ' +
132132
'detail here. fg(1p)</p>',
133133
type: 'module',
134-
displayName: 'Deprecated thingy'
134+
displayName: 'Deprecated thingy',
135135
},
136136
{
137137
textRaw: 'Something',
138138
name: 'something',
139139
desc: '<!-- This is not a metadata comment -->\n<p>' +
140140
'Describe <code>Something</code> in more detail here.</p>',
141141
type: 'module',
142-
displayName: 'Something'
142+
displayName: 'Something',
143143
},
144144
],
145145
type: 'module',
146-
displayName: 'Sample Markdown with YAML info'
146+
displayName: 'Sample Markdown with YAML info',
147147
},
148-
]
149-
}
148+
],
149+
},
150150
},
151151
{
152152
file: fixtures.path('doc_with_backticks_in_headings.md'),
@@ -160,61 +160,61 @@ const testData = [
160160
properties: [
161161
{
162162
name: 'fullName',
163-
textRaw: '`Fqhqwhgads.fullName`'
163+
textRaw: '`Fqhqwhgads.fullName`',
164164
},
165165
],
166166
classMethods: [
167167
{
168168
name: 'again',
169169
signatures: [
170170
{
171-
params: []
171+
params: [],
172172
},
173173
],
174174
textRaw: 'Static method: `Fhqwhgads.again()`',
175-
type: 'classMethod'
175+
type: 'classMethod',
176176
},
177177
],
178178
classes: [
179179
{
180180
textRaw: 'Class: `ComeOn`',
181181
type: 'class',
182-
name: 'ComeOn'
182+
name: 'ComeOn',
183183
},
184184
],
185185
ctors: [
186186
{
187187
name: 'Fhqwhgads',
188188
signatures: [
189189
{
190-
params: []
190+
params: [],
191191
},
192192
],
193193
textRaw: 'Constructor: `new Fhqwhgads()`',
194-
type: 'ctor'
194+
type: 'ctor',
195195
},
196196
],
197197
methods: [
198198
{
199199
textRaw: '`everybody.to(limit)`',
200200
type: 'method',
201201
name: 'to',
202-
signatures: [{ params: [] }]
202+
signatures: [{ params: [] }],
203203
},
204204
],
205205
events: [
206206
{
207207
textRaw: "Event: `'FHQWHfest'`",
208208
type: 'event',
209209
name: 'FHQWHfest',
210-
params: []
210+
params: [],
211211
},
212212
],
213213
type: 'module',
214-
displayName: 'Fhqwhgads'
214+
displayName: 'Fhqwhgads',
215215
},
216-
]
217-
}
216+
],
217+
},
218218
},
219219
];
220220

test/doctool/test-make-doc.mjs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ const actualDocs = allDocs.filter(
2121
(name) => {
2222
const extension = path.extname(name);
2323
return extension === '.html' || extension === '.json';
24-
}
24+
},
2525
);
2626

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

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

@@ -66,6 +66,6 @@ for (const actualDoc of actualDocs) {
6666
assert.notStrictEqual(
6767
fs.statSync(new URL(`./${actualDoc}`, apiURL)).size,
6868
0,
69-
`${actualDoc} is empty`
69+
`${actualDoc} is empty`,
7070
);
7171
}

test/report/test-report-config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ if (!common.isWindows) {
7676
process.report.signal = 'foo';
7777
}, {
7878
code: 'ERR_UNKNOWN_SIGNAL',
79-
message: 'Unknown signal: foo'
79+
message: 'Unknown signal: foo',
8080
});
8181
assert.throws(() => {
8282
process.report.signal = 'sigusr1';
8383
}, {
8484
code: 'ERR_UNKNOWN_SIGNAL',
85-
message: 'Unknown signal: sigusr1 (signals must use all capital letters)'
85+
message: 'Unknown signal: sigusr1 (signals must use all capital letters)',
8686
});
8787
assert.strictEqual(process.report.signal, 'SIGUSR2');
8888
process.report.signal = 'SIGUSR1';

test/report/test-report-uncaught-exception-compat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const child = childProcess.spawn(process.execPath, [
1717
__filename,
1818
'child',
1919
], {
20-
cwd: tmpdir.path
20+
cwd: tmpdir.path,
2121
});
2222
child.on('exit', common.mustCall((code) => {
2323
assert.strictEqual(code, 1);

0 commit comments

Comments
 (0)