1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
6 plugins: ["react", "mozilla", "@babel", "import", "file-header"],
30 extends: ["prettier", "plugin:jest/recommended"],
32 ecmaVersion: "latest",
34 ecmaFeatures: { jsx: true },
36 // When the linter runs from the MC root, it won't pick up this project's
37 // babel.config.js, so we explicitly set Babel's root location so that
38 // it knows where to look.
50 // These are the rules that have been configured so far to match the
51 // devtools coding style.
53 // Rules from the mozilla plugin
54 "mozilla/mark-test-function-used": "error",
55 "mozilla/no-aArgs": "error",
57 "mozilla/reject-importGlobalProperties": "error",
58 "mozilla/var-only-at-top-level": "error",
60 // Rules from the React plugin
61 "react/jsx-uses-react": "error",
62 "react/jsx-uses-vars": "error",
63 "react/no-danger": "error",
64 "react/no-did-mount-set-state": "error",
65 "react/no-did-update-set-state": "error",
66 "react/no-direct-mutation-state": "error",
67 "react/no-unknown-property": "error",
68 "react/prop-types": "off",
72 order: ["propTypes", "everything-else", "render"],
76 // Check for import errors.
77 "import/no-duplicates": "error",
78 "import/named": "error",
79 "import/export": "error",
81 // Incompatible with jest-in-case cases. See related GitHub issue
82 // https://github.com/jest-community/eslint-plugin-jest/issues/534
83 "jest/no-standalone-expect": "off",
85 // Disallow flow control that escapes from "finally".
86 "no-unsafe-finally": "error",
88 // Disallow using variables outside the blocks they are defined (especially
89 // since only let and const are used, see "no-var").
90 "block-scoped-var": 2,
91 // Require camel case names
92 camelcase: ["error", { properties: "never" }],
93 // Warn about cyclomatic complexity in functions.
94 complexity: ["error", { max: 22 }],
95 // Don't warn for inconsistent naming when capturing this (not so important
96 // with auto-binding fat arrow functions).
98 // Don't require a default case in switch statements. Avoid being forced to
99 // add a bogus default when you know all possible cases are handled.
101 // Encourage the use of dot notation whenever possible.
103 // Allow using == instead of ===, in the interest of landing something since
104 // the devtools codebase is split on convention here.
106 // Don't require function expressions to have a name.
107 // This makes the code more verbose and hard to read. Our engine already
108 // does a fantastic job assigning a name to the function, which includes
109 // the enclosing function name, and worst case you have a line number that
110 // you can just look up.
112 // Allow use of function declarations and expressions.
114 // Deprecated, will be removed in 1.0.
116 // Only useful in a node environment.
117 "handle-callback-err": 0,
118 // Don't enforce the maximum depth that blocks can be nested. The complexity
119 // rule is a better rule to check this.
121 // Maximum depth callbacks can be nested.
122 "max-nested-callbacks": [2, 4],
123 // Don't limit the number of parameters that can be used in a function.
125 // Don't limit the maximum number of statement allowed in a function. We
126 // already have the complexity rule that's a better measurement.
128 // Require a capital letter for constructors, only check if all new
129 // operators are followed by a capital letter. Don't warn when capitalized
130 // functions are used without the new operator.
131 "new-cap": [2, { capIsNew: false }],
132 // Disallow use of the Array constructor.
133 "no-array-constructor": 2,
134 // Allow use of bitwise operators.
136 // Disallow use of arguments.caller or arguments.callee.
138 // Disallow the catch clause parameter name being the same as a variable in
139 // the outer scope, to avoid confusion.
140 "no-catch-shadow": 2,
141 // Disallow assignment in conditional expressions.
143 // Allow using the console API.
145 // Allow using constant expressions in conditions like while (true)
146 "no-constant-condition": 0,
147 // Allow use of the continue statement.
149 // Disallow control characters in regular expressions.
150 "no-control-regex": 2,
151 // Disallow use of debugger.
153 // Disallow deletion of variables (deleting properties is fine).
155 // Allow division operators explicitly at beginning of regular expression.
157 // Disallow duplicate arguments in functions.
159 // Disallow duplicate keys when creating object literals.
161 // Disallow a duplicate case label.
162 "no-duplicate-case": 2,
163 // Disallow else after a return in an if. The else around the second return
165 // if (something) { return false; } else { return true; }
167 // Disallow empty statements. This will report an error for:
168 // try { something(); } catch (e) {}
169 // but will not report it for:
170 // try { something(); } catch (e) { /* Silencing the error because ...*/ }
171 // which is a valid use case.
173 // Disallow the use of empty character classes in regular expressions.
174 "no-empty-character-class": 2,
175 // Disallow use of labels for anything other then loops and switches.
177 // Disallow use of eval(). We have other APIs to evaluate code in content.
179 // Disallow assigning to the exception in a catch block.
181 // Disallow adding to native types
182 "no-extend-native": 2,
183 // Disallow unnecessary function binding.
185 // Disallow double-negation boolean casts in a boolean context.
186 "no-extra-boolean-cast": 2,
187 // Deprecated, will be removed in 1.0.
188 "no-extra-strict": 0,
189 // Disallow fallthrough of case statements, except if there is a comment.
191 // Disallow comments inline after code.
192 "no-inline-comments": 2,
193 // Disallow if as the only statement in an else block.
195 // Allow mixing regular variable and require declarations (not a node env).
196 "no-mixed-requires": 0,
197 // Disallow use of multiline strings (use template strings instead).
199 "prefer-template": "error",
203 destructuring: "all",
204 ignoreReadBeforeAssign: false,
207 // Disallow reassignments of native objects.
208 "no-native-reassign": 2,
209 // Disallow nested ternary expressions, they make the code hard to read.
210 "no-nested-ternary": 2,
211 // Allow use of new operator with the require function.
213 // Disallow use of octal literals.
215 // Allow reassignment of function parameters.
216 "no-param-reassign": 0,
217 // Allow string concatenation with __dirname and __filename (not a node env).
219 // Allow use of unary operators, ++ and --.
221 // Allow using process.env (not a node environment).
223 // Allow using process.exit (not a node environment).
224 "no-process-exit": 0,
225 // Disallow usage of __proto__ property.
227 // Disallow declaring the same variable more than once (we use let anyway).
229 // Disallow multiple spaces in a regular expression literal.
230 "no-regex-spaces": 2,
231 // Don't restrict usage of specified node modules (not a node environment).
232 "no-restricted-modules": 0,
233 // Disallow use of assignment in return statement. It is preferable for a
234 // single line of code to have only one easily predictable effect.
235 "no-return-assign": 2,
236 // Allow use of javascript: urls.
238 // Disallow comparisons where both sides are exactly the same.
239 "no-self-compare": 2,
240 // Disallow use of comma operator.
242 // Warn about declaration of variables already declared in the outer scope.
243 // This isn't an error because it sometimes is useful to use the same name
244 // in a small helper function rather than having to come up with another
246 // Still, making this a warning can help people avoid being confused.
248 // Disallow shadowing of names such as arguments.
249 "no-shadow-restricted-names": 2,
250 // Disallow sparse arrays, eg. let arr = [,,2].
251 // Array destructuring is fine though:
252 // for (let [, breakpointPromise] of aPromises)
253 "no-sparse-arrays": 2,
254 // Allow use of synchronous methods (not a node environment).
256 // Allow the use of ternary operators.
258 // Disallow throwing literals (eg. throw "error" instead of
259 // throw new Error("error")).
260 "no-throw-literal": 2,
261 // Disallow use of undeclared variables unless mentioned in a /*global */
262 // block. Note that globals from head.js are automatically imported in tests
263 // by the import-headjs-globals rule form the mozilla eslint plugin.
265 // Allow dangling underscores in identifiers (for privates).
266 "no-underscore-dangle": 0,
267 // Allow use of undefined variable.
269 // Disallow the use of Boolean literals in conditional expressions.
270 "no-unneeded-ternary": 2,
271 // Disallow unreachable statements after a return, throw, continue, or break
274 // Disallow global and local variables that arent used, but allow unused function arguments.
275 "no-unused-vars": [2, { vars: "all", args: "none" }],
276 // Allow using variables before they are defined.
277 "no-use-before-define": 0,
278 // We use var-only-at-top-level instead of no-var as we allow top level
281 // Allow using TODO/FIXME comments.
282 "no-warning-comments": 0,
283 // Disallow use of the with statement.
285 // Dont require method and property shorthand syntax for object literals.
286 // We use this in the code a lot, but not consistently, and this seems more
287 // like something to check at code review time.
288 "object-shorthand": 0,
289 // Allow more than one variable declaration per function.
291 // Require use of the second argument for parseInt().
293 // Dont require to sort variables within the same declaration block.
294 // Anyway, one-var is disabled.
296 // Require "use strict" to be defined globally in the script.
297 strict: [2, "global"],
298 // Disallow comparisons with the value NaN.
300 // Ensure that the results of typeof are compared against a valid string.
302 // Allow vars to be declared anywhere in the scope.
304 // Disallow Yoda conditions (where literal value comes first).
307 // And these are the rules that haven't been discussed so far, and that are
308 // disabled for now until we introduce them, one at a time.
310 // Require for-in loops to have an if statement.
312 // allow/disallow an empty newline after var statement
313 "newline-after-var": 0,
314 // disallow the use of alert, confirm, and prompt
316 // disallow comparisons to null without a type-checking operator
318 // disallow overwriting functions written as function declarations
320 // disallow use of eval()-like methods
321 "no-implied-eval": 0,
322 // disallow function or variable declarations in nested blocks
323 "no-inner-declarations": 0,
324 // disallow invalid regular expression strings in the RegExp constructor
325 "no-invalid-regexp": 0,
326 // disallow irregular whitespace outside of strings and comments
327 "no-irregular-whitespace": 0,
328 // disallow labels that share a name with a variable
330 // disallow unnecessary nested blocks
332 // disallow creation of functions within loops
334 // disallow negation of the left operand of an in expression
335 "no-negated-in-lhs": 0,
336 // disallow use of new operator when not part of the assignment or
339 // disallow use of new operator for Function object
341 // disallow use of the Object constructor
343 // disallows creating new instances of String,Number, and Boolean
344 "no-new-wrappers": 0,
345 // disallow the use of object properties of the global object (Math and
346 // JSON) as functions
348 // disallow use of octal escape sequences in string literals, such as
349 // var foo = "Copyright \251";
350 "no-octal-escape": 0,
351 // disallow use of undefined when initializing variables
353 // disallow usage of expressions in statement position
354 "no-unused-expressions": 0,
355 // disallow use of void operator
357 // require assignment operator shorthand where possible or prohibit it
359 "operator-assignment": 0,
361 "file-header/file-header": [
364 "This Source Code Form is subject to the terms of the Mozilla Public",
365 "License, v. 2.0. If a copy of the MPL was not distributed with this",
366 "file, You can obtain one at <http://mozilla.org/MPL/2.0/>.",
369 ["-\\*-(.*)-\\*-", "eslint(.*)", "vim(.*)"],