forked from zulip/zulip-mobile
/
.eslintrc.yaml
282 lines (241 loc) · 10.2 KB
/
.eslintrc.yaml
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
parser: babel-eslint
extends:
- airbnb
- plugin:jest/recommended
- ./tools/formatting.eslintrc.yaml
plugins:
- jest
- flowtype
# - react-native # see commented-out rules config below
env:
browser: true
mocha: true
node: true
jest: true
globals: # true/false means mutable/const
__DEV__: false
__TEST__: false
settings:
# This setting is shared by the rules `import/*`. For details, see:
# https://github.com/benmosher/eslint-plugin-import#resolvers
# https://www.npmjs.com/package/eslint-import-resolver-node
import/resolver:
node:
extensions: [.js, .ios.js, .android.js, .json]
rules:
#
# Airbnb rule repeals / adjustments
#
# Our settings for a rule supersede Airbnb's, so we duplicate some
# of Airbnb's settings where we don't want a full repeal.
#
# Tricky code.
no-bitwise: off
no-confusing-arrow: off
no-continue: off
no-plusplus: off
no-nested-ternary: off
# Allow multiple classes per file.
#
# It's best to have just one class per file, but there are cases
# where it's useful to have some tiny helper React components
# declared in the same file as a main component.
max-classes-per-file: off
# Don't forbid prop spreading (it works fine for us)
react/jsx-props-no-spreading: off
# Don't enforce linebreaks in curly braces in JSX
#
# The difference this would make is minor, and leaving this rule off
# better aligns with our practices in JS proper (not JSX).
react/jsx-curly-newline: off
# Enforce `static` class property syntax.
react/static-property-placement:
- error
- static public field
# Enforce state initialization style (never in constructor)
react/state-in-constructor:
- error
- never
# Airbnb uses four selectors under 'no-restricted-syntax':
#
# ForInStatement, ForOfStatement, LabeledStatement, WithStatement.
# https://github.com/airbnb/javascript/blob/dee4f17/packages/eslint-config-airbnb-base/rules/style.js#L334.
no-restricted-syntax:
- error
# ForInStatement: We agree to forbid 'for..in' loops.
- selector: ForInStatement
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.'
# Further to Airbnb's explanation: They're also slightly buggy
# in JSC [1], on which react-native is built... and,
# surprisingly, their semantics weren't fully nailed down until
# as late as 2019-12 [2]. But the above is reason enough.
# [1]: https://bugs.webkit.org/show_bug.cgi?id=38970
# [2]: https://github.com/tc39/proposals/commit/cb9c6e50
# ForOfStatement: We don't agree to forbid 'for..of' loops.
#
# Airbnb's style guide discourages language-level loops in favor of
# array iterations. We don't share this controversial view; see it
# expressed at https://github.com/airbnb/javascript/issues/1103.
# LabeledStatement: We don't agree to forbid labeled statements.
#
# We don't really use them, but Airbnb's reasoning flows from their
# anti-loop position, mentioned above, which we don't share.
# WithStatement: Agree to forbid with statements, but not this way.
#
# ESLint provides a built-in `no-with` rule with the same effect,
# which we choose, instead of this circumlocution.
no-with: error
#
# Formatting and naming
#
camelcase: off
no-await-in-loop: off # Promise.all is not always desirable
# Permit dangling underscores in class property names, to denote "private"
# fields. (These should be replaced with true private fields per the TC39
# class fields proposal [1], once that's available to us.)
#
# [1]: https://github.com/tc39/proposal-class-fields
no-underscore-dangle: ["error", { allowAfterThis: true } ]
# Disallow double underscores and trailing underscores.
id-match: ["error", "^_?([a-zA-Z0-9$]+_?)*$", { "properties": true }]
# Disable a bunch of rules that should be taken care of by prettier.
arrow-parens: off
comma-dangle: off
function-paren-newline: off
indent: off
lines-between-class-members: off
max-len: off
no-mixed-operators: off
object-curly-newline: off
quote-props: off
# For more formatting rules, see tools/formatting.eslintrc.yaml .
# Repeal some rather absurd rules that make some code impossible to write in
# the most reasonable way.
no-else-return: off
prefer-destructuring:
- error
- AssignmentExpression: {array: false, object: false}
# Likely-wrong code
no-unused-vars: [warn, {vars: local, args: none}]
# no-param-reassign seems well-intentioned... but fires on common uses
# of Array#reduce. Too noisy.
no-param-reassign: off
# Imports
import/prefer-default-export: off
import/no-extraneous-dependencies:
- error
- devDependencies: ['**/__tests__/**/*.js', tools/**]
no-restricted-imports:
- error
- patterns: ['**/__tests__/**']
import/no-cycle: off # This would be nice to fix; but isn't easy.
import/export: off # This is redundant with Flow, and buggy.
# Jest
# This rule could be useful if it fired only on new instances; but we
# don't have a way to do that, and it doesn't make sense to keep these
# out of the repo.
jest/no-disabled-tests: off
# Only using string literals for test names, under the heading
# `titleMustBeString`, [1] is silly and should probably not be a
# thing [2]. We wish we could get all of this rule except that part.
# In fact, it's possible to ignore it *for describe blocks
# only* [3], but there are no plans to allow turning it off for
# `test` blocks.
#
# [1] https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/valid-title.md
# [2] https://github.com/jest-community/eslint-plugin-jest/issues/203.
# [3] https://github.com/jest-community/eslint-plugin-jest/issues/470
jest/valid-title: off
# The docs for this rule [1] say that placing an `expect` call
# outside a `test` or `it` block (e.g., in a `beforeEach` or
# `afterEach`) means that the assertion isn't executed. Empirically,
# this seems just wrong [2], and there are a few places where we
# want to call `expect` in a `beforeEach` or `afterEach` to assert
# that multiple tests in the same file aren't interfering with each
# other by leaving bits of state lying around.
#
# [1] https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-standalone-expect.md
# [2] https://github.com/zulip/zulip-mobile/pull/4235#discussion_r489984717
jest/no-standalone-expect: off
# React
react/jsx-filename-extension: off # Like RN upstream, we call the files *.js.
react/destructuring-assignment: off # The opposite is often much cleaner.
react/no-multi-comp: off # This often just forces making code worse.
react/no-unused-prop-types: off # This can be perfectly appropriate.
react/default-props-match-prop-types: off # We handle this better with types.
react/prop-types: off # We handle this better with types.
react/require-default-props: off # We handle this better with types.
# These two could be good to fix.
react/prefer-stateless-function: off
react/sort-comp: off
# React Native.
#
# This plugin isn't included in the airbnb config, and it doesn't
# itself enable any rules by default, so this config is it.
#
# (From the docs as of 2020-03, these are the rules we'd like to use.
# Plugin disabled only because the rules are; bring it back when
# reviving either of them.)
#
# react-native/no-unused-styles: error # This is buggy on the `this.styles` pattern.
# react-native/no-color-literals: error # TODO eliminate these and enable.
# Flow
flowtype/boolean-style: [error, boolean]
flowtype/define-flow-type: warn
flowtype/delimiter-dangle: off
flowtype/generic-spacing: [error, never]
flowtype/no-dupe-keys: error
flowtype/no-primitive-constructor-types: error
flowtype/no-types-missing-file-annotation: error
################# flowtype/no-weak-types: error
# flowtype/require-parameter-type: error
flowtype/require-readonly-react-props: error
# flowtype/require-return-type: [error, always, {annotateUndefined: never}]
flowtype/require-valid-file-annotation: error
flowtype/semi: [error, always]
flowtype/space-before-generic-bracket: [error, never]
flowtype/space-before-type-colon: [error, never]
# For more formatting rules, see tools/formatting.eslintrc.yaml.
flowtype/type-id-match: [error, '^([A-Z][a-z0-9]+)+$']
flowtype/union-intersection-spacing: [error, always]
flowtype/use-flow-type: warn
flowtype/valid-syntax: warn
overrides:
# Test file overrides
- files: ['**/__tests__/**']
rules:
no-restricted-imports: off
# Maintain code style of redux-persist as we received it.
- files: ['src/third/redux-persist/**']
rules:
semi: off # semicolons are omitted
curly: off # one-line `if`s and `else`s without semicolons
nonblock-statement-body-position: off # same reason as `curly`
space-before-function-paren: off # `function myFunc (arg1) { ... }`
arrow-body-style: off # `() => { return 1; }` used over `() => 1`
object-curly-spacing: off # `{foo: 'bar'}` used over { foo: 'bar' }
no-underscore-dangle: off # various identifiers beginning with '_'
import/order: off # imports not ordered a particular way
func-names: off # anonymous non-arrow functions sometimes used
object-shorthand: off # ES6 object method syntax not used
# function declarations are made (we favor function expressions
# with `const`), so these functions may be used above the
# declaration because they are hoisted. Don't change them to our
# style without addressing this!
no-use-before-define: off
no-console: off
prefer-const: off # `let` is sometimes used unnecessarily
consistent-return: off # defense against accidental `undefined` return
no-unused-expressions: off # `myFn && myFn()` used
no-var: off # var is rarely, but sometimes, used (avoid new uses)
# a few `var`s not *quite* at the top of function scope (they're
# very near to it); no bugs known to result from this
vars-on-top: off
# a few variables already declared in upper scope; no bugs known
# to result from this
no-shadow: off
# foo.hasOwnProperty("bar") used instead of
# Object.prototype.hasOwnProperty.call(foo, "bar")
no-prototype-builtins: off