-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathvalidator.js
535 lines (468 loc) · 19.2 KB
/
validator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
import { test } from 'tap'
import Validator from '../lib/validator.js'
import { readFileSync } from 'node:fs'
// Note, these are not necessarily all real commit messages
const str = `commit e7c077c610afa371430180fbd447bfef60ebc5ea
Author: Calvin Metcalf <cmetcalf@appgeo.com>
AuthorDate: Tue Apr 12 15:42:23 2016 -0400
Commit: James M Snell <jasnell@gmail.com>
CommitDate: Wed Apr 20 13:28:35 2016 -0700
stream: make null an invalid chunk to write in object mode
this harmonizes behavior between readable, writable, and transform
streams so that they all handle nulls in object mode the same way by
considering them invalid chunks.
PR-URL: https://github.com/nodejs/node/pull/6170
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
`
const str2 = `commit b6475b9a9d0da0971eec7eb5559dff4d18a0e721
Author: Evan Lucas <evanlucas@me.com>
Date: Tue Mar 29 08:09:37 2016 -0500
Revert "tty: do not read from the console stream upon creation"
This reverts commit 461138929498f31bd35bea61aa4375a2f56cceb7.
The offending commit broke certain usages of piping from stdin.
Fixes: https://github.com/nodejs/node/issues/5927
PR-URL: https://github.com/nodejs/node/pull/5947
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Alexis Campailla <orangemocha@nodejs.org>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
`
/* eslint-disable */
const str3 = `commit 75487f0db80e70a3e27fabfe323a33258dfbbea8
Author: Michaël Zasso <targos@protonmail.com>
Date: Fri Apr 15 13:32:36 2016 +0200
module: fix resolution of filename with trailing slash - make this tile too long
A recent optimization of module loading performance [1] forgot to check that
extensions were set in a certain code path.
[1] https://github.com/nodejs/node/pull/5172/commits/ae18bbef48d87d9c641df85369f62cfd5ed8c250
Fixes: https://github.com/nodejs/node/issues/6214
PR-URL: https://github.com/nodejs/node/pull/6215
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Brian White <mscdex@mscdex.net>`
/* eslint-enable */
const str4 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
Author: Wyatt Preul <wpreul@gmail.com>
Date: Thu Mar 3 10:10:46 2016 -0600
check memoryUsage properties
The properties on memoryUsage were not checked before,
this commit checks them.
PR-URL: #5546
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>`
const str5 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
Author: Wyatt Preul <wpreul@gmail.com>
Date: Thu Mar 3 10:10:46 2016 -0600
test: check memoryUsage properties
The properties on memoryUsage were not checked before,
this commit checks them.`
/* eslint-disable */
const str6 = {
"sha": "c5545f2c63fe30b0cfcdafab18c26df8286881d0",
"url": "https://api.github.com/repos/nodejs/node/git/commits/c5545f2c63fe30b0cfcdafab18c26df8286881d0",
"html_url": "https://github.com/nodejs/node/commit/c5545f2c63fe30b0cfcdafab18c26df8286881d0",
"author": {
"name": "Anna Henningsen",
"email": "anna@addaleax.net",
"date": "2016-09-13T10:57:49Z"
},
"committer": {
"name": "Anna Henningsen",
"email": "anna@addaleax.net",
"date": "2016-09-19T12:50:57Z"
},
"tree": {
"sha": "b505c0ffa0555730e9f4cdb391d1ebeb48bb2f59",
"url": "https://api.github.com/repos/nodejs/node/git/trees/b505c0ffa0555730e9f4cdb391d1ebeb48bb2f59"
},
"message": "fs: fix handling of `uv_stat_t` fields\n\n`FChown` and `Chown` test that the `uid` and `gid` parameters\nthey receive are unsigned integers, but `Stat()` and `FStat()`\nwould return the corresponding fields of `uv_stat_t` as signed\nintegers. Applications which pass those these values directly\nto `Chown` may fail\n(e.g. for `nobody` on OS X, who has an `uid` of `-2`, see e.g.\nhttps://github.com/nodejs/node-v0.x-archive/issues/5890).\n\nThis patch changes the `Integer::New()` call for `uid` and `gid`\nto `Integer::NewFromUnsigned()`.\n\nAll other fields are kept as they are, for performance, but\nstrictly speaking the respective sizes of those\nfields aren’t specified, either.\n\nRef: https://github.com/npm/npm/issues/13918\nPR-URL: https://github.com/nodejs/node/pull/8515\nReviewed-By: Ben Noordhuis <info@bnoordhuis.nl>\nReviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>\nReviewed-By: James M Snell <jasnell@gmail.com>\n\nundo accidental change to other fields of uv_fs_stat",
"parents": [
{
"sha": "4e76bffc0c7076a5901179e70c7b8a8f9fcd22e4",
"url": "https://api.github.com/repos/nodejs/node/git/commits/4e76bffc0c7076a5901179e70c7b8a8f9fcd22e4",
"html_url": "https://github.com/nodejs/node/commit/4e76bffc0c7076a5901179e70c7b8a8f9fcd22e4"
}
]
}
/* eslint-enable */
const str7 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
Author: Wyatt Preul <wpreul@gmail.com>
Date: Thu Mar 3 10:10:46 2016 -0600
test: check memoryUsage properties.
`
const str8 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
Author: Wyatt Preul <wpreul@gmail.com>
Date: Thu Mar 3 10:10:46 2016 -0600
test: Check memoryUsage properties
`
const str9 = `commit 7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
Author: Wyatt Preul <wpreul@gmail.com>
Date: Thu Mar 3 10:10:46 2016 -0600
test: Check memoryUsage properties.
`
const str10 = `commit b04fe688d5859f707cf1a5e0206967268118bf7a
Author: Darshan Sen <raisinten@gmail.com>
Date: Sun May 1 21:10:21 2022 +0530
Revert "bootstrap: delay the instantiation of maps in per-context scripts"
The linked issue, https://bugs.chromium.org/p/v8/issues/detail?id=6593,
is marked as "Fixed", so I think we can revert this now.
This reverts commit 08a9c4a996964aca909cd75fa8ecafd652c54885.
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/42934
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=9187
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
`
const str11 = `commit b04fe688d5859f707cf1a5e0206967268118bf7a
Author: Darshan Sen <raisinten@gmail.com>
Date: Sun May 1 21:10:21 2022 +0530
Revert "bootstrap: delay the instantiation of all maps in the per-context scripts"
The linked issue, https://bugs.chromium.org/p/v8/issues/detail?id=6593,
is marked as "Fixed", so I think we can revert this now.
This reverts commit 08a9c4a996964aca909cd75fa8ecafd652c54885.
Signed-off-by: Darshan Sen <raisinten@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/42934
Refs: https://bugs.chromium.org/p/v8/issues/detail?id=9187
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
`
const str12 = `commit cbb404503c9df13aaeb3dd8b345cb3f34c8c07e4
Author: Michaël Zasso <targos@protonmail.com>
Date: Sat Oct 22 10:22:43 2022 +0200
Revert "deps: V8: forward declaration of \`Rtl*FunctionTable\`"
This reverts commit 01bc8e6fd81314e76c7fb0d09e5310f609e48bee.
`
const str13 = `commit 287d681575bdd2099b0cc892f6a90b0323033101
Author: Stephen Belanger <admin@stephenbelanger.com>
Date: Wed Jul 24 10:00:04 2024 -0700
deps: V8: backport 7857eb34db42
Original commit message:
Reland^2 "Add ContinuationPreservedEmbedderData builtins to extras binding"
This reverts commit cb1277e97a0ed32fd893be9f4e927f6e8b6c566c.
> Original change's description:
> > Add ContinuationPreservedEmbedderData builtins to extras binding
> >
> > Node.js and Deno wish to use CPED for AsyncLocalStorage and APM, which
> > needs a high performance implementation. These builtins allow JavaScript
> > to handle CPED performantly.
> >
> > Change-Id: I7577be80818524baa52791dfce57d442d7c0c933
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5638129
> > Commit-Queue: snek <snek@chromium.org>
> > Reviewed-by: Darius Mercadier <dmercadier@chromium.org>
> > Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> > Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
> > Cr-Commit-Position: refs/heads/main@{#94607}
>
> Change-Id: Ief390f0b99891c8de83b4c794180440f91cbaf1f
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5649024
> Auto-Submit: Shu-yu Guo <syg@chromium.org>
> Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
> Cr-Commit-Position: refs/heads/main@{#94608}
Change-Id: I4943071ffe192084e83bfe3113cfe9c92ef31465
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5677045
Reviewed-by: Darius Mercadier <dmercadier@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: snek <snek@chromium.org>
Cr-Commit-Position: refs/heads/main@{#94866}
Refs: v8/v8@7857eb3
`
test('Validator - misc', (t) => {
const v = new Validator()
t.throws(() => {
v.disableRule('biscuits')
}, /Invalid rule: "biscuits"/)
v.disableRule('line-length')
t.equal(v.rules.get('line-length').disabled, true, 'disabled')
v.rules.get('line-length').disabled = false
t.end()
})
test('Validator - real commits', (t) => {
t.test('basic', (tt) => {
const commit = JSON.parse(readFileSync(new URL('fixtures/commit.json', import.meta.url), { encoding: 'utf8' }))
const pr = JSON.parse(readFileSync(new URL('fixtures/pr.json', import.meta.url), { encoding: 'utf8' }))
tt.plan(21)
const v = new Validator()
// run against the output of git show --quiet
// run against the output of github's get commit api request
// run against the output of github's list commits for pr api request
v.lint(str)
v.lint(commit)
v.lint(pr)
v.on('commit', (data) => {
const c = data.commit
tt.equal(c.sha, 'e7c077c610afa371430180fbd447bfef60ebc5ea', 'sha')
tt.same(c.subsystems, ['stream'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/6170', 'pr')
const msgs = data.messages
const failed = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(failed.length, 0, 'failed.length')
const warned = msgs.filter((item) => {
return item.level === 'warn'
})
tt.equal(warned.length, 3, 'warned.length')
tt.equal(warned[0].level, 'warn')
tt.equal(warned[0].id, 'title-length')
})
})
t.test('basic revert', (tt) => {
const v = new Validator()
v.lint(str2)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'b6475b9a9d0da0971eec7eb5559dff4d18a0e721', 'sha')
tt.equal(c.date, 'Tue Mar 29 08:09:37 2016 -0500', 'date')
tt.same(c.subsystems, ['tty'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/5947', 'pr')
tt.equal(c.revert, true, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'warn'
})
tt.equal(filtered.length, 1, 'messages.length')
tt.equal(filtered[0].level, 'warn')
tt.equal(filtered[0].id, 'title-length')
tt.end()
})
})
t.test('more basic', (tt) => {
const v = new Validator()
v.lint(str3)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, '75487f0db80e70a3e27fabfe323a33258dfbbea8', 'sha')
tt.equal(c.date, 'Fri Apr 15 13:32:36 2016 +0200', 'date')
tt.same(c.subsystems, ['module'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/6215', 'pr')
tt.equal(c.revert, false, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 2, 'messages.length')
const ids = filtered.map((item) => {
return item.id
})
const exp = ['line-length', 'title-length']
tt.same(ids.sort(), exp.sort(), 'message ids')
tt.end()
})
})
t.test('accept revert commit titles that are elongated by git', (tt) => {
const v = new Validator()
v.lint(str10)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'b04fe688d5859f707cf1a5e0206967268118bf7a', 'sha')
tt.equal(c.date, 'Sun May 1 21:10:21 2022 +0530', 'date')
tt.same(c.subsystems, ['bootstrap'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/42934', 'pr')
tt.equal(c.revert, true, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 0, 'messages.length')
tt.end()
})
})
t.test('reject revert commit titles whose original titles are really long', (tt) => {
const v = new Validator()
v.lint(str11)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'b04fe688d5859f707cf1a5e0206967268118bf7a', 'sha')
tt.equal(c.date, 'Sun May 1 21:10:21 2022 +0530', 'date')
tt.same(c.subsystems, ['bootstrap'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/42934', 'pr')
tt.equal(c.revert, true, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 1, 'messages.length')
const ids = filtered.map((item) => {
return item.id
})
const exp = ['title-length']
tt.same(ids.sort(), exp.sort(), 'message ids')
tt.end()
})
})
t.test('accept deps: V8 as the subsystem for revert commits', (tt) => {
const v = new Validator({
'validate-metadata': false
})
v.lint(str12)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'cbb404503c9df13aaeb3dd8b345cb3f34c8c07e4', 'sha')
tt.equal(c.date, 'Sat Oct 22 10:22:43 2022 +0200', 'date')
tt.same(c.subsystems, ['deps'], 'subsystems')
tt.equal(c.revert, true, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 0, 'messages.length')
tt.end()
})
})
t.test('invalid pr-url, missing subsystem', (tt) => {
const v = new Validator()
v.lint(str4)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, '7d3a7ea0d7df9b6f11df723dec370f49f4f87e99', 'sha')
tt.equal(c.date, 'Thu Mar 3 10:10:46 2016 -0600', 'date')
tt.same(c.subsystems, [], 'subsystems')
tt.equal(c.prUrl, '#5546', 'pr')
tt.equal(c.revert, false, 'revert')
const msgs = data.messages
msgs.sort((a, b) => {
return a.id < b.id
? -1
: a.id > b.id
? 1
: 0
})
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 3, 'messages.length')
tt.equal(filtered[0].id, 'line-after-title', 'message id')
tt.equal(filtered[1].id, 'pr-url', 'message id')
tt.equal(filtered[1].string, '#5546', 'message string')
tt.equal(filtered[2].id, 'subsystem', 'message id')
tt.equal(filtered[2].line, 0, 'line')
tt.equal(filtered[2].column, 0, 'column')
tt.end()
})
})
t.test('invalid pr-url, missing subsystem no meta', (tt) => {
const v = new Validator({
'validate-metadata': false
})
v.lint(str5)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, '7d3a7ea0d7df9b6f11df723dec370f49f4f87e99', 'sha')
tt.equal(c.date, 'Thu Mar 3 10:10:46 2016 -0600', 'date')
tt.same(c.subsystems, ['test'], 'subsystems')
tt.equal(c.prUrl, null, 'pr')
tt.equal(c.revert, false, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 0, 'messages.length')
tt.end()
})
})
t.test('non empty lines after metadata', (tt) => {
const v = new Validator()
v.lint(str6)
v.on('commit', (data) => {
const c = data.commit.toJSON()
tt.equal(c.sha, 'c5545f2c63fe30b0cfcdafab18c26df8286881d0', 'sha')
tt.equal(c.date, '2016-09-13T10:57:49Z', 'date')
tt.same(c.subsystems, ['fs'], 'subsystems')
tt.equal(c.prUrl, 'https://github.com/nodejs/node/pull/8515', 'pr')
tt.equal(c.revert, false, 'revert')
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 1, 'messages.length')
const item = filtered[0]
tt.equal(item.id, 'metadata-end', 'id')
tt.equal(item.message, 'commit metadata at end of message', 'message')
tt.equal(item.line, 22, 'line')
tt.equal(item.column, 0, 'column')
tt.end()
})
})
t.test('trailing punctuation in title line', (tt) => {
const v = new Validator({
'validate-metadata': false
})
v.lint(str7)
v.on('commit', (data) => {
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 1, 'messages.length')
tt.equal(filtered[0].message,
'Do not use punctuation at end of title.',
'message')
tt.end()
})
})
t.test('first word is lowercase in title line', (tt) => {
const v = new Validator({
'validate-metadata': false
})
v.lint(str8)
v.on('commit', (data) => {
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 1, 'messages.length')
tt.equal(filtered[0].message,
'First word after subsystem(s) in title should be lowercase.',
'message')
tt.equal(filtered[0].column, 7, 'column')
tt.end()
})
})
t.test('more than one formatting error in title line', (tt) => {
const v = new Validator({
'validate-metadata': false
})
v.lint(str9)
v.on('commit', (data) => {
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 2, 'messages.length')
tt.end()
})
})
t.test('validate no metadata should report commits for having metadata', (tt) => {
const v = new Validator({
'validate-no-metadata': true
})
v.lint(str)
v.on('commit', (data) => {
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 2, 'messages.length')
tt.end()
})
})
t.test('validate no metadata should not report commits without metadata', (tt) => {
const v = new Validator({
'validate-no-metadata': true
})
tt.plan(2)
v.lint(str5)
v.lint(str13)
v.on('commit', (data) => {
const msgs = data.messages
const filtered = msgs.filter((item) => {
return item.level === 'fail'
})
tt.equal(filtered.length, 0, 'messages.length')
})
})
t.end()
})