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!: Switch Linter to flat config by default #17851
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -426,7 +426,7 @@ class RuleTester { | |
* @type {Object} | ||
*/ | ||
this.rules = {}; | ||
this.linter = new Linter(); | ||
this.linter = new Linter({ configType: "eslintrc" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Temporary measure until we remove |
||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ describe("Linter", () => { | |
let linter; | ||
|
||
beforeEach(() => { | ||
linter = new Linter(); | ||
linter = new Linter({ configType: "eslintrc" }); | ||
}); | ||
|
||
afterEach(() => { | ||
|
@@ -3419,7 +3419,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", { | ||
|
@@ -3438,7 +3438,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) { | ||
|
@@ -6483,8 +6483,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", () => { | ||
|
@@ -14638,32 +14638,6 @@ var a = "test2"; | |
}); | ||
}); | ||
|
||
describe("Mutability", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why these are still here. There's no way to test this using flat config. |
||
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 = []; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,30 +58,19 @@ describe("rules", () => { | |
|
||
const linter = new Linter(); | ||
|
||
const problems = linter.verify("foo", { rules: { "test-rule": "error" } }); | ||
|
||
assert.lengthOf(problems, 1); | ||
assert.strictEqual(problems[0].message, "Definition for rule 'test-rule' was not found."); | ||
assert.strictEqual(problems[0].line, 1); | ||
assert.strictEqual(problems[0].column, 1); | ||
assert.strictEqual(problems[0].endLine, 1); | ||
assert.strictEqual(problems[0].endColumn, 2); | ||
assert.throws(() => { | ||
linter.verify("foo", { rules: { "test-rule": "error" } }); | ||
}, TypeError, "Could not find \"test-rule\" in plugin \"@\"."); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is a test file for the |
||
}); | ||
|
||
|
||
it("should report a linting error that lists replacements if a rule is known to have been replaced", () => { | ||
const linter = new Linter(); | ||
const problems = linter.verify("foo", { rules: { "no-arrow-condition": "error" } }); | ||
|
||
assert.lengthOf(problems, 1); | ||
assert.strictEqual( | ||
problems[0].message, | ||
"Rule 'no-arrow-condition' was removed and replaced by: no-confusing-arrow, no-constant-condition" | ||
); | ||
assert.strictEqual(problems[0].line, 1); | ||
assert.strictEqual(problems[0].column, 1); | ||
assert.strictEqual(problems[0].endLine, 1); | ||
assert.strictEqual(problems[0].endColumn, 2); | ||
|
||
assert.throws(() => { | ||
linter.verify("foo", { rules: { "no-arrow-condition": "error" } }); | ||
}, TypeError, "Key \"rules\": Key \"no-arrow-condition\": Rule \"no-arrow-condition\" was removed and replaced by \"no-confusing-arrow,no-constant-condition\"."); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we remove eslintrc mode, we'll need to revisit how the fuzzer works. |
||
const coreRules = linter.getRules(); | ||
const fixableRuleNames = Array.from(coreRules) | ||
.filter(rulePair => rulePair[1].meta && rulePair[1].meta.fixable) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
config
argument is not passed toverify
/verifyAndFix
, Linter still runs eslintrc code paths, which is probably not what we want if"flat"
is the new default.An observable difference:
The cause is the condition it uses to switch between modes:
eslint/lib/linter/linter.js
Lines 1371 to 1372 in a9a17b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm, in that case adding a default value to the constructor won't fix the problem, because we are still checking for
config
. Probably need to revisit all of that logic.