Bug 1888033 - [Menu Redesign] Add a secret setting and feature flag for the menu...
[gecko.git] / devtools / .eslintrc.js
blob9ccbfa1d9547dd254d5f60b3983ad42690d6bb19
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", { argsIgnorePattern: "^_", 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       // All DevTools files should avoid relative paths.
87       files: ["**"],
88       excludedFiles: [
89         // Debugger modules have a custom bundling logic which relies on relative
90         // paths.
91         "client/debugger/src/**",
92         // `client/shared/build` contains node helpers to build the debugger and
93         // not devtools modules.
94         "client/shared/build/**",
95       ],
96       rules: {
97         "mozilla/reject-relative-requires": "error",
98       },
99     },
100     {
101       // These tests use old React. We should accept deprecated API usages
102       files: [
103         "client/inspector/markup/test/doc_markup_events_react_development_15.4.1.html",
104         "client/inspector/markup/test/doc_markup_events_react_development_15.4.1_jsx.html",
105         "client/inspector/markup/test/doc_markup_events_react_production_15.3.1.html",
106         "client/inspector/markup/test/doc_markup_events_react_production_15.3.1_jsx.html",
107       ],
108       rules: {
109         "react/no-deprecated": "off",
110       },
111     },
112     {
113       // These files are used in both browser and node environments,
114       files: [
115         "shared/compatibility/constants.js",
116         "shared/compatibility/helpers.js",
117       ],
118       env: {
119         browser: false,
120         "mozilla/privileged": false,
121         "mozilla/specific": false,
122       },
123     },
124     {
125       // This file is only used in node environment.
126       files: ["shared/compatibility/bin/update.js"],
127       env: {
128         browser: false,
129         node: true,
130         "mozilla/privileged": false,
131         "mozilla/specific": false,
132       },
133     },
134     {
135       files: [
136         "client/inspector/markup/test/doc_markup_events_react_*_jsx.html",
137       ],
138       parserOptions: {
139         ecmaFeatures: {
140           jsx: true,
141         },
142       },
143     },
144   ],
145   rules: {
146     // These are the rules that have been configured so far to match the
147     // devtools coding style.
149     // Rules from the mozilla plugin
150     "mozilla/balanced-observers": "error",
151     "mozilla/no-aArgs": "error",
152     // See bug 1224289.
153     "mozilla/reject-importGlobalProperties": ["error", "everything"],
154     "mozilla/var-only-at-top-level": "error",
156     // Rules from the React plugin
157     "react/display-name": "error",
158     "react/no-danger": "error",
159     "react/no-deprecated": "error",
160     "react/no-did-mount-set-state": "error",
161     "react/no-did-update-set-state": "error",
162     "react/no-direct-mutation-state": "error",
163     "react/no-unknown-property": "error",
164     "react/prefer-es6-class": ["off", "always"],
165     "react/prop-types": "error",
166     "react/sort-comp": [
167       "error",
168       {
169         order: ["static-methods", "lifecycle", "everything-else", "render"],
170         groups: {
171           lifecycle: [
172             "displayName",
173             "propTypes",
174             "contextTypes",
175             "childContextTypes",
176             "mixins",
177             "statics",
178             "defaultProps",
179             "constructor",
180             "getDefaultProps",
181             "getInitialState",
182             "state",
183             "getChildContext",
184             "UNSAFE_componentWillMount",
185             "componentDidMount",
186             "UNSAFE_componentWillReceiveProps",
187             "shouldComponentUpdate",
188             "UNSAFE_componentWillUpdate",
189             "componentDidUpdate",
190             "componentWillUnmount",
191           ],
192         },
193       },
194     ],
196     // Disallow using variables outside the blocks they are defined (especially
197     // since only let and const are used, see "no-var").
198     "block-scoped-var": "error",
199     // Require camel case names
200     camelcase: ["error", { properties: "never" }],
201     // Warn about cyclomatic complexity in functions.
202     // 20 is ESLint's default, and we want to keep it this way to prevent new highly
203     // complex functions from being introduced. However, because Mozilla's eslintrc has
204     // some other value defined, we need to override it here. See bug 1553449 for more
205     // information on complex DevTools functions that are currently excluded.
206     complexity: ["error", 20],
207     // componentDidUnmount is not a real lifecycle method, use componentWillUnmount.
208     "id-denylist": ["error", "componentDidUnmount"],
209     // Maximum depth callbacks can be nested.
210     "max-nested-callbacks": ["error", 3],
211     // Require a capital letter for constructors, only check if all new
212     // operators are followed by a capital letter. Don't warn when capitalized
213     // functions are used without the new operator.
214     "new-cap": ["error", { capIsNew: false }],
215     // Disallow empty statements. This will report an error for:
216     // try { something(); } catch (e) {}
217     // but will not report it for:
218     // try { something(); } catch (e) { /* Silencing the error because ...*/ }
219     // which is a valid use case.
220     "no-empty": "error",
221     // Disallow adding to native types
222     "no-extend-native": "error",
223     // Disallow use of multiline strings (use template strings instead).
224     "no-multi-str": "error",
225     // Disallow usage of __proto__ property.
226     "no-proto": "error",
227     // Disallow use of assignment in return statement. It is preferable for a
228     // single line of code to have only one easily predictable effect.
229     "no-return-assign": "error",
230     // Warn about declaration of variables already declared in the outer scope.
231     // This isn't an error because it sometimes is useful to use the same name
232     // in a small helper function rather than having to come up with another
233     // random name.
234     // Still, making this a warning can help people avoid being confused.
235     "no-shadow": "error",
236     // Disallow global and local variables that aren't used. Allow unused
237     // function arguments prefixed with `_`.
238     "no-unused-vars": ["error", { argsIgnorePattern: "^_", vars: "all" }],
239     // Enforce using `let` only when variables are reassigned.
240     "prefer-const": ["error", { destructuring: "all" }],
241     // Require use of the second argument for parseInt().
242     radix: "error",
243     // Require "use strict" to be defined globally in the script.
244     strict: ["error", "global"],
245     // Disallow Yoda conditions (where literal value comes first).
246     yoda: "error",
248     // And these are the rules that haven't been discussed so far, and that are
249     // disabled for now until we introduce them, one at a time.
251     // disallow overwriting functions written as function declarations
252     "no-func-assign": "off",
253     // disallow unnecessary nested blocks
254     "no-lone-blocks": "off",
255     // disallow unnecessary concatenation of literals or template literals
256     "no-useless-concat": "off",
257     // This rule will match any function starting with `use` which aren't
258     // necessarily in a React component. Also DevTools aren't using React hooks
259     // so this sounds unecessary.
260     "react-hooks/rules-of-hooks": "off",
261   },
262   settings: {
263     react: {
264       version: "16.8",
265     },
266   },