-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.eslintrc.js
176 lines (164 loc) · 6.31 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/** We extend a variety of already-configured ESLint rules (see `extends` in the exported ESLint
* config below). Note that plugins (see `plugins`) simply give us access to rules. We can extend
* rules from those plugins, if an exported configuration is available, or we can customize
* individual rules ourselves (see `customRules`). We can also extend rules and then override some
* of them (see `airbnbOverrides`). To inspect a configured rule that we're extending, simply go to
* the package repository and search for the rule name (e.g. https://github.com/airbnb/javascript/search?q=arrow-parens).
*/
// Rules that override the airbnb configuration that we extend.
const airbnbOverrides = {
// Files.com: Brevity.
// Airbnb: Consistency. Diff churn. Inconvenience of adding/removing parens as code changes.
'arrow-parens': ['error', 'as-needed'],
// Files.com: Consistency. Diff churn. Inconvenience of adding/removing braces as code changes.
// Airbnb: Brevity (only require curly braces for multi-line statements, allowing for single-line
// `if` statements with no braces, for example).
curly: ['error', 'all'],
// Airbnb: Enforces strict equality with the exception of loose equality checks on null (which is
// an easy way to check for either null or undefined). See
// https://github.com/airbnb/javascript/issues/1473#issuecomment-312178468.
// Files.com: No exceptions to strict equality. For a check of either null or undefined, prefer
// isNil() from lodash which does a loose equality check under the hood, but demonstrates explicit
// intent when used in our codebase.
eqeqeq: ['error', 'always'],
// Function names allow for a better debugging experience (i.e. eliminates anonymous function
// exceptions). Airbnb has this set to warn, and they recommend always naming functions (in order
// to eliminate any assumptions made about the Error's call stack). However, in our case, the name
// is inferred from the containing variable (modern browsers already handle this, as do compilers
// such as Babel, which we use). Therefore, we can use the 'as-needed' option and only require a
// name when it isn't assigned automatically per the ECMAScript specification.
'func-names': ['error', 'as-needed'],
// Enforced by Airbnb style guide, but not yet enforced via Airbnb's lint rules. This is on
// Airbnb's TODO list, but we'll go ahead and enforce it now. We can remove override after they
// enforce expression with an error.
'func-style': ['error', 'expression'],
// Airbnb: warn
'no-console': 'error',
// Airbnb: off
'padding-line-between-statements': [
'error',
{
blankLine: 'always',
next: '*',
prev: [
'block',
'block-like',
'multiline-block-like',
'multiline-const',
'multiline-expression',
'multiline-let',
],
},
],
// Files.com: Brevity.
// Airbnb: Rare code-safety concerns that may grow with new editions of ECMAScript.
semi: ['error', 'never'],
// Airbnb has this configured, but disabled. We enable it with their configuration, given that
// Files.com prefers alphabetization. Also see the 'react/jsx-sort-props' and
// sort-destructure-keys rules.
'sort-keys': ['error', 'asc', { caseSensitive: false, natural: true }],
}
// Temporary overrides of our extended configurations, until we've either cleaned up all errors or
// make a decision to permanently override a rule. To clean up, remove rule (allowing the extended
// style guide to take over), run lint, and fix errors.
const temporaryOverrides = {
camelcase: ['warn', { ignoreDestructuring: false, properties: 'never' }],
'consistent-return': 'warn',
'global-require': 'off',
'guard-for-in': 'warn',
'implicit-arrow-linebreak': 'off',
'import/no-dynamic-require': 'warn',
'import/no-import-module-exports': 'off',
'import/no-named-as-default': 'warn',
'import/prefer-default-export': 'warn',
'jest/no-conditional-expect': 'warn',
'jsx-a11y/label-has-associated-control': ['warn', {
assert: 'either',
controlComponents: ['Input', 'Field'],
depth: 25,
labelAttributes: [],
labelComponents: [],
}],
'jsx-a11y/no-autofocus': ['warn', { ignoreNonDOM: true }],
'max-len': "off",
'no-await-in-loop': 'warn',
'no-confusing-arrow': ['warn', { allowParens: true }],
'no-continue': 'warn',
'no-empty-function': ['warn', {
allow: [
'arrowFunctions',
'functions',
'methods',
],
}],
'no-nested-ternary': 'off',
'no-param-reassign': 'off',
'no-plusplus': 'off',
'no-promise-executor-return': 'warn',
'no-restricted-exports': ['warn', { restrictedNamedExports: ['default', 'then'] }],
'no-restricted-syntax': [
'warn',
{
message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
selector: 'ForInStatement',
},
{
message: 'iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations.',
selector: 'ForOfStatement',
},
{
message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
selector: 'LabeledStatement',
},
{
message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
selector: 'WithStatement',
},
],
'no-return-await': 'warn',
'no-shadow': 'warn',
'no-underscore-dangle': 'off',
'import/extensions': 'off',
radix: 'warn',
}
module.exports = {
env: {
browser: true,
es2021: true,
node: true,
},
extends: [
// Rule names without prefixes (standard ESLint rules), and those prefixed with jsx-a11y/,
// react/, and import/
'airbnb',
// Rule names prefixed with jest/
'plugin:jest/recommended',
],
overrides: [
{
files: ['*_spec.js'], // cypress specs
rules: {
'jest/expect-expect': 'off',
},
},
],
parser: '@babel/eslint-parser',
parserOptions: {
ecmaFeatures: {
jsx: true,
},
sourceType: 'module',
},
plugins: ['jest'],
rules: {
...airbnbOverrides,
...temporaryOverrides,
},
settings: {
'import/resolver': {
node: {
paths: ['src'],
},
},
},
}