forked from sindresorhus/eslint-plugin-unicorn
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expiring-todo-comments.js
398 lines (385 loc) · 13.7 KB
/
expiring-todo-comments.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
import test from 'ava';
import avaRuleTester from 'eslint-ava-rule-tester';
import rule from '../rules/expiring-todo-comments';
const ruleTester = avaRuleTester(test, {
env: {
es6: true
}
});
const expiredTodoError = (expirationDate, message) => ({
message: `There is a TODO that is past due date: ${expirationDate}. ${message}`
});
const avoidMultipleDatesError = (expirationDates, message) => ({
message: `Avoid using multiple expiration dates in TODO: ${expirationDates}. ${message}`
});
const havePackageError = (package_, message) => ({
message: `There is a TODO that is deprecated since you installed: ${package_}. ${message}`
});
const dontHavePackageError = (package_, message) => ({
message: `There is a TODO that is deprecated since you uninstalled: ${package_}. ${message}`
});
const versionMatchesError = (comparison, message) => ({
message: `There is a TODO match for package version: ${comparison}. ${message}`
});
const engineMatchesError = (comparison, message) => ({
message: `There is a TODO match for Node.js version: ${comparison}. ${message}`
});
const reachedPackageVersionError = (version, message) => ({
message: `There is a TODO that is past due package version: ${version}. ${message}`
});
const avoidMultiplePackageVersionsError = (versions, message) => ({
message: `Avoid using multiple package versions in TODO: ${versions}. ${message}`
});
const removeWhitespacesError = (argument, message) => ({
message: `Avoid using whitespaces on TODO argument. On '${argument}' use '${argument.replace(/ /g, '')}'. ${message}`
});
const missingAtSymbolError = (bad, good, message) => ({
message: `Missing '@' on TODO argument. On '${bad}' use '${good}'. ${message}`
});
const noWarningCommentError = comment => ({
message: `Unexpected 'todo' comment: '${comment}'.`
});
ruleTester.run('expiring-todo-comments', rule, {
valid: [
'// TODO [2200-12-12]: Too long... Can you feel it?',
'// FIXME [2200-12-12]: Too long... Can you feel it?',
'// XXX [2200-12-12]: Too long... Can you feel it?',
'// TODO (lubien) [2200-12-12]: Too long... Can you feel it?',
'// FIXME [2200-12-12] (lubien): Too long... Can you feel it?',
{
code: '// Expire Condition [2200-12-12]: new term name',
errors: [],
options: [{terms: ['Expire Condition']}]
},
'// Expire Condition [2000-01-01]: new term name',
'// TODO [>2000]: We sure didnt past this version',
'// TODO [-read-pkg-up]: We actually use this.',
'// TODO [+popura]: I think we wont need a broken package.',
'// TODO [semver@>1000]: Welp hopefully we wont get at that.',
'// TODO [semver@>=1000]: Welp hopefully we wont get at that.',
'// TODO [@lubien/fixture-beta-package@>=1.0.0]: we are using a pre-release',
'// TODO [@lubien/fixture-beta-package@>=1.0.0-gamma.1]: beta comes first from gamma',
'// TODO [@lubien/fixture-beta-package@>=1.0.0-beta.2]: we are in beta.1',
'// TODO [2200-12-12, -read-pkg-up]: Combo',
'// TODO [2200-12-12, -read-pkg-up, +popura]: Combo',
'// TODO [2200-12-12, -read-pkg-up, +popura, semver@>=1000]: Combo',
'// TODO [engine:node@>=100]: When we start supporting only >= 10',
`// TODO [2200-12-12]: Multiple
// TODO [2200-12-12]: Lines`,
`/*
* TODO [2200-12-12]: Yet
* TODO [engine:node@>=100]: Another
* TODO [+popura]: Way
*/`,
{
code: '// TODO',
errors: []
},
{
code: '// TODO [invalid]',
errors: []
},
{
code: '// TODO [] might have [some] that [try [to trick] me]',
errors: []
},
{
code: '// TODO [but [it will]] [fallback] [[[ to the default ]]] rule [[',
errors: []
},
{
code: '// TODO ISSUE-123 fix later',
options: [{allowWarningComments: false, ignore: ['ISSUE-\\d+']}]
},
{
code: '// TODO [ISSUE-123] fix later',
options: [{allowWarningComments: false, ignore: ['ISSUE-\\d+']}]
},
{
code: '// TODO [1999-01-01, ISSUE-123] fix later',
options: [{allowWarningComments: false, ignore: ['ISSUE-\\d+']}]
},
{
code: '// TODO [Issue-123] fix later',
options: [{allowWarningComments: false, ignore: [/issue-\d+/i]}]
}
],
invalid: [
{
code: '// TODO [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: `/*
* TODO [2000-01-01]: Yet
* TODO [2000-01-01]: Another
* TODO [2000-01-01]: Way
*/`,
errors: [
expiredTodoError('2000-01-01', 'Yet'),
expiredTodoError('2000-01-01', 'Another'),
expiredTodoError('2000-01-01', 'Way')
],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: `/*
* TODO [2000-01-01]: Invalid
* TODO [2200-01-01]: Valid
* TODO [2000-01-01]: Invalid
*/`,
errors: [
expiredTodoError('2000-01-01', 'Invalid'),
expiredTodoError('2000-01-01', 'Invalid')
],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: `/*
* Something here
* TODO [engine:node@>=8]: Invalid
* Also something here
*/`,
errors: [
engineMatchesError('node>=8', 'Invalid')
],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// fixme [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// xxx [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// ToDo [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// fIxME [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// Todoist [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false, terms: ['Todoist']}]
},
{
code: '// Expire Condition [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false, terms: ['Expire Condition']}]
},
{
code: '// XxX [2000-01-01]: too old',
errors: [expiredTodoError('2000-01-01', 'too old')],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// TODO [2200-12-12, 2200-12-12]: Multiple dates',
errors: [avoidMultipleDatesError('2200-12-12, 2200-12-12', 'Multiple dates')],
output: '// TODO [2200-12-12, 2200-12-12]: Multiple dates'
},
{
code: '// TODO [>1]: if your package.json version is >1',
errors: [reachedPackageVersionError('>1', 'if your package.json version is >1')]
},
{
code: '// TODO [>1, >2]: multiple package versions',
errors: [avoidMultiplePackageVersionsError('>1, >2', 'multiple package versions')]
},
{
code: '// TODO [>=1]: if your package.json version is >=1',
errors: [reachedPackageVersionError('>=1', 'if your package.json version is >=1')]
},
{
code: '// TODO [+read-pkg-up]: when you install `read-pkg-up`',
errors: [havePackageError('read-pkg-up', 'when you install `read-pkg-up`')]
},
{
code: '// TODO [-popura]: when you uninstall `popura`',
errors: [dontHavePackageError('popura', 'when you uninstall `popura`')]
},
{
code: '// TODO [read-pkg-up@>1]: when `read-pkg-up` version is > 1',
errors: [versionMatchesError('read-pkg-up > 1', 'when `read-pkg-up` version is > 1')]
},
{
code: '// TODO [engine:node@>=8]: when support is for node >= 8',
errors: [engineMatchesError('node>=8', 'when support is for node >= 8')]
},
{
code: '// TODO [read-pkg-up@>=5.1.1]: when `read-pkg-up` version is >= 5.1.1',
errors: [versionMatchesError('read-pkg-up >= 5.1.1', 'when `read-pkg-up` version is >= 5.1.1')]
},
{
code: '// TODO [@lubien/fixture-beta-package@>=1.0.0-alfa.1]: when `@lubien/fixture-beta-package` version is >= 1.0.0-alfa.1',
errors: [versionMatchesError('@lubien/fixture-beta-package >= 1.0.0-alfa.1', 'when `@lubien/fixture-beta-package` version is >= 1.0.0-alfa.1')]
},
{
code: '// TODO [@lubien/fixture-beta-package@>=1.0.0-beta.1]: when `@lubien/fixture-beta-package` version is >= 1.0.0-beta.1',
errors: [versionMatchesError('@lubien/fixture-beta-package >= 1.0.0-beta.1', 'when `@lubien/fixture-beta-package` version is >= 1.0.0-beta.1')]
},
{
code: '// TODO [@lubien/fixture-beta-package@>=1.0.0-beta.0]: when `@lubien/fixture-beta-package` version is >= 1.0.0-beta.0',
errors: [versionMatchesError('@lubien/fixture-beta-package >= 1.0.0-beta.0', 'when `@lubien/fixture-beta-package` version is >= 1.0.0-beta.0')]
},
{
code: '// TODO [semver>1]: Missing @.',
errors: [missingAtSymbolError('semver>1', 'semver@>1', 'Missing @.')]
},
{
code: '// TODO [> 1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('> 1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO [semver@> 1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('semver@> 1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO [semver @>1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('semver @>1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO [semver@>= 1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('semver@>= 1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO [semver @>=1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('semver @>=1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO [engine:node @>=1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('engine:node @>=1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO [engine:node@>= 1]: Remove whitespaces when it can fix.',
errors: [removeWhitespacesError('engine:node@>= 1', 'Remove whitespaces when it can fix.')]
},
{
code: '// TODO',
errors: [noWarningCommentError('TODO')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO []',
errors: [noWarningCommentError('TODO []')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [no meaning at all]',
errors: [noWarningCommentError('TODO [no meaning at all]')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [] might have [some] that [try [to trick] me]',
errors: [noWarningCommentError('TODO [] might have [some] that [try [to...')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [but [it will]] [fallback] [[[ to the default ]]] rule [[[',
errors: [noWarningCommentError('TODO [but [it will]] [fallback] [[[ to...')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [engine:npm@>=10000]: Unsupported engine',
errors: [noWarningCommentError('TODO [engine:npm@>=10000]: Unsupported...')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [engine:somethingrandom@>=10000]: Unsupported engine',
errors: [noWarningCommentError('TODO [engine:somethingrandom@>=10000]:...')],
options: [{allowWarningComments: false}]
},
{
code: '// TODO [2000-01-01, >1]: Combine date with package version',
errors: [
expiredTodoError('2000-01-01', 'Combine date with package version'),
reachedPackageVersionError('>1', 'Combine date with package version')
],
options: [{ignoreDatesOnPullRequests: false}]
},
{
code: '// TODO [2200-12-12, >1, 2200-12-12, >2]: Multiple dates and package versions',
errors: [
avoidMultipleDatesError('2200-12-12, 2200-12-12', 'Multiple dates and package versions'),
avoidMultiplePackageVersionsError('>1, >2', 'Multiple dates and package versions')
]
},
{
code: '// TODO [-popura, read-pkg-up@>1]: Combine not having a package with version match',
errors: [
dontHavePackageError('popura', 'Combine not having a package with version match'),
versionMatchesError('read-pkg-up > 1', 'Combine not having a package with version match')
]
},
{
code: '// TODO [+read-pkg-up, -popura]: Combine presence/absence of packages',
errors: [
havePackageError('read-pkg-up', 'Combine presence/absence of packages'),
dontHavePackageError('popura', 'Combine presence/absence of packages')
]
},
{
code: '// Expire Condition [2000-01-01, semver>1]: Expired TODO and missing symbol',
errors: [
expiredTodoError('2000-01-01', 'Expired TODO and missing symbol'),
missingAtSymbolError('semver>1', 'semver@>1', 'Expired TODO and missing symbol')
],
options: [{ignoreDatesOnPullRequests: false, terms: ['Expire Condition']}]
},
{
code: '// TODO [semver @>=1, -popura]: Package uninstalled and whitespaces error',
errors: [
dontHavePackageError('popura', 'Package uninstalled and whitespaces error'),
removeWhitespacesError('semver @>=1', 'Package uninstalled and whitespaces error')
]
},
{
code: '// HUGETODO [semver @>=1, engine:node@>=8, 2000-01-01, -popura, >1, +read-pkg-up, read-pkg-up@>1]: Big mix',
errors: [
expiredTodoError('2000-01-01', 'Big mix'),
reachedPackageVersionError('>1', 'Big mix'),
dontHavePackageError('popura', 'Big mix'),
havePackageError('read-pkg-up', 'Big mix'),
versionMatchesError('read-pkg-up > 1', 'Big mix'),
engineMatchesError('node>=8', 'Big mix'),
removeWhitespacesError('semver @>=1', 'Big mix')
],
options: [{ignoreDatesOnPullRequests: false, terms: ['HUGETODO']}]
},
{
code: '// TODO [ISSUE-123] fix later',
options: [{allowWarningComments: false, ignore: []}],
errors: [
noWarningCommentError('TODO [ISSUE-123] fix later')
]
},
{
code: `
// TODO fix later
// TODO ISSUE-123 fix later
`,
options: [{allowWarningComments: false, ignore: [/issue-\d+/i]}],
errors: [
noWarningCommentError('TODO fix later')
]
},
{
code: `/*
TODO Invalid
TODO ISSUE-123 Valid
*/`,
options: [{allowWarningComments: false, ignore: [/issue-\d+/i]}],
errors: [
noWarningCommentError('TODO Invalid')
]
}
]
});