no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / devtools / .eslintrc.js
blob7fab2039c6611324139981b4c453e0f6aba51222
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     require: true,
15     DebuggerNotificationObserver: true,
16   },
17   overrides: [
18     {
19       files: ["client/framework/**"],
20       rules: {
21         "no-return-assign": "off",
22       },
23     },
24     {
25       files: [
26         // Allow non-camelcase so that run_test doesn't produce a warning.
27         "**/test*/**/*",
28       ],
29       rules: {
30         camelcase: "off",
31       },
32     },
33     {
34       files: ["client/framework/**"],
35       rules: {
36         "max-nested-callbacks": "off",
37       },
38     },
39     {
40       files: ["client/framework/**", "shared/webconsole/test/chrome/*.html"],
41       rules: {
42         "mozilla/no-aArgs": "off",
43       },
44     },
45     {
46       files: ["client/framework/test/**"],
47       rules: {
48         "mozilla/var-only-at-top-level": "off",
49       },
50     },
51     {
52       files: ["client/framework/**"],
53       rules: {
54         "no-shadow": "off",
55       },
56     },
57     {
58       files: ["client/framework/**"],
59       rules: {
60         strict: "off",
61       },
62     },
63     {
64       // For all head*.js files, turn off no-unused-vars at a global level
65       files: ["**/head*.js"],
66       rules: {
67         "no-unused-vars": ["error", { args: "none", vars: "local" }],
68       },
69     },
70     {
71       // For all server and shared files, prevent requiring devtools/client
72       // modules.
73       files: ["server/**", "shared/**"],
74       rules: {
75         "mozilla/reject-some-requires": [
76           "error",
77           "^(resource://)?devtools/client",
78         ],
79       },
80       excludedFiles: [
81         // Tests can always import anything.
82         "**/test*/**/*",
83       ],
84     },
85     {
86       // Cu, Cc etc... are not available in most devtools modules loaded by require.
87       files: ["**"],
88       excludedFiles: [
89         // Enable the rule on JSM, test head files and some specific files.
90         "**/*.jsm",
91         "**/*.sjs",
92         "**/test/**/head.js",
93         "**/test/**/shared-head.js",
94         "client/debugger/test/mochitest/code_frame-script.js",
95         "client/responsive.html/browser/content.js",
96         "server/startup/content-process.js",
97         "server/startup/frame.js",
98         "shared/loader/base-loader.sys.mjs",
99         "shared/loader/browser-loader.js",
100         "shared/loader/worker-loader.js",
101         "startup/aboutdebugging-registration.js",
102         "startup/aboutdevtoolstoolbox-registration.js",
103         "startup/devtools-startup.js",
104       ],
105       rules: {
106         "mozilla/no-define-cc-etc": "off",
107       },
108     },
109     {
110       // All DevTools files should avoid relative paths.
111       files: ["**"],
112       excludedFiles: [
113         // Debugger modules have a custom bundling logic which relies on relative
114         // paths.
115         "client/debugger/src/**",
116         // `client/shared/build` contains node helpers to build the debugger and
117         // not devtools modules.
118         "client/shared/build/**",
119       ],
120       rules: {
121         "mozilla/reject-relative-requires": "error",
122       },
123     },
124     {
125       // These tests use old React. We should accept deprecated API usages
126       files: [
127         "client/inspector/markup/test/doc_markup_events_react_development_15.4.1.html",
128         "client/inspector/markup/test/doc_markup_events_react_development_15.4.1_jsx.html",
129         "client/inspector/markup/test/doc_markup_events_react_production_15.3.1.html",
130         "client/inspector/markup/test/doc_markup_events_react_production_15.3.1_jsx.html",
131       ],
132       rules: {
133         "react/no-deprecated": "off",
134       },
135     },
136     {
137       // These files are used in both browser and node environments,
138       files: [
139         "shared/compatibility/constants.js",
140         "shared/compatibility/helpers.js",
141       ],
142       env: {
143         browser: false,
144         "mozilla/privileged": false,
145         "mozilla/specific": false,
146       },
147     },
148     {
149       // This file is only used in node environment.
150       files: ["shared/compatibility/bin/update.js"],
151       env: {
152         browser: false,
153         node: true,
154         "mozilla/privileged": false,
155         "mozilla/specific": false,
156       },
157     },
158     {
159       files: [
160         "client/inspector/markup/test/doc_markup_events_react_*_jsx.html",
161       ],
162       parserOptions: {
163         ecmaFeatures: {
164           jsx: true,
165         },
166       },
167     },
168   ],
169   rules: {
170     // These are the rules that have been configured so far to match the
171     // devtools coding style.
173     // Rules from the mozilla plugin
174     "mozilla/balanced-observers": "error",
175     "mozilla/no-aArgs": "error",
176     // See bug 1224289.
177     "mozilla/reject-importGlobalProperties": ["error", "everything"],
178     "mozilla/var-only-at-top-level": "error",
180     // Rules from the React plugin
181     "react/display-name": "error",
182     "react/no-danger": "error",
183     "react/no-deprecated": "error",
184     "react/no-did-mount-set-state": "error",
185     "react/no-did-update-set-state": "error",
186     "react/no-direct-mutation-state": "error",
187     "react/no-unknown-property": "error",
188     "react/prefer-es6-class": ["off", "always"],
189     "react/prop-types": "error",
190     "react/sort-comp": [
191       "error",
192       {
193         order: ["static-methods", "lifecycle", "everything-else", "render"],
194         groups: {
195           lifecycle: [
196             "displayName",
197             "propTypes",
198             "contextTypes",
199             "childContextTypes",
200             "mixins",
201             "statics",
202             "defaultProps",
203             "constructor",
204             "getDefaultProps",
205             "getInitialState",
206             "state",
207             "getChildContext",
208             "UNSAFE_componentWillMount",
209             "componentDidMount",
210             "UNSAFE_componentWillReceiveProps",
211             "shouldComponentUpdate",
212             "UNSAFE_componentWillUpdate",
213             "componentDidUpdate",
214             "componentWillUnmount",
215           ],
216         },
217       },
218     ],
220     // Disallow using variables outside the blocks they are defined (especially
221     // since only let and const are used, see "no-var").
222     "block-scoped-var": "error",
223     // Require camel case names
224     camelcase: ["error", { properties: "never" }],
225     // Warn about cyclomatic complexity in functions.
226     // 20 is ESLint's default, and we want to keep it this way to prevent new highly
227     // complex functions from being introduced. However, because Mozilla's eslintrc has
228     // some other value defined, we need to override it here. See bug 1553449 for more
229     // information on complex DevTools functions that are currently excluded.
230     complexity: ["error", 20],
231     // componentDidUnmount is not a real lifecycle method, use componentWillUnmount.
232     "id-denylist": ["error", "componentDidUnmount"],
233     // Maximum depth callbacks can be nested.
234     "max-nested-callbacks": ["error", 3],
235     // Require a capital letter for constructors, only check if all new
236     // operators are followed by a capital letter. Don't warn when capitalized
237     // functions are used without the new operator.
238     "new-cap": ["error", { capIsNew: false }],
239     // Disallow empty statements. This will report an error for:
240     // try { something(); } catch (e) {}
241     // but will not report it for:
242     // try { something(); } catch (e) { /* Silencing the error because ...*/ }
243     // which is a valid use case.
244     "no-empty": "error",
245     // Disallow adding to native types
246     "no-extend-native": "error",
247     // Disallow use of multiline strings (use template strings instead).
248     "no-multi-str": "error",
249     // Disallow usage of __proto__ property.
250     "no-proto": "error",
251     // Disallow use of assignment in return statement. It is preferable for a
252     // single line of code to have only one easily predictable effect.
253     "no-return-assign": "error",
254     // Warn about declaration of variables already declared in the outer scope.
255     // This isn't an error because it sometimes is useful to use the same name
256     // in a small helper function rather than having to come up with another
257     // random name.
258     // Still, making this a warning can help people avoid being confused.
259     "no-shadow": "error",
260     // Disallow global and local variables that aren't used, but allow unused
261     // function arguments.
262     "no-unused-vars": ["error", { args: "none", vars: "all" }],
263     // Enforce using `let` only when variables are reassigned.
264     "prefer-const": ["error", { destructuring: "all" }],
265     // Require use of the second argument for parseInt().
266     radix: "error",
267     // Require "use strict" to be defined globally in the script.
268     strict: ["error", "global"],
269     // Disallow Yoda conditions (where literal value comes first).
270     yoda: "error",
272     // And these are the rules that haven't been discussed so far, and that are
273     // disabled for now until we introduce them, one at a time.
275     // disallow overwriting functions written as function declarations
276     "no-func-assign": "off",
277     // disallow unnecessary nested blocks
278     "no-lone-blocks": "off",
279     // disallow unnecessary concatenation of literals or template literals
280     "no-useless-concat": "off",
281     // This rule will match any function starting with `use` which aren't
282     // necessarily in a React component. Also DevTools aren't using React hooks
283     // so this sounds unecessary.
284     "react-hooks/rules-of-hooks": "off",
285   },
286   settings: {
287     react: {
288       version: "16.8",
289     },
290   },