Bug 1690340 - Part 2: Use the new naming for the developer tools menu items. r=jdescottes
[gecko.git] / devtools / .eslintrc.js
blobae08814a41f4a4897810c91f3067927d64dea9fc
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/. */
5 "use strict";
7 module.exports = {
8   plugins: ["react"],
9   globals: {
10     exports: true,
11     isWorker: true,
12     loader: true,
13     module: true,
14     reportError: true,
15     require: true,
16   },
17   overrides: [
18     {
19       files: ["client/framework/**"],
20       rules: {
21         "no-return-assign": "off",
22       },
23     },
24     {
25       files: ["client/shared/*.jsm"],
26       rules: {
27         camelcase: "off",
28       },
29     },
30     {
31       files: [
32         "client/framework/**",
33         "client/shared/*.jsm",
34         "client/shared/widgets/*.jsm",
35         "client/storage/VariablesView.jsm",
36       ],
37       rules: {
38         "consistent-return": "off",
39       },
40     },
41     {
42       files: ["client/framework/**"],
43       rules: {
44         "max-nested-callbacks": "off",
45       },
46     },
47     {
48       files: [
49         "client/framework/**",
50         "client/shared/*.jsm",
51         "client/shared/widgets/*.jsm",
52         "client/storage/VariablesView.jsm",
53         "shared/webconsole/test/chrome/*.html",
54       ],
55       rules: {
56         "mozilla/no-aArgs": "off",
57       },
58     },
59     {
60       files: ["client/framework/test/**"],
61       rules: {
62         "mozilla/var-only-at-top-level": "off",
63       },
64     },
65     {
66       files: [
67         "client/framework/**",
68         "client/shared/widgets/*.jsm",
69         "client/storage/VariablesView.jsm",
70       ],
71       rules: {
72         "no-shadow": "off",
73       },
74     },
75     {
76       files: ["client/framework/**"],
77       rules: {
78         strict: "off",
79       },
80     },
81     {
82       // For all head*.js files, turn off no-unused-vars at a global level
83       files: ["**/head*.js"],
84       rules: {
85         "no-unused-vars": ["error", { args: "none", vars: "local" }],
86       },
87     },
88     {
89       // For all server and shared files, prevent requiring devtools/client
90       // modules.
91       files: ["server/**", "shared/**"],
92       rules: {
93         "mozilla/reject-some-requires": [
94           "error",
95           "^(resource://)?devtools/client",
96         ],
97       },
98     },
99     {
100       // Cu, Cc etc... are not available in most devtools modules loaded by require.
101       files: ["**"],
102       excludedFiles: [
103         // Enable the rule on JSM, test head files and some specific files.
104         "**/*.jsm",
105         "**/test/**/head.js",
106         "**/test/**/shared-head.js",
107         "client/debugger/test/mochitest/code_frame-script.js",
108         "client/responsive.html/browser/content.js",
109         "client/shared/browser-loader.js",
110         "server/actors/webconsole/content-process-forward.js",
111         "server/actors/worker/service-worker-process.js",
112         "server/startup/content-process.js",
113         "server/startup/frame.js",
114         "shared/base-loader.js",
115         "shared/worker/loader.js",
116         "startup/aboutdebugging-registration.js",
117         "startup/aboutdevtools/aboutdevtools-registration.js",
118         "startup/aboutdevtoolstoolbox-registration.js",
119         "startup/devtools-startup.js",
120       ],
121       rules: {
122         "mozilla/no-define-cc-etc": "off",
123       },
124     },
125     {
126       // All DevTools files should avoid relative paths.
127       files: ["**"],
128       excludedFiles: [
129         // Debugger modules have a custom bundling logic which relies on relative
130         // paths.
131         "client/debugger/**",
132         // `client/shared/build` contains node helpers to build the debugger and
133         // not devtools modules.
134         "client/shared/build/**",
135       ],
136       rules: {
137         "mozilla/reject-relative-requires": "error",
138       },
139     },
140   ],
141   rules: {
142     // These are the rules that have been configured so far to match the
143     // devtools coding style.
145     // Rules from the mozilla plugin
146     "mozilla/balanced-observers": "error",
147     "mozilla/no-aArgs": "error",
148     // See bug 1224289.
149     "mozilla/reject-importGlobalProperties": ["error", "everything"],
150     "mozilla/var-only-at-top-level": "error",
151     "mozilla/use-chromeutils-import": ["error", { allowCu: true }],
153     // Rules from the React plugin
154     "react/display-name": "error",
155     "react/no-danger": "error",
156     "react/no-did-mount-set-state": "error",
157     "react/no-did-update-set-state": "error",
158     "react/no-direct-mutation-state": "error",
159     "react/no-unknown-property": "error",
160     "react/prefer-es6-class": ["off", "always"],
161     "react/prop-types": "error",
162     "react/sort-comp": [
163       "error",
164       {
165         order: ["static-methods", "lifecycle", "everything-else", "render"],
166         groups: {
167           lifecycle: [
168             "displayName",
169             "propTypes",
170             "contextTypes",
171             "childContextTypes",
172             "mixins",
173             "statics",
174             "defaultProps",
175             "constructor",
176             "getDefaultProps",
177             "getInitialState",
178             "state",
179             "getChildContext",
180             "componentWillMount",
181             "componentDidMount",
182             "componentWillReceiveProps",
183             "shouldComponentUpdate",
184             "componentWillUpdate",
185             "componentDidUpdate",
186             "componentWillUnmount",
187           ],
188         },
189       },
190     ],
192     // Disallow using variables outside the blocks they are defined (especially
193     // since only let and const are used, see "no-var").
194     "block-scoped-var": "error",
195     // Require camel case names
196     camelcase: ["error", { properties: "never" }],
197     // Warn about cyclomatic complexity in functions.
198     // 20 is ESLint's default, and we want to keep it this way to prevent new highly
199     // complex functions from being introduced. However, because Mozilla's eslintrc has
200     // some other value defined, we need to override it here. See bug 1553449 for more
201     // information on complex DevTools functions that are currently excluded.
202     complexity: ["error", 20],
203     // Don't warn for inconsistent naming when capturing this (not so important
204     // with auto-binding fat arrow functions).
205     "consistent-this": "off",
206     // Don't require a default case in switch statements. Avoid being forced to
207     // add a bogus default when you know all possible cases are handled.
208     "default-case": "off",
209     // Allow using == instead of ===, in the interest of landing something since
210     // the devtools codebase is split on convention here.
211     eqeqeq: "off",
212     // Don't require function expressions to have a name.
213     // This makes the code more verbose and hard to read. Our engine already
214     // does a fantastic job assigning a name to the function, which includes
215     // the enclosing function name, and worst case you have a line number that
216     // you can just look up.
217     "func-names": "off",
218     // Allow use of function declarations and expressions.
219     "func-style": "off",
220     // Only useful in a node environment.
221     "handle-callback-err": "off",
222     // Maximum depth callbacks can be nested.
223     "max-nested-callbacks": ["error", 3],
224     // Don't limit the number of parameters that can be used in a function.
225     "max-params": "off",
226     // Don't limit the maximum number of statement allowed in a function. We
227     // already have the complexity rule that's a better measurement.
228     "max-statements": "off",
229     // Require a capital letter for constructors, only check if all new
230     // operators are followed by a capital letter. Don't warn when capitalized
231     // functions are used without the new operator.
232     "new-cap": ["error", { capIsNew: false }],
233     // Allow use of bitwise operators.
234     "no-bitwise": "off",
235     // Allow using the console API.
236     "no-console": "off",
237     // Allow using constant expressions in conditions like while (true)
238     "no-constant-condition": "off",
239     // Allow use of the continue statement.
240     "no-continue": "off",
241     // Allow division operators explicitly at beginning of regular expression.
242     "no-div-regex": "off",
243     // Disallow empty statements. This will report an error for:
244     // try { something(); } catch (e) {}
245     // but will not report it for:
246     // try { something(); } catch (e) { /* Silencing the error because ...*/ }
247     // which is a valid use case.
248     "no-empty": "error",
249     // Disallow adding to native types
250     "no-extend-native": "error",
251     // Disallow fallthrough of case statements, except if there is a comment.
252     "no-fallthrough": "error",
253     // Allow comments inline after code.
254     "no-inline-comments": "off",
255     // Allow mixing regular variable and require declarations (not a node env).
256     "no-mixed-requires": "off",
257     // Disallow use of multiline strings (use template strings instead).
258     "no-multi-str": "error",
259     // Allow use of new operator with the require function.
260     "no-new-require": "off",
261     // Allow reassignment of function parameters.
262     "no-param-reassign": "off",
263     // Allow string concatenation with __dirname and __filename (not a node env).
264     "no-path-concat": "off",
265     // Allow use of unary operators, ++ and --.
266     "no-plusplus": "off",
267     // Allow using process.env (not a node environment).
268     "no-process-env": "off",
269     // Allow using process.exit (not a node environment).
270     "no-process-exit": "off",
271     // Disallow usage of __proto__ property.
272     "no-proto": "error",
273     // Disallow multiple spaces in a regular expression literal.
274     "no-regex-spaces": "off",
275     // Don't restrict usage of specified node modules (not a node environment).
276     "no-restricted-modules": "off",
277     // Prevent using some properties
278     "no-restricted-properties": [
279       "error",
280       {
281         property: "setupInParent",
282         message: "avoid child/parent communication with setupInParent",
283       },
284     ],
285     // Disallow use of assignment in return statement. It is preferable for a
286     // single line of code to have only one easily predictable effect.
287     "no-return-assign": "error",
288     // Allow use of javascript: urls.
289     "no-script-url": "off",
290     // Warn about declaration of variables already declared in the outer scope.
291     // This isn't an error because it sometimes is useful to use the same name
292     // in a small helper function rather than having to come up with another
293     // random name.
294     // Still, making this a warning can help people avoid being confused.
295     "no-shadow": "error",
296     // Allow use of synchronous methods (not a node environment).
297     "no-sync": "off",
298     // Allow the use of ternary operators.
299     "no-ternary": "off",
300     // Allow dangling underscores in identifiers (for privates).
301     "no-underscore-dangle": "off",
302     // Allow use of undefined variable.
303     "no-undefined": "off",
304     // Disallow global and local variables that aren't used, but allow unused
305     // function arguments.
306     "no-unused-vars": ["error", { args: "none", vars: "all" }],
307     // Allow using variables before they are defined.
308     "no-use-before-define": "off",
309     // We use var-only-at-top-level instead of no-var as we allow top level
310     // vars.
311     "no-var": "off",
312     // Allow using TODO/FIXME comments.
313     "no-warning-comments": "off",
314     // Don't require method and property shorthand syntax for object literals.
315     // We use this in the code a lot, but not consistently, and this seems more
316     // like something to check at code review time.
317     "object-shorthand": "off",
318     // Allow more than one variable declaration per function.
319     "one-var": "off",
320     // Enforce using `let` only when variables are reassigned.
321     "prefer-const": ["error", { destructuring: "all" }],
322     // Require use of the second argument for parseInt().
323     radix: "error",
324     // Don't require to sort variables within the same declaration block.
325     // Anyway, one-var is disabled.
326     "sort-vars": "off",
327     // Require "use strict" to be defined globally in the script.
328     strict: ["error", "global"],
329     // Warn about invalid JSDoc comments.
330     // Disabled for now because of https://github.com/eslint/eslint/issues/2270
331     // The rule fails on some jsdoc comments like in:
332     // devtools/client/webconsole/old/console-output.js
333     "valid-jsdoc": "off",
334     // Allow vars to be declared anywhere in the scope.
335     "vars-on-top": "off",
336     // Disallow Yoda conditions (where literal value comes first).
337     yoda: "error",
339     // And these are the rules that haven't been discussed so far, and that are
340     // disabled for now until we introduce them, one at a time.
342     // Require for-in loops to have an if statement.
343     "guard-for-in": "off",
344     // disallow the use of alert, confirm, and prompt
345     "no-alert": "off",
346     // disallow comparisons to null without a type-checking operator
347     "no-eq-null": "off",
348     // disallow overwriting functions written as function declarations
349     "no-func-assign": "off",
350     // disallow function or variable declarations in nested blocks
351     "no-inner-declarations": "off",
352     // disallow invalid regular expression strings in the RegExp constructor
353     "no-invalid-regexp": "off",
354     // disallow irregular whitespace outside of strings and comments
355     "no-irregular-whitespace": "off",
356     // disallow labels that share a name with a variable
357     "no-label-var": "off",
358     // disallow unnecessary nested blocks
359     "no-lone-blocks": "off",
360     // disallow creation of functions within loops
361     "no-loop-func": "off",
362     // disallow use of new operator when not part of the assignment or
363     // comparison
364     "no-new": "off",
365     // disallow use of new operator for Function object
366     "no-new-func": "off",
367     // disallow use of the Object constructor
368     "no-new-object": "off",
369     // disallows creating new instances of String,Number, and Boolean
370     "no-new-wrappers": "off",
371     // disallow the use of object properties of the global object (Math and
372     // JSON) as functions
373     "no-obj-calls": "off",
374     // disallow use of octal escape sequences in string literals, such as
375     // var foo = "Copyright \251";
376     "no-octal-escape": "off",
377     // disallow use of undefined when initializing variables
378     "no-undef-init": "off",
379     // disallow usage of expressions in statement position
380     "no-unused-expressions": "off",
381     // disallow unnecessary concatenation of literals or template literals
382     "no-useless-concat": "off",
383     // disallow use of void operator
384     "no-void": "off",
385     // require assignment operator shorthand where possible or prohibit it
386     // entirely
387     "operator-assignment": "off",
388   },