-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheslint.config.mjs
121 lines (119 loc) · 5.38 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import js from "@eslint/js"
import comments from "@eslint-community/eslint-plugin-eslint-comments/configs"
import gitignore from "eslint-config-flat-gitignore"
import * as depend from "eslint-plugin-depend"
import jsdoc from "eslint-plugin-jsdoc"
import markdown from "eslint-plugin-markdown"
import node from "eslint-plugin-n"
import perfectionist from "eslint-plugin-perfectionist"
import promise from "eslint-plugin-promise"
import * as regexp from "eslint-plugin-regexp"
import security from "eslint-plugin-security"
import sonarjs from "eslint-plugin-sonarjs"
import unicorn from "eslint-plugin-unicorn"
import vitest from "eslint-plugin-vitest"
import ts from "typescript-eslint"
export default [
gitignore(),
{ files: ["**/*.{js,mjs,cjs,ts}"] },
js.configs.recommended,
...ts.configs.strictTypeChecked,
...ts.configs.stylisticTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: import.meta.dirname,
},
},
},
/* eslint-disable sonarjs/no-duplicate-string */
comments.recommended,
depend.configs["flat/recommended"],
jsdoc.configs["flat/logical-typescript"],
jsdoc.configs["flat/stylistic-typescript"],
jsdoc.configs["flat/contents-typescript"],
...markdown.configs.recommended,
node.configs["flat/recommended-module"],
perfectionist.configs["recommended-natural"],
promise.configs["flat/recommended"],
regexp.configs["flat/recommended"],
security.configs.recommended,
sonarjs.configs.recommended,
unicorn.configs["flat/recommended"],
vitest.configs.recommended,
/* eslint-enable */
{
plugins: {
node,
},
rules: {
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/method-signature-style": "error", // cf. https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
"@typescript-eslint/naming-convention": [
"error",
{
format: ["PascalCase"],
prefix: ["is", "should", "has", "can", "did", "will"],
selector: "variable",
types: ["boolean"],
},
],
"@typescript-eslint/no-magic-numbers": [
"error",
{
ignore: [-1, 0, 1, 2], // cf. https://en.wikipedia.org/wiki/Magic_number_(programming)#Accepted_uses
},
],
"@typescript-eslint/promise-function-async": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#14-typescript-eslint-promise-function-async
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"arrow-body-style": "error",
eqeqeq: "error",
"guard-for-in": "error", // cf. https://www.executeprogram.com/courses/modern-javascript/lessons/for-of-loops
"max-nested-callbacks": ["error", 2], // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#5-max-nested-callbacks
"n/no-missing-import": [
"error",
{
tryExtensions: [".js", ".json", ".node", ".ts"],
},
],
"no-await-in-loop": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#2-no-await-in-loop
"no-promise-executor-return": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#3-no-promise-executor-return
"no-restricted-syntax": [
"error",
{
// cf. https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums
// cf. https://www.typescriptlang.org/docs/handbook/enums.html#const-enum-pitfalls
message: "Use const assertion or a string union type instead.",
selector: "TSEnumDeclaration",
},
{
// cf. https://effectivetypescript.com/2020/03/09/evolving-any
// cf. https://stackoverflow.com/questions/77150939/triggering-typescript-error-for-untyped-arrays/77804988#77804988
message: "Don't use evolving any arrays.",
selector:
"VariableDeclarator:matches([id.typeAnnotation=undefined]):matches([init.type=ArrayExpression]):matches([init.elements.length=0])",
},
],
"node/handle-callback-err": ["error", "^.*(e|E)rr"], // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#8-node-handle-callback-err
"node/no-callback-literal": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#9-node-no-callback-literal
"node/no-sync": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#10-node-no-sync
"prefer-arrow-callback": "error",
"prefer-promise-reject-errors": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#7-prefer-promise-reject-errors
"require-atomic-updates": "error", // cf. https://maximorlov.com/linting-rules-for-asynchronous-code-in-javascript/#4-require-atomic-updates
"vitest/prefer-strict-equal": "error",
// Custom
/* eslint-disable perfectionist/sort-objects */
"@typescript-eslint/ban-ts-comment": "off",
"security/detect-non-literal-fs-filename": "off",
"security/detect-object-injection": "off",
/* eslint-enable perfectionist/sort-objects */
},
},
{
files: ["**/*.{js,mjs,cjs}", "vitest.config.ts"],
...ts.configs.disableTypeChecked,
},
]