Skip to content

Commit ad98388

Browse files
committed
Update ESLint config
1 parent 8eb648f commit ad98388

File tree

5 files changed

+69
-30
lines changed

5 files changed

+69
-30
lines changed

.eslintrc.js

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,70 @@
11
"use strict";
22

3-
const baseRules = require("eslint-config-lydell");
3+
const error = "error";
4+
const warn = process.argv.includes("--report-unused-disable-directives")
5+
? "error"
6+
: "warn";
47

58
module.exports = {
69
root: true,
7-
plugins: ["import", "jest"],
10+
extends: ["eslint:recommended"],
11+
plugins: ["jest"],
12+
parserOptions: {
13+
ecmaVersion: 2018,
14+
},
815
env: { es6: true, node: true },
9-
rules: Object.assign({}, baseRules({ import: true }), {
10-
"import/order": ["error", { "newlines-between": "always" }],
11-
"no-console": "error",
12-
"prefer-template": "off",
13-
}),
16+
rules: {
17+
"arrow-body-style": warn,
18+
"dot-notation": warn,
19+
"no-caller": error,
20+
"no-console": warn,
21+
"no-eval": error,
22+
"no-labels": error,
23+
"no-octal-escape": error,
24+
"no-param-reassign": error,
25+
"no-promise-executor-return": error,
26+
"no-restricted-syntax": [
27+
error,
28+
{
29+
selector: "SequenceExpression",
30+
message:
31+
"The comma operator is confusing and a common mistake. Don’t use it!",
32+
},
33+
],
34+
"no-self-compare": error,
35+
"no-shadow": "error",
36+
"no-template-curly-in-string": error,
37+
"no-unmodified-loop-condition": error,
38+
"no-unneeded-ternary": warn,
39+
"no-useless-backreference": error,
40+
"no-useless-computed-key": warn,
41+
"no-useless-concat": warn,
42+
"no-useless-constructor": warn,
43+
"no-useless-rename": warn,
44+
"no-var": warn,
45+
"object-shorthand": warn,
46+
"one-var": [warn, "never"],
47+
"prefer-arrow-callback": warn,
48+
"prefer-const": warn,
49+
"prefer-destructuring": [warn, { object: true, array: false }],
50+
"prefer-exponentiation-operator": warn,
51+
"prefer-numeric-literals": warn,
52+
"prefer-object-spread": warn,
53+
"prefer-promise-reject-errors": error,
54+
"prefer-regex-literals": warn,
55+
"prefer-rest-params": warn,
56+
"prefer-spread": warn,
57+
"prefer-template": warn,
58+
curly: warn,
59+
eqeqeq: [error, "always", { null: "ignore" }],
60+
strict: error,
61+
yoda: warn,
62+
},
1463
overrides: [
1564
{
1665
files: ["*.test.js"],
17-
env: { jest: true },
18-
rules: baseRules({ builtin: false, jest: true }),
66+
extends: ["plugin:jest/recommended"],
67+
env: { "jest/globals": true },
1968
},
2069
],
2170
};

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
"prettier": "prettier --write .",
77
"eslint": "eslint . --fix",
88
"eslint:examples": "eslint --rulesdir src --no-ignore --fix-dry-run --format json --report-unused-disable-directives examples --ext .js,.ts,.vue,.md",
9-
"test": "prettier --check . && eslint . && node build.js && jest --coverage"
9+
"test": "prettier --check . && eslint . --report-unused-disable-directives && node build.js && jest --coverage"
1010
},
1111
"devDependencies": {
1212
"@typescript-eslint/parser": "4.6.1",
1313
"babel-eslint": "10.1.0",
1414
"cross-spawn": "7.0.3",
1515
"doctoc": "1.4.0",
1616
"eslint": "7.13.0",
17-
"eslint-config-lydell": "14.0.0",
1817
"eslint-plugin-import": "2.22.1",
1918
"eslint-plugin-jest": "24.1.0",
2019
"eslint-plugin-markdown": "1.0.2",

src/sort.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,14 @@ function handleLastSemicolon(imports, sourceCode) {
287287
}
288288

289289
// Preserve the start position, but use the end position of the `from` string.
290-
const newLastImport = Object.assign({}, lastImport, {
290+
const newLastImport = {
291+
...lastImport,
291292
range: [lastImport.range[0], nextToLastToken.range[1]],
292293
loc: {
293294
start: lastImport.loc.start,
294295
end: nextToLastToken.loc.end,
295296
},
296-
});
297+
};
297298

298299
return imports.slice(0, lastIndex).concat(newLastImport);
299300
}
@@ -323,9 +324,10 @@ function printSortedSpecifiers(importNode, sourceCode) {
323324
const specifierTokens = allTokens.slice(openBraceIndex + 1, closeBraceIndex);
324325
const itemsResult = getSpecifierItems(specifierTokens, sourceCode);
325326

326-
const items = itemsResult.items.map((originalItem, index) =>
327-
Object.assign({}, originalItem, { node: specifiers[index] })
328-
);
327+
const items = itemsResult.items.map((originalItem, index) => ({
328+
...originalItem,
329+
node: specifiers[index],
330+
}));
329331

330332
const sortedItems = sortSpecifierItems(items);
331333

@@ -679,9 +681,7 @@ function getAllTokens(node, sourceCode) {
679681
const tokens = sourceCode.getTokens(node);
680682
const lastTokenIndex = tokens.length - 1;
681683
return flatMap(tokens, (token, tokenIndex) => {
682-
const newToken = Object.assign({}, token, {
683-
code: sourceCode.getText(token),
684-
});
684+
const newToken = { ...token, code: sourceCode.getText(token) };
685685

686686
if (tokenIndex === lastTokenIndex) {
687687
return [newToken];
@@ -700,7 +700,7 @@ function getAllTokens(node, sourceCode) {
700700
...parseWhitespace(
701701
sourceCode.text.slice(previous.range[1], comment.range[0])
702702
),
703-
Object.assign({}, comment, { code: sourceCode.getText(comment) }),
703+
{ ...comment, code: sourceCode.getText(comment) },
704704
];
705705
}),
706706
...parseWhitespace(

test/examples.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe("examples", () => {
2323
for (const item of output) {
2424
const name = path.basename(item.filePath);
2525
if (!name.startsWith(".")) {
26-
test(name, () => {
26+
test(`${name}`, () => {
2727
expect(item).toMatchObject({
2828
messages: [],
2929
errorCount: 0,

0 commit comments

Comments
 (0)