-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.js
137 lines (107 loc) · 4.59 KB
/
.eslintrc.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const jsRulesExtension = [
'next/core-web-vitals',
'plugin:prettier/recommended',
];
const rules = {
// Warns if console.log is left in code. If you want to leave it permanently, use 'info'
"no-console": ["warn", { allow: ["info", "warn", "error"] }],
"react/jsx-filename-extension": "off",
"import/prefer-default-export": "off",
// Discourage reassigning parameters but allow for special cases
"no-param-reassign": [
"error",
{ props: true, ignorePropertyModificationsFor: ["draft"] },
],
// Allow using ++/--. It has it's own place under the Sun.
"no-plusplus": "off",
// Seems to be normal to have functions defined all over the place
// Classes? Lets define those helper classes at the top of the file.
"no-use-before-define": ["error", { functions: false, classes: true }],
// While properly formatted string using templates
// might be more readable over concatenation,
// auto-fix is very intrusive, and renders not the best results.
"prefer-template": "off",
// Restriction of using for x of xes is a bit heavy handed
"no-restricted-syntax": "off",
// Underscores are not the enemy
"no-underscore-dangle": "off",
// Highlight TODO comments in the code to make them more visible
"no-warning-comments": ["warn", { terms: ["todo", "fixme", "fix"] }],
// We don't need React in scope
"react/react-in-jsx-scope": 0,
// This one is nice to have but should not fail builds.
"import/order": "warn",
// Some times we want to explicitly return undefined to ensure there are no
// mistaken function return types
"no-useless-return": "off",
};
module.exports = {
plugins: ["prettier", "@typescript-eslint"],
extends: jsRulesExtension,
parser: "@typescript-eslint/parser",
root: true,
rules,
overrides: [
// Add typescript specific rules to typescript files
{
files: ["*.ts", "*.tsx"],
extends: ["plugin:@typescript-eslint/recommended"].concat(
jsRulesExtension,
),
rules: {
...rules,
// Eslint mis-reports this for typescript files. Typescript will handle on it's own.
"no-use-before-define": "off",
// ESLint misreports this in typescript files
"import/no-unresolved": "off",
"import/extensions": "off",
// PropTypes not required for typescript
"react/prop-types": "off",
// Prop spreading is totally fine in a type safe language
"react/jsx-props-no-spreading": "off",
// Implicit return types are sometimes okay
"@typescript-eslint/explicit-function-return-type": "off",
// Typescript has its own "no-use-before-define" that needs to be adjusted
"@typescript-eslint/no-use-before-define": [
"error",
{ functions: false, classes: true },
],
// Sometimes it is nice to have multiple related classes in a single file
"max-classes-per-file": "off",
// Typescript forces variable assignment before use so we sometimes need to
// explicity set a variable as undefined.
"no-undef-init": "off",
// Let's let typescript deal with that instead of eslint
"consistent-return": "off",
// ESLint shadow rule produces false positives for enums in typescript.
// Replace it with the typescript specific one
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
/**
* Lets turn of the requirement of return types being defined for module boundaries.
* This rule can be maddeningly annoying for simple functions like:
* export const foo = (bar: string) => bar
* Doesn't need to be:
* export const foo = (bar: string): string => bar
*/
"@typescript-eslint/explicit-module-boundary-types": "off",
/**
* This is misreported for namespaces in typescript files. Let's let typescript
* worry about using undefined variables instead of eslint.
*/
"no-undef": "off",
/* Replace with the typescript equivalent since the normal eslint rule doesn't work with enums */
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
// We don't need default props on typescript files
"react/require-default-props": "off",
// This one misreports on some typescript files
"react/no-unused-prop-types": "off",
// This rule doesn't play nicely with typescript
"react/function-component-definition": "off",
// Using require to import images where they are rendered is nice
"@typescript-eslint/no-var-requires": "off",
},
},
],
};