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

Chore: add some rules to eslint-config-eslint #14692

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/eslint/eslint.js
Expand Up @@ -552,9 +552,12 @@ class ESLint {
...unknownOptions
} = options || {};

for (const key of Object.keys(unknownOptions)) {
throw new Error(`'options' must not include the unknown option '${key}'`);
const unknownOptionKeys = Object.keys(unknownOptions);

if (unknownOptionKeys.length > 0) {
throw new Error(`'options' must not include the unknown option(s) '${unknownOptionKeys}'`);
aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
}

if (filePath !== void 0 && !isNonEmptyString(filePath)) {
throw new Error("'options.filePath' must be a non-empty string or undefined");
}
Expand Down
3 changes: 1 addition & 2 deletions lib/init/npm-utils.js
Expand Up @@ -50,8 +50,7 @@ function findPackageJson(startDir) {
*/
function installSyncSaveDev(packages) {
const packageList = Array.isArray(packages) ? packages : [packages];
const npmProcess = spawn.sync("npm", ["i", "--save-dev"].concat(packageList),
{ stdio: "inherit" });
const npmProcess = spawn.sync("npm", ["i", "--save-dev"].concat(packageList), { stdio: "inherit" });
const error = npmProcess.error;

if (error && error.code === "ENOENT") {
Expand Down
16 changes: 11 additions & 5 deletions lib/rule-tester/rule-tester.js
Expand Up @@ -610,7 +610,8 @@ class RuleTester {
const messages = result.messages;

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

assertASTDidntChange(result.beforeAST, result.afterAST);
}
Expand Down Expand Up @@ -665,13 +666,18 @@ class RuleTester {
}

assert.strictEqual(messages.length, item.errors, util.format("Should have %d error%s but had %d: %s",
item.errors, item.errors === 1 ? "" : "s", messages.length, util.inspect(messages)));
item.errors,
item.errors === 1 ? "" : "s",
messages.length,
util.inspect(messages)));
} else {
assert.strictEqual(
messages.length, item.errors.length,
util.format(
messages.length, item.errors.length, util.format(
"Should have %d error%s but had %d: %s",
item.errors.length, item.errors.length === 1 ? "" : "s", messages.length, util.inspect(messages)
item.errors.length,
item.errors.length === 1 ? "" : "s",
messages.length,
util.inspect(messages)
)
);

Expand Down
3 changes: 1 addition & 2 deletions lib/rules/comma-style.js
Expand Up @@ -207,8 +207,7 @@ module.exports = {
* they are always valid regardless of an undefined item.
*/
if (astUtils.isCommaToken(commaToken)) {
validateCommaItemSpacing(previousItemToken, commaToken,
currentItemToken, reportItem);
validateCommaItemSpacing(previousItemToken, commaToken, currentItemToken, reportItem);
}

if (item) {
Expand Down
6 changes: 2 additions & 4 deletions lib/rules/indent.js
Expand Up @@ -1177,8 +1177,7 @@ module.exports = {
offsets.setDesiredOffset(questionMarkToken, firstToken, 1);
offsets.setDesiredOffset(colonToken, firstToken, 1);

offsets.setDesiredOffset(firstConsequentToken, firstToken,
firstConsequentToken.type === "Punctuator" &&
offsets.setDesiredOffset(firstConsequentToken, firstToken, firstConsequentToken.type === "Punctuator" &&
options.offsetTernaryExpressions ? 2 : 1);

/*
Expand All @@ -1204,8 +1203,7 @@ module.exports = {
* If `baz` were aligned with `bar` rather than being offset by 1 from `foo`, `baz` would end up
* having no expected indentation.
*/
offsets.setDesiredOffset(firstAlternateToken, firstToken,
firstAlternateToken.type === "Punctuator" &&
offsets.setDesiredOffset(firstAlternateToken, firstToken, firstAlternateToken.type === "Punctuator" &&
options.offsetTernaryExpressions ? 2 : 1);
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-config-eslint/default.yml
Expand Up @@ -29,15 +29,18 @@ rules:
consistent-return: "error"
curly: ["error", "all"]
default-case: "error"
default-case-last: "error"
default-param-last: "error"
dot-location: ["error", "property"]
dot-notation: ["error", { allowKeywords: true }]
eol-last: "error"
eqeqeq: "error"
func-call-spacing: "error"
func-style: ["error", "declaration"]
function-call-argument-newline: ["error", "consistent"]
function-paren-newline: ["error", "consistent"]
generator-star-spacing: "error"
grouped-accessor-pairs: "error"
guard-for-in: "error"
jsdoc/check-alignment: "error"
jsdoc/check-param-names: "error"
Expand Down Expand Up @@ -79,6 +82,7 @@ rules:
no-caller: "error"
no-confusing-arrow: "error"
no-console: "error"
no-constructor-return: "error"
no-delete-var: "error"
no-else-return: ["error", { allowElseIf: false }]
no-eval: "error"
Expand Down Expand Up @@ -133,6 +137,7 @@ rules:
no-underscore-dangle: ["error", {allowAfterThis: true}]
no-unmodified-loop-condition: "error"
no-unneeded-ternary: "error"
no-unreachable-loop: "error"
no-unused-expressions: "error"
no-unused-vars: ["error", {vars: "all", args: "after-used", caughtErrors: "all"}]
no-use-before-define: "error"
Expand Down Expand Up @@ -174,6 +179,7 @@ rules:
]
prefer-arrow-callback: "error"
prefer-const: "error"
prefer-exponentiation-operator: "error"
prefer-numeric-literals: "error"
prefer-promise-reject-errors: "error"
prefer-regex-literals: "error"
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/eslint/eslint.js
Expand Up @@ -846,7 +846,7 @@ describe("ESLint", () => {

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

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