Skip to content
Permalink
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 <milos.djermanovic@gmail.com>

* chore: update tests

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
aladdin-add and mdjermanovic committed Jun 12, 2021
1 parent 831f6b3 commit 757c49584a5852c468c1b4a0b74ad3aa39d954e5
@@ -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.join(", ")}`);
}

if (filePath !== void 0 && !isNonEmptyString(filePath)) {
throw new Error("'options.filePath' must be a non-empty string or undefined");
}
@@ -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") {
@@ -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);
}
@@ -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)
)
);

@@ -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) {
@@ -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);

/*
@@ -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);
}
}
@@ -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"
@@ -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"
@@ -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"
@@ -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"
@@ -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 () => {

0 comments on commit 757c495

Please sign in to comment.