Skip to content

Commit 3cd7256

Browse files
committed
Revert "Update: make no-unused-disable fixable (#13)"
This reverts commit f625cd6. # Conflicts: # docs/rules/no-unused-disable.md
1 parent 0edf03c commit 3cd7256

File tree

4 files changed

+18
-131
lines changed

4 files changed

+18
-131
lines changed

docs/rules/no-unused-disable.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
> disallow unused `eslint-disable` comments
44
5-
- ✒️ The `--fix` option on the [command line](http://eslint.org/docs/user-guide/command-line-interface#fix) can automatically fix some of the problems reported by this rule.
6-
75
Since refactoring or a bug fix of upstream, an `eslint-disable` directive-comment may become unnecessary.
86
In that case, you should remove the garbage as soon as possible since the garbage may cause to overlook ESLint warnings in future.
97

lib/rules/no-unused-disable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
url:
1818
"https://mysticatea.github.io/eslint-plugin-eslint-comments/rules/no-unused-disable.html",
1919
},
20-
fixable: "code",
20+
fixable: null,
2121
schema: [],
2222
},
2323

lib/utils/patch.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ function createNoUnusedDisableError(ruleId, severity, message, comment) {
9898
clone.endLine = comment.loc.end.line
9999
clone.endColumn = comment.loc.end.column + 1
100100
}
101-
102-
// Remove the whole node if it is the only rule, otherwise
103-
// don't try to fix because it is quite complicated.
104-
if (!comment.value.includes(",")) {
105-
// We can't use the typical `fixer` helper because we are injecting
106-
// this message after the fixes are resolved.
107-
clone.fix = {
108-
range: comment.range,
109-
text: comment.value.includes("\n") ? "\n" : "",
110-
}
111-
}
112101
}
113102

114103
return clone

tests/lib/rules/no-unused-disable.js

Lines changed: 17 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,10 @@ function baz() {
143143
})
144144

145145
describe("invalid", () => {
146-
for (const testCase of [
146+
for (const { code, errors, reportUnusedDisableDirectives } of [
147147
{
148-
title: "Generic same line",
149148
code: `/*eslint no-undef:off*/
150149
var a = b //eslint-disable-line`,
151-
output: `/*eslint no-undef:off*/
152-
var a = b `,
153150
errors: [
154151
{
155152
message:
@@ -162,11 +159,8 @@ var a = b `,
162159
],
163160
},
164161
{
165-
title: "Specific same line",
166162
code: `/*eslint no-undef:off*/
167163
var a = b //eslint-disable-line no-undef`,
168-
output: `/*eslint no-undef:off*/
169-
var a = b `,
170164
errors: [
171165
{
172166
message:
@@ -179,7 +173,6 @@ var a = b `,
179173
],
180174
},
181175
{
182-
title: "Multiple in a same line",
183176
code: `/*eslint no-undef:off, no-unused-vars:off*/
184177
var a = b //eslint-disable-line no-undef,no-unused-vars`,
185178
errors: [
@@ -202,12 +195,8 @@ var a = b //eslint-disable-line no-undef,no-unused-vars`,
202195
],
203196
},
204197
{
205-
title: "Generic next line",
206198
code: `/*eslint no-undef:off*/
207199
//eslint-disable-next-line
208-
var a = b`,
209-
output: `/*eslint no-undef:off*/
210-
211200
var a = b`,
212201
errors: [
213202
{
@@ -221,12 +210,8 @@ var a = b`,
221210
],
222211
},
223212
{
224-
title: "Specific next line",
225213
code: `/*eslint no-undef:off*/
226214
//eslint-disable-next-line no-undef
227-
var a = b`,
228-
output: `/*eslint no-undef:off*/
229-
230215
var a = b`,
231216
errors: [
232217
{
@@ -240,7 +225,6 @@ var a = b`,
240225
],
241226
},
242227
{
243-
title: "Multiple next line",
244228
code: `/*eslint no-undef:off, no-unused-vars:off*/
245229
//eslint-disable-next-line no-undef,no-unused-vars
246230
var a = b`,
@@ -264,12 +248,8 @@ var a = b`,
264248
],
265249
},
266250
{
267-
title: "Generic block",
268251
code: `/*eslint no-undef:off*/
269252
/*eslint-disable*/
270-
var a = b`,
271-
output: `/*eslint no-undef:off*/
272-
273253
var a = b`,
274254
errors: [
275255
{
@@ -283,29 +263,8 @@ var a = b`,
283263
],
284264
},
285265
{
286-
title: "Replaces multi-line block comments with a newline",
287-
code: `foo/* eslint-disable
288-
*/ bar`,
289-
output: `foo
290-
bar`,
291-
errors: [
292-
{
293-
message:
294-
"ESLint rules are disabled but never reported.",
295-
line: 1,
296-
column: 4,
297-
endLine: 2,
298-
endColumn: 3,
299-
},
300-
],
301-
},
302-
{
303-
title: "Specific block",
304266
code: `/*eslint no-undef:off*/
305267
/*eslint-disable no-undef*/
306-
var a = b`,
307-
output: `/*eslint no-undef:off*/
308-
309268
var a = b`,
310269
errors: [
311270
{
@@ -319,7 +278,6 @@ var a = b`,
319278
],
320279
},
321280
{
322-
title: "Multiple block",
323281
code: `/*eslint no-undef:off, no-unused-vars:off*/
324282
/*eslint-disable no-undef,no-unused-vars*/
325283
var a = b`,
@@ -343,13 +301,8 @@ var a = b`,
343301
],
344302
},
345303
{
346-
title: "Generic block with enable after",
347304
code: `/*eslint no-undef:off*/
348305
/*eslint-disable*/
349-
var a = b
350-
/*eslint-enable*/`,
351-
output: `/*eslint no-undef:off*/
352-
353306
var a = b
354307
/*eslint-enable*/`,
355308
errors: [
@@ -364,13 +317,8 @@ var a = b
364317
],
365318
},
366319
{
367-
title: "Specific block with enable after",
368320
code: `/*eslint no-undef:off*/
369321
/*eslint-disable no-undef*/
370-
var a = b
371-
/*eslint-enable*/`,
372-
output: `/*eslint no-undef:off*/
373-
374322
var a = b
375323
/*eslint-enable*/`,
376324
errors: [
@@ -385,7 +333,6 @@ var a = b
385333
],
386334
},
387335
{
388-
title: "Multiple block with enable after",
389336
code: `/*eslint no-undef:off, no-unused-vars:off*/
390337
/*eslint-disable no-undef,no-unused-vars*/
391338
var a = b
@@ -410,13 +357,8 @@ var a = b
410357
],
411358
},
412359
{
413-
title: "Generic block disable with no error inside",
414360
code: `/*eslint no-undef:error*/
415361
/*eslint-disable*/
416-
/*eslint-enable*/
417-
var a = b//eslint-disable-line no-undef`,
418-
output: `/*eslint no-undef:error*/
419-
420362
/*eslint-enable*/
421363
var a = b//eslint-disable-line no-undef`,
422364
errors: [
@@ -431,13 +373,8 @@ var a = b//eslint-disable-line no-undef`,
431373
],
432374
},
433375
{
434-
title: "Specific block disable with no error inside",
435376
code: `/*eslint no-undef:error*/
436377
/*eslint-disable no-undef*/
437-
/*eslint-enable no-undef*/
438-
var a = b//eslint-disable-line no-undef`,
439-
output: `/*eslint no-undef:error*/
440-
441378
/*eslint-enable no-undef*/
442379
var a = b//eslint-disable-line no-undef`,
443380
errors: [
@@ -452,7 +389,6 @@ var a = b//eslint-disable-line no-undef`,
452389
],
453390
},
454391
{
455-
title: "Multiple specific block disable with no error inside",
456392
code: `/*eslint no-undef:error, no-unused-vars:error*/
457393
/*eslint-disable no-undef,no-unused-vars*/
458394
/*eslint-enable no-undef*/
@@ -469,8 +405,6 @@ var a = b//eslint-disable-line no-undef`,
469405
],
470406
},
471407
{
472-
title:
473-
"Multiple specific block disable with only one error inside",
474408
code: `/*eslint no-undef:error, no-unused-vars:error*/
475409
/*eslint-disable
476410
no-undef,
@@ -490,10 +424,8 @@ var a = b
490424
],
491425
},
492426
{
493-
title: "Specific block disable at end of input",
494427
code:
495428
"/* eslint new-parens:error*/ /*eslint-disable new-parens*/",
496-
output: "/* eslint new-parens:error*/ ",
497429
errors: [
498430
{
499431
message:
@@ -506,11 +438,8 @@ var a = b
506438
],
507439
},
508440
{
509-
title: "Generic same line with rule off",
510441
code: `/*eslint no-undef:off*/
511442
var a = b //eslint-disable-line`,
512-
output: `/*eslint no-undef:off*/
513-
var a = b `,
514443
errors: [
515444
{
516445
message:
@@ -528,11 +457,8 @@ var a = b `,
528457
reportUnusedDisableDirectives: true,
529458
},
530459
{
531-
title: "Specific same line with rule off",
532460
code: `/*eslint no-undef:off*/
533461
var a = b //eslint-disable-line no-undef`,
534-
output: `/*eslint no-undef:off*/
535-
var a = b `,
536462
errors: [
537463
{
538464
message:
@@ -550,8 +476,8 @@ var a = b `,
550476
reportUnusedDisableDirectives: true,
551477
},
552478

479+
// Don't crash even if the source code has a parse error.
553480
{
554-
title: "Don't crash even if the source code has a parse error",
555481
code:
556482
"/*eslint no-undef:error*/\nvar a = b c //eslint-disable-line no-undef",
557483
errors: [
@@ -561,50 +487,24 @@ var a = b `,
561487
],
562488
},
563489
]) {
564-
it(testCase.title || testCase.code, () =>
565-
runESLint(
566-
testCase.code,
567-
testCase.reportUnusedDisableDirectives
568-
).then(actualMessages => {
569-
assert.strictEqual(
570-
actualMessages.length,
571-
testCase.errors.length
572-
)
573-
574-
let actualOutput = testCase.code
575-
576-
for (let i = 0; i < testCase.errors.length; ++i) {
577-
const actual = actualMessages[i]
578-
const expected = testCase.errors[i]
579-
580-
// We need to duplicate the simple logic in ESLint's
581-
// source-code-fixer.js to apply the fix. If we run
582-
// ESLint with --fix-dry-run, it won't report any
583-
// errors since it would have fixed them.
584-
if (actual.fix) {
585-
actualOutput =
586-
actualOutput.slice(0, actual.fix.range[0]) +
587-
actual.fix.text +
588-
actualOutput.slice(actual.fix.range[1])
589-
}
490+
it(code, () =>
491+
runESLint(code, reportUnusedDisableDirectives).then(
492+
actualMessages => {
493+
assert.strictEqual(actualMessages.length, errors.length)
494+
for (let i = 0; i < errors.length; ++i) {
495+
const actual = actualMessages[i]
496+
const expected = errors[i]
590497

591-
for (const key of Object.keys(expected)) {
592-
assert.strictEqual(
593-
actual[key],
594-
expected[key],
595-
`'${key}' is not expected.`
596-
)
498+
for (const key of Object.keys(expected)) {
499+
assert.strictEqual(
500+
actual[key],
501+
expected[key],
502+
`'${key}' is not expected.`
503+
)
504+
}
597505
}
598506
}
599-
600-
if (testCase.output) {
601-
assert.strictEqual(
602-
actualOutput,
603-
testCase.output,
604-
"output is not expected"
605-
)
606-
}
607-
})
507+
)
608508
)
609509
}
610510
})

0 commit comments

Comments
 (0)