Skip to content

Commit

Permalink
feat!: Switch Linter to flat config by default
Browse files Browse the repository at this point in the history
Refs #13481
  • Loading branch information
nzakas committed Dec 13, 2023
1 parent 7d5e5f6 commit 78ba2f5
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/cli-engine/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ class CLIEngine {
});
const lintResultCache =
options.cache ? new LintResultCache(cacheFilePath, options.cacheStrategy) : null;
const linter = new Linter({ cwd: options.cwd });
const linter = new Linter({ cwd: options.cwd, configType: "eslintrc" });

/** @type {ConfigArray[]} */
const lastConfigArrays = [configArrayFactory.getConfigArrayForFile()];
Expand Down
4 changes: 2 additions & 2 deletions lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,9 @@ class Linter {
* Initialize the Linter.
* @param {Object} [config] the config object
* @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
* @param {"flat"|"eslintrc"} [config.configType="eslintrc"] the type of config used.
* @param {"flat"|"eslintrc"} [config.configType="flat"] the type of config used.
*/
constructor({ cwd, configType } = {}) {
constructor({ cwd, configType = "flat" } = {}) {
internalSlotsMap.set(this, {
cwd: normalizeCwd(cwd),
lastConfigArray: null,
Expand Down
2 changes: 1 addition & 1 deletion lib/rule-tester/rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ class RuleTester {
* @type {Object}
*/
this.rules = {};
this.linter = new Linter();
this.linter = new Linter({ configType: "eslintrc" });
}

/**
Expand Down
36 changes: 5 additions & 31 deletions tests/lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe("Linter", () => {
let linter;

beforeEach(() => {
linter = new Linter();
linter = new Linter({ configType: "eslintrc" });
});

afterEach(() => {
Expand Down Expand Up @@ -4133,7 +4133,7 @@ var a = "test2";

it("should get cwd correctly in the context", () => {
const cwd = "cwd";
const linterWithOption = new Linter({ cwd });
const linterWithOption = new Linter({ cwd, configType: "eslintrc" });
let spy;

linterWithOption.defineRule("checker", {
Expand All @@ -4152,7 +4152,7 @@ var a = "test2";

it("should assign process.cwd() to it if cwd is undefined", () => {
let spy;
const linterWithOption = new Linter({ });
const linterWithOption = new Linter({ configType: "eslintrc" });

linterWithOption.defineRule("checker", {
create(context) {
Expand Down Expand Up @@ -7690,8 +7690,8 @@ var a = "test2";
let linter2 = null;

beforeEach(() => {
linter1 = new Linter();
linter2 = new Linter();
linter1 = new Linter({ configType: "eslintrc" });
linter2 = new Linter({ configType: "eslintrc" });
});

describe("rules", () => {
Expand Down Expand Up @@ -17505,32 +17505,6 @@ var a = "test2";
});
});

describe("Mutability", () => {
let linter1 = null;
let linter2 = null;

beforeEach(() => {
linter1 = new Linter();
linter2 = new Linter();
});

describe("rules", () => {
it("with no changes, same rules are loaded", () => {
assert.sameDeepMembers(Array.from(linter1.getRules().keys()), Array.from(linter2.getRules().keys()));
});

it("loading rule in one doesn't change the other", () => {
linter1.defineRule("mock-rule", {
create: () => ({})
});

assert.isTrue(linter1.getRules().has("mock-rule"), "mock rule is present");
assert.isFalse(linter2.getRules().has("mock-rule"), "mock rule is not present");
});
});
});


describe("processors", () => {
let receivedFilenames = [];
let receivedPhysicalFilenames = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/source-code/source-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const DEFAULT_CONFIG = {
range: true,
loc: true
};
const linter = new Linter();
const linter = new Linter({ configType: "eslintrc" });
const flatLinter = new Linter({ configType: "flat" });
const AST = espree.parse("let foo = bar;", DEFAULT_CONFIG),
TEST_CODE = "var answer = 6 * 7;",
Expand Down
2 changes: 1 addition & 1 deletion tests/tools/eslint-fuzzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe("eslint-fuzzer", function() {
*/
this.timeout(15000); // eslint-disable-line no-invalid-this -- Mocha timeout

const linter = new eslint.Linter();
const linter = new eslint.Linter({ configType: "eslintrc" });
const coreRules = linter.getRules();
const fixableRuleNames = Array.from(coreRules)
.filter(rulePair => rulePair[1].meta && rulePair[1].meta.fixable)
Expand Down

0 comments on commit 78ba2f5

Please sign in to comment.