Skip to content

Commit

Permalink
feat: warn by default for unused disable directives
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Dec 19, 2023
1 parent 0dd9704 commit bdfc123
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/src/use/configure/configuration-files-new.md
Expand Up @@ -76,7 +76,7 @@ Each configuration object contains all of the information ESLint needs to execut
* `parserOptions` - An object specifying additional options that are passed directly to the `parse()` or `parseForESLint()` method on the parser. The available options are parser-dependent.
* `linterOptions` - An object containing settings related to the linting process.
* `noInlineConfig` - A Boolean value indicating if inline configuration is allowed.
* `reportUnusedDisableDirectives` - A severity string indicating if and how unused disable and enable directives should be tracked and reported. For legacy compatibility, `true` is equivalent to `"warn"` and `false` is equivalent to `"off"`. (default: `"off"`)
* `reportUnusedDisableDirectives` - A severity string indicating if and how unused disable and enable directives should be tracked and reported. For legacy compatibility, `true` is equivalent to `"warn"` and `false` is equivalent to `"off"`. (default: `"warn"`)
* `processor` - Either an object containing `preprocess()` and `postprocess()` methods or a string indicating the name of a processor inside of a plugin (i.e., `"pluginName/processorName"`).
* `plugins` - An object containing a name-value mapping of plugin names to plugin objects. When `files` is specified, these plugins are only available to the matching files.
* `rules` - An object containing the configured rules. When `files` or `ignores` are specified, these rule configurations are only available to the matching files.
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/linter.js
Expand Up @@ -657,7 +657,7 @@ function normalizeVerifyOptions(providedOptions, config) {
if (typeof linterOptions.reportUnusedDisableDirectives === "boolean") {
reportUnusedDisableDirectives = linterOptions.reportUnusedDisableDirectives ? "warn" : "off";
} else {
reportUnusedDisableDirectives = linterOptions.reportUnusedDisableDirectives === void 0 ? "off" : normalizeSeverityToString(linterOptions.reportUnusedDisableDirectives);
reportUnusedDisableDirectives = linterOptions.reportUnusedDisableDirectives === void 0 ? "warn" : normalizeSeverityToString(linterOptions.reportUnusedDisableDirectives);
}
}

Expand Down
16 changes: 8 additions & 8 deletions tests/lib/rules/capitalized-comments.js
Expand Up @@ -59,8 +59,8 @@ ruleTester.run("capitalized-comments", rule, {
// No options: eslint/istanbul/jshint/jscs/globals?/exported are okay
"// jscs: enable",
"// jscs:disable",
"// eslint-disable-line",
"// eslint-disable-next-line",
"// eslint-foo-line",
"// eslint-foo-next-line",
"/* eslint semi:off */",
"/* eslint-env node */",
"/* istanbul ignore next */",
Expand Down Expand Up @@ -120,8 +120,8 @@ ruleTester.run("capitalized-comments", rule, {
// Using "always" string option: eslint/istanbul/jshint/jscs/globals?/exported are okay
{ code: "// jscs: enable", options: ["always"] },
{ code: "// jscs:disable", options: ["always"] },
{ code: "// eslint-disable-line", options: ["always"] },
{ code: "// eslint-disable-next-line", options: ["always"] },
{ code: "// eslint-foo-line", options: ["always"] },
{ code: "// eslint-foo-next-line", options: ["always"] },
{ code: "/* eslint semi:off */", options: ["always"] },
{ code: "/* eslint-env node */", options: ["always"] },
{ code: "/* istanbul ignore next */", options: ["always"] },
Expand Down Expand Up @@ -564,8 +564,8 @@ ruleTester.run("capitalized-comments", rule, {
}]
},
{
code: "//* eslint-disable-line",
output: "//* Eslint-disable-line",
code: "//* eslint-foo-line",
output: "//* Eslint-foo-line",
options: ["always"],
errors: [{
messageId: "unexpectedLowercaseComment",
Expand All @@ -574,8 +574,8 @@ ruleTester.run("capitalized-comments", rule, {
}]
},
{
code: "//* eslint-disable-next-line",
output: "//* Eslint-disable-next-line",
code: "//* eslint-foo-next-line",
output: "//* Eslint-foo-next-line",
options: ["always"],
errors: [{
messageId: "unexpectedLowercaseComment",
Expand Down
10 changes: 5 additions & 5 deletions tests/lib/rules/line-comment-position.js
Expand Up @@ -24,10 +24,10 @@ ruleTester.run("line-comment-position", rule, {
"/* block comments are skipped */\n1 + 1;",
"1 + 1; /* block comments are skipped */",
"1 + 1; /* eslint eqeqeq: 'error' */",
"1 + 1; /* eslint-disable */",
"1 + 1; /* eslint-enable */",
"1 + 1; // eslint-disable-line",
"// eslint-disable-next-line\n1 + 1;",
"1 + 1; /* eslint-foo-disable */",
"1 + 1; /* eslint-foo-enable */",
"1 + 1; // eslint-foo-disable-line",
"// eslint-foo-disable-next-line\n1 + 1;",
"1 + 1; // global MY_GLOBAL, ANOTHER",
"1 + 1; // globals MY_GLOBAL: true",
"1 + 1; // exported MY_GLOBAL, ANOTHER",
Expand Down Expand Up @@ -82,7 +82,7 @@ ruleTester.run("line-comment-position", rule, {
options: [{ ignorePattern: "ignored" }]
},
{
code: "foo; // eslint-disable-line no-alert",
code: "foo; // eslint-foo-disable-line no-alert",
options: [{ position: "above" }]
}
],
Expand Down
12 changes: 6 additions & 6 deletions tests/lib/rules/lines-around-comment.js
Expand Up @@ -1026,10 +1026,10 @@ ruleTester.run("lines-around-comment", rule, {
{
code:
"foo;\n\n" +
"/* eslint-disable no-underscore-dangle */\n\n" +
"/* eslint-foo-disable no-underscore-dangle */\n\n" +
"this._values = values;\n" +
"this._values2 = true;\n" +
"/* eslint-enable no-underscore-dangle */\n" +
"/* eslint-foo-enable no-underscore-dangle */\n" +
"bar",
options: [{
beforeBlockComment: true,
Expand Down Expand Up @@ -2088,18 +2088,18 @@ ruleTester.run("lines-around-comment", rule, {
{
code:
"foo;\n\n" +
"/* eslint-disable no-underscore-dangle */\n\n" +
"/* eslint-foo-disable no-underscore-dangle */\n\n" +
"this._values = values;\n" +
"this._values2 = true;\n" +
"/* eslint-enable no-underscore-dangle */\n" +
"/* eslint-foo-enable no-underscore-dangle */\n" +
"bar",
output:
"foo;\n\n" +
"/* eslint-disable no-underscore-dangle */\n\n" +
"/* eslint-foo-disable no-underscore-dangle */\n\n" +
"this._values = values;\n" +
"this._values2 = true;\n" +
"\n" +
"/* eslint-enable no-underscore-dangle */\n" +
"/* eslint-foo-enable no-underscore-dangle */\n" +
"\n" +
"bar",
options: [{
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/no-inline-comments.js
Expand Up @@ -41,8 +41,8 @@ ruleTester.run("no-inline-comments", rule, {
"// A valid comment before code\nvar a = 1;",
"var a = 2;\n// A valid comment after code",
"// A solitary comment",
"var a = 1; // eslint-disable-line no-debugger",
"var a = 1; /* eslint-disable-line no-debugger */",
"var a = 1; // eslint-foo-line no-debugger",
"var a = 1; /* eslint-foo-line no-debugger */",
"foo(); /* global foo */",
"foo(); /* globals foo */",
"var foo; /* exported foo */",
Expand Down Expand Up @@ -138,7 +138,7 @@ ruleTester.run("no-inline-comments", rule, {
errors: [lineError]
},
{
code: "var a = 3; // someday use eslint-disable-line here",
code: "var a = 3; // someday use eslint-foo-line here",
errors: [lineError]
},
{
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/spaced-comment.js
Expand Up @@ -163,8 +163,8 @@ ruleTester.run("spaced-comment", rule, {
options: ["always", { markers: ["eslint"] }]
},
{
code: "/*eslint-disable no-alert, no-console */\nalert()\nconsole.log()\n/*eslint-enable no-alert */",
options: ["always", { markers: ["eslint-enable", "eslint-disable"] }]
code: "/*eslint-foo-disable no-alert, no-console */\nalert()\nconsole.log()\n/*eslint-foo-enable no-alert */",
options: ["always", { markers: ["eslint-foo-enable", "eslint-foo-disable"] }]
},

// misc. variations
Expand Down

0 comments on commit bdfc123

Please sign in to comment.