Skip to content

Commit

Permalink
Update CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Dec 20, 2023
1 parent df69890 commit 208d2bc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
8 changes: 6 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ const cli = {
* Executes the CLI based on an array of arguments that is passed in.
* @param {string|Array|Object} args The arguments to process.
* @param {string} [text] The text to lint (used for TTY).
* @param {boolean} [allowFlatConfig] Whether or not to allow flat config.
* @param {boolean} [allowFlatConfig=true] Whether or not to allow flat config.
* @returns {Promise<number>} The exit code for the operation.
*/
async execute(args, text, allowFlatConfig) {
async execute(args, text, allowFlatConfig = true) {
if (Array.isArray(args)) {
debug("CLI args: %o", args.slice(2));
}
Expand All @@ -323,6 +323,10 @@ const cli = {

debug("Using flat config?", usingFlatConfig);

if (!usingFlatConfig) {
process.emitWarning("You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details.", "ESLintRCWarning");
}

const CLIOptions = createCLIOptions(usingFlatConfig);

/** @type {ParsedCLIOptions} */
Expand Down
45 changes: 34 additions & 11 deletions tests/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,7 @@ describe("cli", () => {

describe("when given a config file", () => {
it("should load the specified config file", async () => {
const configPath = getFixturePath(".eslintrc");
const configPath = getFixturePath("eslint.config.js");
const filePath = getFixturePath("passing.js");

await cli.execute(`--config ${configPath} ${filePath}`);
Expand All @@ -1498,7 +1498,7 @@ describe("cli", () => {
const filePath = getFixturePath("globals-browser.js");
const code = `--config ${configPath} ${filePath}`;

const exit = await cli.execute(code);
const exit = await cli.execute(code, null, false);

assert.strictEqual(exit, 0);
});
Expand All @@ -1510,7 +1510,7 @@ describe("cli", () => {
const filePath = getFixturePath("globals-node.js");
const code = `--config ${configPath} ${filePath}`;

const exit = await cli.execute(code);
const exit = await cli.execute(code, null, false);

assert.strictEqual(exit, 0);
});
Expand All @@ -1522,7 +1522,7 @@ describe("cli", () => {
const filePath = getFixturePath("globals-nashorn.js");
const code = `--config ${configPath} ${filePath}`;

const exit = await cli.execute(code);
const exit = await cli.execute(code, null, false);

assert.strictEqual(exit, 0);
});
Expand All @@ -1534,7 +1534,7 @@ describe("cli", () => {
const filePath = getFixturePath("globals-webextensions.js");
const code = `--config ${configPath} ${filePath}`;

const exit = await cli.execute(code);
const exit = await cli.execute(code, null, false);

assert.strictEqual(exit, 0);
});
Expand All @@ -1549,7 +1549,7 @@ describe("cli", () => {
const code = `--rulesdir ${rulesPath} --config ${configPath} --no-ignore ${filePath}`;

await stdAssert.rejects(async () => {
const exit = await cli.execute(code);
const exit = await cli.execute(code, null, false);

assert.strictEqual(exit, 2);
}, /Error while loading rule 'custom-rule': Boom!/u);
Expand All @@ -1561,7 +1561,7 @@ describe("cli", () => {
const filePath = getFixturePath("rules", "test", "test-custom-rule.js");
const code = `--rulesdir ${rulesPath} --config ${configPath} --no-ignore ${filePath}`;

await cli.execute(code);
await cli.execute(code, null, false);

assert.isTrue(log.info.calledOnce);
assert.isTrue(log.info.neverCalledWith(""));
Expand All @@ -1573,7 +1573,7 @@ describe("cli", () => {
const configPath = getFixturePath("rules", "multi-rulesdirs.json");
const filePath = getFixturePath("rules", "test-multi-rulesdirs.js");
const code = `--rulesdir ${rulesPath} --rulesdir ${rulesPath2} --config ${configPath} --no-ignore ${filePath}`;
const exit = await cli.execute(code);
const exit = await cli.execute(code, null, false);

const call = log.info.getCall(0);

Expand All @@ -1591,17 +1591,40 @@ describe("cli", () => {
describe("when executing with no-eslintrc flag", () => {
it("should ignore a local config file", async () => {
const filePath = getFixturePath("eslintrc", "quotes.js");
const exit = await cli.execute(`--no-eslintrc --no-ignore ${filePath}`);
const exit = await cli.execute(`--no-eslintrc --no-ignore ${filePath}`, null, false);

assert.isTrue(log.info.notCalled);
assert.strictEqual(exit, 0);
});
});

describe("when using an eslintrc config file", () => {

let processStub;

beforeEach(() => {
processStub = sinon.stub(process, "emitWarning");
});

afterEach(() => {
processStub.restore();
});

it("should emit deprecation warning", async () => {
const configPath = getFixturePath(".eslintrc");
const filePath = getFixturePath("passing.js");

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

assert.strictEqual(processStub.callCount, 1, "calls `process.emitWarning()` once");
assert.strictEqual(processStub.getCall(0).args[1], "ESLintRCWarning");
});
});

describe("when executing without no-eslintrc flag", () => {
it("should load a local config file", async () => {
const filePath = getFixturePath("eslintrc", "quotes.js");
const exit = await cli.execute(`--no-ignore ${filePath}`);
const exit = await cli.execute(`--no-ignore ${filePath}`, null, false);

assert.isTrue(log.info.calledOnce);
assert.strictEqual(exit, 1);
Expand All @@ -1615,7 +1638,7 @@ describe("cli", () => {
getFixturePath("globals-node.js")
];

await cli.execute(`--no-eslintrc --config ./packages/js/src/configs/eslint-recommended.js --no-ignore ${files.join(" ")}`);
await cli.execute(`--no-eslintrc --config ./packages/js/src/configs/eslint-recommended.js --no-ignore ${files.join(" ")}`, null, false);

assert.strictEqual(log.info.args[0][0].split("\n").length, 10);
});
Expand Down

0 comments on commit 208d2bc

Please sign in to comment.