Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit warning when .eslintignore file is detected #17952

Merged
merged 9 commits into from Jan 19, 2024
7 changes: 7 additions & 0 deletions lib/eslint/eslint.js
Expand Up @@ -613,6 +613,13 @@ class ESLint {
});
}

// Check for the .eslintignore file, and warn if it's present.
if (existsSync(path.resolve(processedOptions.cwd, ".eslintignore"))) {
process.emitWarning(
"The \".eslintignore\" file is no longer supported. For an upgrade, switch to using the \"ignores\" property in a config object. See https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files for details.",
"ESLintIgnoreWarning"
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/bin/eslint.js
Expand Up @@ -123,7 +123,7 @@ describe("bin/eslint.js", () => {
const exitCodePromise = assertExitCode(child, 0);
const stdoutPromise = getOutput(child).then(output => {
assert.strictEqual(output.stdout.trim(), expectedOutput);
assert.strictEqual(output.stderr, "");
assert.match(output.stderr, /ESLintIgnoreWarning: The ".eslintignore" file is no longer supported./u);
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
});

child.stdin.write("var foo = bar;;\n");
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/eslint/eslint.js
Expand Up @@ -4603,6 +4603,20 @@ describe("ESLint", () => {

await assert.rejects(() => eslint.isPathIgnored(null), /'filePath' must be a non-empty string/u);
});

it("should warn if .eslintignore file is present", async () => {
snitin315 marked this conversation as resolved.
Show resolved Hide resolved
const cwd = getFixturePath("ignored-paths");
const processStub = sinon.stub(process, "emitWarning");

// eslint-disable-next-line no-new -- for testing purpose only
new ESLint({ cwd });

assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once");
assert.strictEqual(processStub.getCall(0).args[0], "The \".eslintignore\" file is no longer supported. For an upgrade, switch to using the \"ignores\" property in a config object. See https://eslint.org/docs/latest/use/configure/migration-guide#ignoring-files for details.");
assert.strictEqual(processStub.getCall(0).args[1], "ESLintIgnoreWarning");

processStub.restore();
});
});

describe("loadFormatter()", () => {
Expand Down