Skip to content

Commit

Permalink
run CLI tests for both flat and eslintrc
Browse files Browse the repository at this point in the history
  • Loading branch information
bmish committed Dec 8, 2023
1 parent 54cc4a3 commit 691b142
Showing 1 changed file with 101 additions and 71 deletions.
172 changes: 101 additions & 71 deletions tests/lib/cli.js
Expand Up @@ -1367,94 +1367,124 @@ describe("cli", () => {
});
});

// ---------
});
describe("when passing --report-unused-disable-directives", () => {
describe(`config type: ${configType}`, () => {
it("errors when --report-unused-disable-directives", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives --rule "'no-console': 'error'"`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

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("errors when --report-unused-disable-directives-severity error", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity error --rule "'no-console': 'error'"`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

describe("when given a config file", () => {
it("should load the specified config file", async () => {
const configPath = getFixturePath(".eslintrc");
const filePath = getFixturePath("passing.js");
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");
});

await cli.execute(`--config ${configPath} ${filePath}`);
});
});
it("errors when --report-unused-disable-directives-severity 2", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity 2 --rule "'no-console': 'error'"`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

describe("--report-unused-disable-directives", () => {
it("errors when --report-unused-disable-directives", async () => {
const exitCode = await cli.execute("--no-config-lookup --report-unused-disable-directives --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");
});
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("errors when --report-unused-disable-directives-severity error", async () => {
const exitCode = await cli.execute("--no-config-lookup --report-unused-disable-directives-severity error --rule \"'no-console': 'error'\"",
"foo(); // eslint-disable-line no-console",
true);
it("warns when --report-unused-disable-directives-severity warn", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity warn --rule "'no-console': 'error'""`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

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");
});
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("0 errors and 1 warning"), "has correct error and warning count");
assert.strictEqual(exitCode, 0, "exit code should be 0");
});

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);
it("warns when --report-unused-disable-directives-severity 1", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity 1 --rule "'no-console': 'error'"`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

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");
});
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("0 errors and 1 warning"), "has correct error and warning count");
assert.strictEqual(exitCode, 0, "exit code should be 0");
});

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",
true);
it("does not report when --report-unused-disable-directives-severity off", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity off --rule "'no-console': 'error'"`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

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("0 errors and 1 warning"), "has correct error and warning count");
assert.strictEqual(exitCode, 0, "exit code should be 0");
});
assert.strictEqual(log.error.callCount, 0, "log.error should not be called");
assert.strictEqual(log.info.callCount, 0, "log.info should not be called");
assert.strictEqual(exitCode, 0, "exit code should be 0");
});

it("does not report when --report-unused-disable-directives-severity off", async () => {
const exitCode = await cli.execute("--no-config-lookup --report-unused-disable-directives-severity off --rule \"'no-console': 'error'\"",
"foo(); // eslint-disable-line no-console",
true);
it("does not report when --report-unused-disable-directives-severity 0", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity 0 --rule "'no-console': 'error'"`,
"foo(); // eslint-disable-line no-console",
useFlatConfig);

assert.strictEqual(log.error.callCount, 0, "log.error should not be called");
assert.strictEqual(log.info.callCount, 0, "log.info should not be called");
assert.strictEqual(exitCode, 0, "exit code should be 0");
});
assert.strictEqual(log.error.callCount, 0, "log.error should not be called");
assert.strictEqual(log.info.callCount, 0, "log.info should not be called");
assert.strictEqual(exitCode, 0, "exit code should be 0");
});

it("fails when passing invalid string for --report-unused-disable-directives-severity", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives-severity foo`, null, useFlatConfig);

assert.strictEqual(log.info.callCount, 0, "log.info should not be called");
assert.strictEqual(log.error.callCount, 1, "log.error should be called once");

const lines = ["Option report-unused-disable-directives-severity: 'foo' not one of off, warn, error, 0, 1, or 2."];

if (useFlatConfig) {
lines.push("You'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.");
}
assert.deepStrictEqual(log.error.firstCall.args, [lines.join("\n")], "has the right text to log.error");
assert.strictEqual(exitCode, 2, "exit code should be 2");
});

it("fails when passing invalid string for --report-unused-disable-directives-severity", async () => {
const exitCode = await cli.execute("--report-unused-disable-directives-severity foo", null, true);
it("fails when passing both --report-unused-disable-directives and --report-unused-disable-directives-severity", async () => {
const exitCode = await cli.execute(`${useFlatConfig ? "--no-config-lookup" : "--no-eslintrc"} --report-unused-disable-directives --report-unused-disable-directives-severity warn`, null, useFlatConfig);

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, error, 0, 1, or 2.\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");
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, ["The --report-unused-disable-directives option and the --report-unused-disable-directives-severity option cannot be used together."], "has the right text to log.error");
assert.strictEqual(exitCode, 2, "exit code should be 2");
});
});
});

it("fails when passing both --report-unused-disable-directives and --report-unused-disable-directives-severity", async () => {
const exitCode = await cli.execute("--report-unused-disable-directives --report-unused-disable-directives-severity warn", null, true);
// ---------
});


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, ["The --report-unused-disable-directives option and the --report-unused-disable-directives-severity option cannot be used together."], "has the right text to log.error");
assert.strictEqual(exitCode, 2, "exit code should be 2");
describe("when given a config file", () => {
it("should load the specified config file", async () => {
const configPath = getFixturePath(".eslintrc");
const filePath = getFixturePath("passing.js");

await cli.execute(`--config ${configPath} ${filePath}`);
});
});

Expand Down

0 comments on commit 691b142

Please sign in to comment.