UNPKG

9.81 kBJavaScriptView Raw
1/*
2
3gregjoeval ESLint config
4
5ESLint Rule Documentation: https://eslint.org/docs/rules/
6AirBnB Javascript Style Guide: https://github.com/airbnb/javascript
7Tool for comparing configs: https://sqren.github.io/eslint-compare/
8Typescript ESLint: https://github.com/typescript-eslint/typescript-eslint
9
10off: don't care or overriding rule config from plugin
11warn: dont do this; writing code this way is not accepted but shouldn't prevent you from writing code during development
12error: dont do this; writing code this way is not accepted; if you must break the rule you should use @ts-expect-error and provide a reason
13
14*/
15
16module.exports = {
17 "parser": "@typescript-eslint/parser",
18 "plugins": [
19 "@typescript-eslint",
20 "promise",
21 "import-helpers"
22 ],
23 // extended configs should be ordered by least to greatest importance
24 "extends": [
25 "plugin:import/typescript",
26 "plugin:@typescript-eslint/eslint-recommended",
27 "plugin:@typescript-eslint/recommended",
28 "plugin:@typescript-eslint/recommended-requiring-type-checking",
29 "airbnb-base"
30 ],
31 // https://stackoverflow.com/a/58323590/7571132
32 "settings": {
33 "import/resolver": {
34 "node": {
35 "extensions": [
36 ".ts",
37 ".tsx",
38 ".js",
39 ".jsx"
40 ]
41 }
42 }
43 },
44 "rules": {
45 // Rules that cause issues between eslint and @typescript-eslint (https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules)
46 "brace-style": "off",
47 "comma-dangle": "off",
48 "comma-spacing": "off",
49 "default-param-last": "off",
50 "dot-notation": "off",
51 "func-call-spacing": "off",
52 "indent": "off", // https://github.com/typescript-eslint/typescript-eslint/issues/1824
53 "init-declarations": "off",
54 "keyword-spacing": "off",
55 "lines-between-class-members": "off",
56 "no-array-constructor": "off",
57 "no-dupe-class-members": "off",
58 "no-duplicate-imports": "off",
59 "no-empty-function": "off",
60 "no-extra-parens": "off",
61 "no-extra-semi": "off",
62 "no-invalid-this": "off",
63 "no-loop-func": "off",
64 "no-loss-of-precision": "off",
65 "no-magic-numbers": "off",
66 "no-redeclare": "off",
67 "no-shadow": "off",
68 "no-throw-literal": "off",
69 "no-unused-expressions": "off",
70 "no-unused-vars": "off",
71 "no-use-before-define": "off", // https://github.com/typescript-eslint/typescript-eslint/issues/1856
72 "no-useless-constructor": "off",
73 "object-curly-spacing": "off",
74 "quotes": "off",
75 "require-await": "off",
76 "no-return-await": "off", // return-await
77 "semi": "off",
78 "space-before-function-paren": "off",
79 "space-infix-ops": "off",
80
81 // ESLint (https://eslint.org/docs/rules/)
82 "spaced-comment": "warn",
83 "linebreak-style": ["off", "unix"],
84 "eol-last": ["error", "always"],
85 "max-len": ["error", {
86 "code": 225,
87 "ignoreComments": false,
88 "ignoreRegExpLiterals": true,
89 "ignoreStrings": true,
90 "ignoreTemplateLiterals": true,
91 "ignoreUrls": true
92 }],
93 "no-case-declarations": "off",
94 "no-console": "warn",
95 "no-debugger": "warn",
96 "no-multiple-empty-lines": ["warn", { "max": 1 }],
97 "no-param-reassign": "error",
98 "no-underscore-dangle": "error",
99 "no-undefined": "warn",
100 "multiline-ternary": ["error", "always-multiline"],
101 "prefer-destructuring": "off",
102 "object-shorthand": ["error", "consistent"],
103 "object-property-newline": ["error", { "allowAllPropertiesOnSameLine": false }],
104 "object-curly-newline": ["error", {
105 "ObjectExpression": {
106 "consistent": true,
107 "multiline": true,
108 "minProperties": 2
109 },
110 "ObjectPattern": {
111 "consistent": true,
112 "multiline": true
113 },
114 "ImportDeclaration": {
115 "consistent": true,
116 "multiline": true
117 },
118 "ExportDeclaration": {
119 "consistent": true,
120 "multiline": true
121 }
122 }],
123 "function-paren-newline": ["error", "multiline"],
124 "implicit-arrow-linebreak": ["error", "beside"],
125 "jsx-quotes": ["error", "prefer-single"],
126
127 // Import Plugin (https://github.com/benmosher/eslint-plugin-import)
128 "import/prefer-default-export": "off",
129 "import/no-named-default": "off",
130 "import/no-named-as-default": "off",
131 "import/exports-last": "off",
132 "import/group-exports": "off",
133 "import/order": "off", // turned off in favor of import-helpers/order-imports
134 "import/no-unused-modules": ["off", { "unusedExports": true }], // keep turned off since it takes a long time to run, turn on only when checking for this rule
135 "import/no-duplicates": "error",
136 "import/newline-after-import": "error",
137 "import/no-useless-path-segments": "error",
138 "import/no-cycle": ["off", { "maxDepth": 2 }], // turning this off for now but should consider turning it on
139 "import/first": "error",
140 "import/extensions": ["error", "ignorePackages", {
141 "js": "never",
142 "jsx": "never",
143 "ts": "never",
144 "tsx": "never"
145 }],
146 "import/no-extraneous-dependencies": ["error", { "devDependencies": ["**/*.test.*", "**/*.d.*", "**/setupTests.ts", "**/*.stories.*"] }],
147
148 // Import Helpers Plugin (https://github.com/Tibfib/eslint-plugin-import-helpers)
149 "import-helpers/order-imports": ["warn", {
150 "newlinesBetween": "never",
151 "groups": ["absolute", "module", "parent", "sibling", "index"],
152 "alphabetize": { "order": "asc" }
153 }],
154
155 // Promise Plugin (https://github.com/xjamundx/eslint-plugin-promise)
156 "promise/catch-or-return": "error",
157 "promise/no-return-wrap": "error",
158 "promise/param-names": "error",
159 "promise/always-return": "error",
160 "promise/no-native": "off",
161 "promise/no-nesting": "error",
162 "promise/no-promise-in-callback": "error",
163 "promise/no-callback-in-promise": "error",
164 "promise/avoid-new": "error",
165 "promise/no-new-statics": "error",
166 "promise/no-return-in-finally": "error",
167 "promise/valid-params": "error",
168 "promise/prefer-await-to-then": "error",
169 "promise/prefer-await-to-callbacks": "off", // using callbacks for thunks since those cannot be awaited
170
171 // Typescript Plugin (https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin)
172 "@typescript-eslint/brace-style": "error",
173 "@typescript-eslint/comma-dangle": ["warn", {
174 "arrays": "always-multiline",
175 "objects": "always-multiline",
176 "imports": "always-multiline",
177 "exports": "always-multiline",
178 "functions": "never", // parameters are positional and should not be easily re-arranged
179 "enums": "always-multiline",
180 "generics": "ignore", // in a .tsx file you need to do <T,> for generics so that it is not confused with jsx
181 "tuples": "always-multiline"
182 }],
183 "@typescript-eslint/indent": ["error", 4, { "SwitchCase": 1 }],
184 "@typescript-eslint/no-empty-function": "warn",
185 "@typescript-eslint/no-extra-parens": ["warn", "all", {
186 "nestedBinaryExpressions": false,
187 "ignoreJSX": "all",
188 "enforceForArrowConditionals": false,
189 "enforceForNewInMemberExpressions": false
190 }],
191 "@typescript-eslint/no-unused-vars": "warn",
192 "@typescript-eslint/lines-between-class-members": ["warn", "always"],
193 "@typescript-eslint/quotes": ["error", "single", {
194 "avoidEscape": false,
195 "allowTemplateLiterals": false
196 }],
197 "@typescript-eslint/semi": ["warn", "never"],
198 "@typescript-eslint/explicit-function-return-type": ["error", {
199 "allowExpressions": true,
200 "allowTypedFunctionExpressions": true,
201 "allowHigherOrderFunctions": true
202 }],
203 "@typescript-eslint/naming-convention": ["error",
204 {
205 "selector": "interface",
206 "format": ["PascalCase"],
207 "custom": {
208 "regex": "^I[A-Z]",
209 "match": true
210 }
211 }
212 ],
213 "@typescript-eslint/interface-name-prefix": "off", // off in favor of @typescript-eslint/naming-convention
214 "@typescript-eslint/promise-function-async": "error",
215 "@typescript-eslint/type-annotation-spacing": "warn",
216 "@typescript-eslint/object-curly-spacing": ["warn", "always"],
217 "@typescript-eslint/no-implicit-any-catch": "warn",
218 "@typescript-eslint/consistent-type-assertions": "warn", // https://basarat.gitbook.io/typescript/type-system/type-assertion#as-foo-vs-less-than-foo-greater-than
219 "@typescript-eslint/no-dynamic-delete": "error",
220 "@typescript-eslint/prefer-ts-expect-error": "error",
221 "@typescript-eslint/require-array-sort-compare": "error",
222 "@typescript-eslint/default-param-last": "error"
223 }
224}