Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Nov 26, 2023
1 parent 4b8ce60 commit d185024
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
7 changes: 2 additions & 5 deletions lib/eslint/eslint-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,9 @@ function processOptions({
errors.push("'plugins' doesn't add plugins to configuration to load. Please use the 'overrideConfig.plugins' option instead.");
}
if (
reportUnusedDisableDirectives !== "error" &&
reportUnusedDisableDirectives !== "warn" &&
reportUnusedDisableDirectives !== "off" &&
reportUnusedDisableDirectives !== null
!["error", "warn", "off", 2, 1, 0, null].includes(reportUnusedDisableDirectives)
) {
errors.push("'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", and null.");
errors.push("'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", 2, 1, 0, and null.");
}
if (typeof warnIgnored !== "boolean") {
errors.push("'warnIgnored' must be a boolean.");
Expand Down
7 changes: 2 additions & 5 deletions lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,9 @@ function processOptions({
errors.push("'plugins' doesn't add plugins to configuration to load. Please use the 'overrideConfig.plugins' option instead.");
}
if (
reportUnusedDisableDirectives !== "error" &&
reportUnusedDisableDirectives !== "warn" &&
reportUnusedDisableDirectives !== "off" &&
reportUnusedDisableDirectives !== null
!["error", "warn", "off", 2, 1, 0, null].includes(reportUnusedDisableDirectives)
) {
errors.push("'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", and null.");
errors.push("'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", 2, 1, 0, and null.");
}
if (
!isNonEmptyString(resolvePluginsRelativeTo) &&
Expand Down
2 changes: 1 addition & 1 deletion lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ function normalizeVerifyOptions(providedOptions, config) {

// Handle either a boolean or severity string in linterOptions.reportUnusedDisableDirectives.
if (typeof linterOptions.reportUnusedDisableDirectives === "string") {
if (!["error", "warn", "off"].includes(linterOptions.reportUnusedDisableDirectives)) {
if (!["error", "warn", "off", 2, 1, 0].includes(linterOptions.reportUnusedDisableDirectives)) {
throw new Error("Invalid value for 'reportUnusedDisableDirectives' in config.");
}
reportUnusedDisableDirectives = linterOptions.reportUnusedDisableDirectives;
Expand Down
2 changes: 1 addition & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ module.exports = function(usingFlatConfig) {
type: "String",
default: void 0,
description: "Chooses severity level for reporting unused eslint-disable directives",
enum: ["off", "warn", "error"]
enum: ["off", "warn", "error", "2", "1", "0"]
},
{
heading: "Caching"
Expand Down
14 changes: 13 additions & 1 deletion tests/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,18 @@ describe("cli", () => {
assert.strictEqual(exitCode, 1, "exit code should be 1");
});

it("errors when --report-unused-disable-directives-severity 2", async () => {
const exitCode = await cli.execute("--no-config-lookup --report-unused-disable-directives-severity 2 --rule \"'no-console': 'error'\"",
"foo(); // eslint-disable-line no-console",
true);

assert.strictEqual(log.error.callCount, 0, "log.error should not be called");
assert.strictEqual(log.info.callCount, 1, "log.info is called once");
assert.ok(log.info.firstCall.args[0].includes("Unused eslint-disable directive (no problems were reported from 'no-console')"), "has correct message about unused directives");
assert.ok(log.info.firstCall.args[0].includes("1 error and 0 warning"), "has correct error and warning count");
assert.strictEqual(exitCode, 1, "exit code should be 1");
});

it("warns when --report-unused-disable-directives-severity warn", async () => {
const exitCode = await cli.execute("--no-config-lookup --report-unused-disable-directives-severity warn --rule \"'no-console': 'error'\"",
"foo(); // eslint-disable-line no-console",
Expand Down Expand Up @@ -1432,7 +1444,7 @@ describe("cli", () => {

assert.strictEqual(log.info.callCount, 0, "log.info should not be called");
assert.strictEqual(log.error.callCount, 1, "log.error should be called once");
assert.deepStrictEqual(log.error.firstCall.args, ["Option report-unused-disable-directives-severity: 'foo' not one of off, warn, or error.\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details."], "has the right text to log.error");
assert.deepStrictEqual(log.error.firstCall.args, ["Option report-unused-disable-directives-severity: 'foo' not one of off, warn, error, 2, 1, or 0.\nYou're using eslint.config.js, some command line flags are no longer available. Please see https://eslint.org/docs/latest/use/command-line-interface for details."], "has the right text to log.error");
assert.strictEqual(exitCode, 2, "exit code should be 2");
});

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe("ESLint", () => {
"- 'overrideConfig' must be an object or null.",
"- 'overrideConfigFile' must be a non-empty string or null.",
"- 'plugins' must be an object or null.",
"- 'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", and null.",
"- 'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", 2, 1, 0, and null.",
"- 'resolvePluginsRelativeTo' must be a non-empty string or null.",
"- 'rulePaths' must be an array of non-empty strings.",
"- 'useEslintrc' must be a boolean."
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/eslint/flat-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe("FlatESLint", () => {
"- 'overrideConfig' must be an object or null.",
"- 'overrideConfigFile' must be a non-empty string, null, or true.",
"- 'plugins' must be an object or null.",
"- 'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", and null.",
"- 'reportUnusedDisableDirectives' must be any of \"error\", \"warn\", \"off\", 2, 1, 0, and null.",
"- 'warnIgnored' must be a boolean."
].join("\n")), "u")
);
Expand Down

0 comments on commit d185024

Please sign in to comment.