Bug 1942006 - Upstream a variety of Servo-specific code from Servo's downstream fork...
[gecko.git] / devtools / .eslintrc.js
blob86505e71ef346ed82794ecfd14022edd51efc2ba
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 DebuggerNotificationObserver: true,
14 overrides: [
16 files: ["**/*.*"],
17 excludedFiles: ["**/*.sys.mjs", "**/*.worker.js"],
18 globals: {
19 loader: true,
20 module: true,
21 require: true,
25 files: ["client/framework/**"],
26 rules: {
27 "no-return-assign": "off",
31 files: [
32 // Allow non-camelcase so that run_test doesn't produce a warning.
33 "**/test*/**/*",
35 rules: {
36 camelcase: "off",
40 files: ["client/framework/**"],
41 rules: {
42 "max-nested-callbacks": "off",
46 files: ["client/framework/**", "shared/webconsole/test/chrome/*.html"],
47 rules: {
48 "mozilla/no-aArgs": "off",
52 files: ["client/framework/test/**"],
53 rules: {
54 "mozilla/var-only-at-top-level": "off",
58 files: ["client/framework/**"],
59 rules: {
60 strict: "off",
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" }],
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",
80 excludedFiles: [
81 // Tests can always import anything.
82 "**/test*/**/*",
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/**",
96 rules: {
97 "mozilla/reject-relative-requires": "error",
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",
108 rules: {
109 "react/no-deprecated": "off",
113 // These files are used in both browser and node environments,
114 files: [
115 "shared/compatibility/constants.js",
116 "shared/compatibility/helpers.js",
118 env: {
119 browser: false,
120 "mozilla/privileged": false,
121 "mozilla/specific": false,
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,
135 files: [
136 "client/inspector/markup/test/doc_markup_events_react_*_jsx.html",
138 parserOptions: {
139 ecmaFeatures: {
140 jsx: true,
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",
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",
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 // Disallow global and local variables that aren't used. Allow unused
231 // function arguments prefixed with `_`.
232 "no-unused-vars": ["error", { argsIgnorePattern: "^_", vars: "all" }],
233 // Enforce using `let` only when variables are reassigned.
234 "prefer-const": ["error", { destructuring: "all" }],
235 // Require use of the second argument for parseInt().
236 radix: "error",
237 // Require "use strict" to be defined globally in the script.
238 strict: ["error", "global"],
239 // Disallow Yoda conditions (where literal value comes first).
240 yoda: "error",
242 // And these are the rules that haven't been discussed so far, and that are
243 // disabled for now until we introduce them, one at a time.
245 // disallow overwriting functions written as function declarations
246 "no-func-assign": "off",
247 // disallow unnecessary nested blocks
248 "no-lone-blocks": "off",
249 // disallow unnecessary concatenation of literals or template literals
250 "no-useless-concat": "off",
251 // This rule will match any function starting with `use` which aren't
252 // necessarily in a React component. Also DevTools aren't using React hooks
253 // so this sounds unecessary.
254 "react-hooks/rules-of-hooks": "off",
256 settings: {
257 react: {
258 version: "16.8",