Skip to content

Commit 757c495

Browse files
Chore: add some rules to eslint-config-eslint (#14692)
* Chore: add some rules to eslint-config-eslint note: this is a breaking for eslint-config-eslint * chore: fix some linting problems * Update lib/eslint/eslint.js Co-authored-by: Milos Djermanovic <[email protected]> * chore: update tests Co-authored-by: Milos Djermanovic <[email protected]>
1 parent 831f6b3 commit 757c495

7 files changed

Lines changed: 27 additions & 16 deletions

File tree

lib/eslint/eslint.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,9 +552,12 @@ class ESLint {
552552
...unknownOptions
553553
} = options || {};
554554

555-
for (const key of Object.keys(unknownOptions)) {
556-
throw new Error(`'options' must not include the unknown option '${key}'`);
555+
const unknownOptionKeys = Object.keys(unknownOptions);
556+
557+
if (unknownOptionKeys.length > 0) {
558+
throw new Error(`'options' must not include the unknown option(s): ${unknownOptionKeys.join(", ")}`);
557559
}
560+
558561
if (filePath !== void 0 && !isNonEmptyString(filePath)) {
559562
throw new Error("'options.filePath' must be a non-empty string or undefined");
560563
}

lib/init/npm-utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ function findPackageJson(startDir) {
5050
*/
5151
function installSyncSaveDev(packages) {
5252
const packageList = Array.isArray(packages) ? packages : [packages];
53-
const npmProcess = spawn.sync("npm", ["i", "--save-dev"].concat(packageList),
54-
{ stdio: "inherit" });
53+
const npmProcess = spawn.sync("npm", ["i", "--save-dev"].concat(packageList), { stdio: "inherit" });
5554
const error = npmProcess.error;
5655

5756
if (error && error.code === "ENOENT") {

lib/rule-tester/rule-tester.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ class RuleTester {
610610
const messages = result.messages;
611611

612612
assert.strictEqual(messages.length, 0, util.format("Should have no errors but had %d: %s",
613-
messages.length, util.inspect(messages)));
613+
messages.length,
614+
util.inspect(messages)));
614615

615616
assertASTDidntChange(result.beforeAST, result.afterAST);
616617
}
@@ -665,13 +666,18 @@ class RuleTester {
665666
}
666667

667668
assert.strictEqual(messages.length, item.errors, util.format("Should have %d error%s but had %d: %s",
668-
item.errors, item.errors === 1 ? "" : "s", messages.length, util.inspect(messages)));
669+
item.errors,
670+
item.errors === 1 ? "" : "s",
671+
messages.length,
672+
util.inspect(messages)));
669673
} else {
670674
assert.strictEqual(
671-
messages.length, item.errors.length,
672-
util.format(
675+
messages.length, item.errors.length, util.format(
673676
"Should have %d error%s but had %d: %s",
674-
item.errors.length, item.errors.length === 1 ? "" : "s", messages.length, util.inspect(messages)
677+
item.errors.length,
678+
item.errors.length === 1 ? "" : "s",
679+
messages.length,
680+
util.inspect(messages)
675681
)
676682
);
677683

lib/rules/comma-style.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ module.exports = {
207207
* they are always valid regardless of an undefined item.
208208
*/
209209
if (astUtils.isCommaToken(commaToken)) {
210-
validateCommaItemSpacing(previousItemToken, commaToken,
211-
currentItemToken, reportItem);
210+
validateCommaItemSpacing(previousItemToken, commaToken, currentItemToken, reportItem);
212211
}
213212

214213
if (item) {

lib/rules/indent.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,8 +1177,7 @@ module.exports = {
11771177
offsets.setDesiredOffset(questionMarkToken, firstToken, 1);
11781178
offsets.setDesiredOffset(colonToken, firstToken, 1);
11791179

1180-
offsets.setDesiredOffset(firstConsequentToken, firstToken,
1181-
firstConsequentToken.type === "Punctuator" &&
1180+
offsets.setDesiredOffset(firstConsequentToken, firstToken, firstConsequentToken.type === "Punctuator" &&
11821181
options.offsetTernaryExpressions ? 2 : 1);
11831182

11841183
/*
@@ -1204,8 +1203,7 @@ module.exports = {
12041203
* If `baz` were aligned with `bar` rather than being offset by 1 from `foo`, `baz` would end up
12051204
* having no expected indentation.
12061205
*/
1207-
offsets.setDesiredOffset(firstAlternateToken, firstToken,
1208-
firstAlternateToken.type === "Punctuator" &&
1206+
offsets.setDesiredOffset(firstAlternateToken, firstToken, firstAlternateToken.type === "Punctuator" &&
12091207
options.offsetTernaryExpressions ? 2 : 1);
12101208
}
12111209
}

packages/eslint-config-eslint/default.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,18 @@ rules:
2929
consistent-return: "error"
3030
curly: ["error", "all"]
3131
default-case: "error"
32+
default-case-last: "error"
3233
default-param-last: "error"
3334
dot-location: ["error", "property"]
3435
dot-notation: ["error", { allowKeywords: true }]
3536
eol-last: "error"
3637
eqeqeq: "error"
3738
func-call-spacing: "error"
3839
func-style: ["error", "declaration"]
40+
function-call-argument-newline: ["error", "consistent"]
3941
function-paren-newline: ["error", "consistent"]
4042
generator-star-spacing: "error"
43+
grouped-accessor-pairs: "error"
4144
guard-for-in: "error"
4245
jsdoc/check-alignment: "error"
4346
jsdoc/check-param-names: "error"
@@ -79,6 +82,7 @@ rules:
7982
no-caller: "error"
8083
no-confusing-arrow: "error"
8184
no-console: "error"
85+
no-constructor-return: "error"
8286
no-delete-var: "error"
8387
no-else-return: ["error", { allowElseIf: false }]
8488
no-eval: "error"
@@ -133,6 +137,7 @@ rules:
133137
no-underscore-dangle: ["error", {allowAfterThis: true}]
134138
no-unmodified-loop-condition: "error"
135139
no-unneeded-ternary: "error"
140+
no-unreachable-loop: "error"
136141
no-unused-expressions: "error"
137142
no-unused-vars: ["error", {vars: "all", args: "after-used", caughtErrors: "all"}]
138143
no-use-before-define: "error"
@@ -174,6 +179,7 @@ rules:
174179
]
175180
prefer-arrow-callback: "error"
176181
prefer-const: "error"
182+
prefer-exponentiation-operator: "error"
177183
prefer-numeric-literals: "error"
178184
prefer-promise-reject-errors: "error"
179185
prefer-regex-literals: "error"

tests/lib/eslint/eslint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ describe("ESLint", () => {
846846

847847
it("should throw if 'options' argument contains unknown key", async () => {
848848
eslint = new ESLint();
849-
await assert.rejects(() => eslint.lintText("var a = 0", { filename: "foo.js" }), /'options' must not include the unknown option 'filename'/u);
849+
await assert.rejects(() => eslint.lintText("var a = 0", { filename: "foo.js" }), /'options' must not include the unknown option\(s\): filename/u);
850850
});
851851

852852
it("should throw if non-string value is given to 'options.filePath' option", async () => {

0 commit comments

Comments
 (0)