UNPKG

26.3 kBJavaScriptView Raw
1/* eslint sort-keys: ["error", "asc"], quote-props: ["error", "consistent"] */
2/* eslint-disable sort-keys */
3
4const options = require("./options.js");
5const globPatterns = require("./glob-patterns.js");
6
7module.exports = {
8 plugins: ["@typescript-eslint"],
9 overrides: [
10 {
11 files: globPatterns.typescript,
12 parser: "@typescript-eslint/parser",
13 parserOptions: {
14 ecmaFeatures: {
15 jsx: true,
16 },
17 extraFileExtensions: [".vue"],
18 },
19 extends: [
20 "plugin:import/typescript",
21 "plugin:@typescript-eslint/recommended",
22 "plugin:@typescript-eslint/eslint-recommended",
23 "plugin:@typescript-eslint/recommended-requiring-type-checking",
24 ],
25 rules: {
26 /* eslint-enable sort-keys */
27 // "no-undef": "off", // produces false positive with some TypeScript syntax. This is caught by TypeScript anyway.
28 "@typescript-eslint/adjacent-overload-signatures": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/adjacent-overload-signatures.md
29 "@typescript-eslint/array-type": ["warn", {default: "generic"}], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/array-type.md
30 "@typescript-eslint/await-thenable": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/await-thenable.md
31 // Disable the warning for legimitate use cases
32 "@typescript-eslint/ban-ts-ignore": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-ts-ignore.md
33 "@typescript-eslint/ban-types": ["warn", options["@typescript-eslint/ban-types"]], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md
34 "@typescript-eslint/brace-style": [
35 "warn",
36 "1tbs",
37 {
38 "allowSingleLine": false,
39 }
40 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/brace-style.md
41 // Handled by @typescript-eslint/naming-convention
42 "@typescript-eslint/camelcase": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/camelcase.md
43 "@typescript-eslint/class-name-casing": [
44 "warn",
45 {
46 allowUnderscorePrefix: true,
47 },
48 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/class-name-casing.md
49 "@typescript-eslint/comma-spacing": ["warn", options["comma-spacing"]], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/comma-spacing.md
50 "@typescript-eslint/consistent-type-assertions": [
51 "warn",
52 {
53 assertionStyle: "as",
54 // Using {} as Something can hide errors (see rule docs).
55 // It's better to declare a typed variable first.
56 objectLiteralTypeAssertions: "allow-as-parameter",
57 },
58 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-assertions.md
59 "@typescript-eslint/consistent-type-definitions": ["warn", "type"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-definitions.md
60 "@typescript-eslint/default-param-last": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/default-param-last.md
61 "@typescript-eslint/explicit-function-return-type": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-function-return-type.md
62 "@typescript-eslint/explicit-member-accessibility": [
63 "warn",
64 {
65 accessibility: "no-public",
66 overrides: {
67 parameterProperties: "explicit",
68 },
69 },
70 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-member-accessibility.md
71 "@typescript-eslint/explicit-module-boundary-types": ["off", {
72 allowDirectConstAssertionInArrowFunctions: true,
73 allowHigherOrderFunctions: true,
74 allowTypedFunctionExpressions: true,
75 allowedNames: [],
76 }], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/explicit-module-boundary-types.md
77 "@typescript-eslint/func-call-spacing": ["warn"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/func-call-spacing.md
78 "@typescript-eslint/generic-type-naming": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/generic-type-naming.md
79 "@typescript-eslint/indent": ["warn", 4, options["indent"]], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/indent.md
80 // There are good reasons why interfaces should not be prefixed
81 // https://stackoverflow.com/questions/31876947/confused-about-the-interface-and-class-coding-guidelines-for-typescript/41967120#comment75349088_41967120
82 "@typescript-eslint/interface-name-prefix": ["warn", "never"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/interface-name-prefix.md
83 "@typescript-eslint/member-delimiter-style": [
84 "warn",
85 {
86 // We're using "semi" because classes do only allow semi
87 // and we want to stay consistent with them.
88 multiline: {
89 delimiter: "semi",
90 requireLast: true,
91 },
92 singleline: {
93 delimiter: "semi",
94 requireLast: false,
95 },
96 },
97 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-delimiter-style.md
98 "@typescript-eslint/member-naming": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-naming.md
99 "@typescript-eslint/member-ordering": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/member-ordering.md
100 "@typescript-eslint/naming-convention": [
101 "warn",
102 ...options["@typescript-eslint/naming-convention"].defaultRules,
103 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
104 "@typescript-eslint/no-array-constructor": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-array-constructor.md
105 "@typescript-eslint/no-dupe-class-members": ["warn"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dupe-class-members.md
106 "@typescript-eslint/no-dynamic-delete": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-dynamic-delete.md
107 "@typescript-eslint/no-empty-function": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-function.md
108 "@typescript-eslint/no-empty-interface": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-empty-interface.md
109 "@typescript-eslint/no-explicit-any": [
110 "warn",
111 {
112 fixToUnknown: false,
113 ignoreRestArgs: true,
114 },
115 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-explicit-any.md
116 "@typescript-eslint/no-extra-non-null-assertion": ["warn"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-non-null-assertion.md
117 "@typescript-eslint/no-extra-parens": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extra-parens.md
118 "@typescript-eslint/no-extraneous-class": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-extraneous-class.md
119 // This rule might be a good idea, but often it's ok to let the global error handler handle it
120 "@typescript-eslint/no-floating-promises": ["off", {
121 ignoreVoid: true
122 }], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md
123 "@typescript-eslint/no-for-in-array": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-for-in-array.md
124 "@typescript-eslint/no-implied-eval": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-implied-eval.md
125 "@typescript-eslint/no-inferrable-types": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-inferrable-types.md
126 "@typescript-eslint/no-magic-numbers": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-magic-numbers.md
127 "@typescript-eslint/no-misused-new": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-misused-new.md
128 "@typescript-eslint/no-misused-promises": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-misused-promises.md
129 "@typescript-eslint/no-namespace": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-namespace.md
130 "@typescript-eslint/no-non-null-asserted-optional-chain": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-non-null-asserted-optional-chain.md
131 "@typescript-eslint/no-non-null-assertion": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-non-null-assertion.md
132 "@typescript-eslint/no-parameter-properties": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-parameter-properties.md
133 "@typescript-eslint/no-require-imports": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-require-imports.md
134 "@typescript-eslint/no-this-alias": [
135 "warn",
136 {
137 allowDestructuring: true,
138 allowedNames: [],
139 },
140 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-this-alias.md
141 "@typescript-eslint/no-throw-literal": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-throw-literal.md
142 "@typescript-eslint/no-type-alias": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-type-alias.md
143 "@typescript-eslint/no-unnecessary-boolean-literal-compare": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-boolean-literal-compare.md
144 "@typescript-eslint/no-unnecessary-condition": ["warn", {
145 allowConstantLoopConditions: true,
146 checkArrayPredicates: true,
147 ignoreRhs: true,
148 }], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-condition.md
149 "@typescript-eslint/no-unnecessary-qualifier": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-qualifier.md
150 "@typescript-eslint/no-unnecessary-type-arguments": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-arguments.md
151 "@typescript-eslint/no-unnecessary-type-assertion": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unnecessary-type-assertion.md
152 "@typescript-eslint/no-unused-expressions": ["warn", options["no-unused-expressions"]], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-expressions.md
153 "@typescript-eslint/no-unused-vars": ["warn", options["no-unused-vars"]], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-unused-vars.md
154 "@typescript-eslint/no-unused-vars-experimental": "off", // https://github.com/typescript-eslint/typescript-eslint/tree/v2.19.0/packages/eslint-plugin
155 // The following rules would require to sort each function (declaration and expression)
156 // in a module in a specific way which seems to be impractical.
157 "@typescript-eslint/no-use-before-define": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md
158 "@typescript-eslint/no-useless-constructor": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-useless-constructor.md
159 "@typescript-eslint/no-var-requires": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-var-requires.md
160 "@typescript-eslint/prefer-as-const": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-as-const.md
161 "@typescript-eslint/prefer-for-of": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-for-of.md
162 "@typescript-eslint/prefer-function-type": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-function-type.md
163 "@typescript-eslint/prefer-includes": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-includes.md
164 "@typescript-eslint/prefer-interface": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-interface.md
165 "@typescript-eslint/prefer-namespace-keyword": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-namespace-keyword.md
166 // Enabling prefer-readonly would require developers to write
167 // private readonly someMethod = () => {};
168 // which is verbose and kind of annoying.
169 "@typescript-eslint/prefer-nullish-coalescing": ["warn", {
170 ignoreConditionalTests: true,
171 ignoreMixedLogicalExpressions: true,
172 }], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-nullish-coalescing.md
173 "@typescript-eslint/prefer-optional-chain": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-optional-chain.md
174 // We can't activate prefer-readonly currently as we don't want to flag class properties
175 // that are functions as readonly (although it would be correct).
176 // That would just be too verbose.
177 "@typescript-eslint/prefer-readonly": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md
178 // Sometimes it makes more sense to use .match() or maybe the global flag is added later.
179 // In this case we want to prevent the developer from needing to refactor the code.
180 "@typescript-eslint/prefer-regexp-exec": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-regexp-exec.md
181 "@typescript-eslint/prefer-string-starts-ends-with": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/prefer-string-starts-ends-with.md
182 "@typescript-eslint/promise-function-async": [
183 "warn",
184 {
185 allowAny: true,
186 allowedPromiseNames: [],
187 checkArrowFunctions: true,
188 checkFunctionDeclarations: true,
189 checkFunctionExpressions: true,
190 checkMethodDeclarations: true,
191 },
192 ], // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin
193 "@typescript-eslint/quotes": ["warn", "double", options.quotes], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/quotes.md
194 "@typescript-eslint/require-array-sort-compare": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/require-array-sort-compare.md
195 "@typescript-eslint/require-await": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/require-await.md
196 "@typescript-eslint/restrict-plus-operands": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-plus-operands.md
197 "@typescript-eslint/restrict-template-expressions": ["off", {
198 allowBoolean: false,
199 allowNullable: false,
200 allowNumber: true,
201 }], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md
202 "@typescript-eslint/return-await": ["warn", "in-try-catch"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/return-await.md
203 "@typescript-eslint/semi": ["warn"], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/semi.md
204 "@typescript-eslint/space-before-function-paren": ["warn", options["space-before-function-paren"]], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/space-before-function-paren.md
205 "@typescript-eslint/strict-boolean-expressions": [
206 "off",
207 {
208 allowNullable: true,
209 allowSafe: true,
210 ignoreRhs: true,
211 },
212 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/strict-boolean-expressions.md
213 "@typescript-eslint/switch-exhaustiveness-check": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md
214 "@typescript-eslint/triple-slash-reference": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/triple-slash-reference.md
215 "@typescript-eslint/type-annotation-spacing": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/type-annotation-spacing.md
216 "@typescript-eslint/typedef": "off", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/typedef.md
217 "@typescript-eslint/unbound-method": [
218 "warn",
219 {
220 ignoreStatic: true,
221 },
222 ], // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md
223 "@typescript-eslint/unified-signatures": "warn", // https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unified-signatures.md
224 "babel/camelcase": "off",
225 "babel/no-unused-expressions": "off", // covered by @typescript-eslint/no-unused-expressions
226 "babel/quotes": "off", // covered by @typescript-eslint/quotes
227 "babel/semi": "off", // covered by @typescript-eslint/semi
228 "brace-style": "off", // covered by @comma-spacing/brace-style
229 "comma-spacing": "off", // covered by @comma-spacing/comma-spacing
230 "func-call-spacing": "off", // covered by @typescript-eslint/func-call-spacing
231 // There's currently a problem with this rule, see https://github.com/benmosher/eslint-plugin-import/issues/1341
232 "import/export": "off", // TypeScript should catch it anyway
233 "import/extensions": ["warn", "ignorePackages", {
234 "ts": "never",
235 "tsx": "never",
236 }], // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/extensions.md
237 // TypeScript project have usually more imports due to types
238 "import/max-dependencies": ["warn", {max: 45}],
239 "import/named": "off", // TypeScript should catch it anyway
240 "import/namespace": "off", // TypeScript should catch it anyway
241 "import/no-unresolved": "off", // TypeScript should catch it anyway
242 "indent": "off",
243 "jsdoc/no-types": "warn", // JSDoc types are not necessary when using TypeScript
244 "jsdoc/require-param": "off",
245 "jsdoc/require-param-type": "off",
246 "jsdoc/require-returns": "off",
247 "jsdoc/require-returns-type": "off",
248 // TypeScript files tend to get longer due to types
249 "max-lines": [
250 "warn",
251 {
252 ...options["max-lines"],
253 max: 1400,
254 },
255 ],
256 "no-dupe-class-members": "off", // covered by @typescript-eslint/no-dupe-class-members
257 "no-empty-function": "off", // covered by @typescript-eslint/no-empty-function
258 "no-extra-parens": "off",
259 "no-useless-constructor": "off", // covered by @typescript-eslint/no-useless-constructor
260 "semi": "off", // covered by @typescript-eslint/semi
261 "space-before-function-paren": "off", // covered by @typescript-eslint/space-before-function-paren
262 "valid-jsdoc": "off", // when using TypeScript most things enforced by valid-jsdoc don't make sense
263 },
264 },
265 {
266 files: ["*.d.ts"],
267 rules: {
268 // In d.ts files it might be necessary to merge an existing interface
269 "@typescript-eslint/consistent-type-definitions": "off",
270 // When someone wants to extend the typings of a third-party module, it might
271 // be necessary to import the module so that TypeScript finds the typings that should be extended.
272 // This is a better alternative to the triple-slash directive
273 "import/no-unassigned-import": "off",
274 },
275 },
276 {
277 files: globPatterns.tests,
278 rules: {
279 // The any type is ok in tests
280 "@typescript-eslint/no-explicit-any": "off",
281 // Non-null assertions can be handy when testing instances of Map
282 "@typescript-eslint/no-non-null-assertion": "off",
283 // chai uses these as assertions
284 "@typescript-eslint/no-unused-expressions": "off",
285 // Passing functions around like this can be common with mocking
286 "@typescript-eslint/unbound-method": "off",
287 },
288 },
289 ]
290};