Bug 1568151 - Replace `target.getInspector()` by `target.getFront("inspector")`....
[gecko.git] / .eslintrc.js
blob2f39cda63560e89a7ae61ea6d8410a9a2251ab01
1 "use strict";
3 const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-test.js");
4 const browserTestConfig = require("eslint-plugin-mozilla/lib/configs/browser-test.js");
5 const mochitestTestConfig = require("eslint-plugin-mozilla/lib/configs/mochitest-test.js");
6 const chromeTestConfig = require("eslint-plugin-mozilla/lib/configs/chrome-test.js");
8 /**
9  * Some configurations have overrides, which can't be specified within overrides,
10  * so we need to remove them.
11  */
12 function removeOverrides(config) {
13   config = {...config};
14   delete config.overrides;
15   return config;
18 const xpcshellTestPaths = [
19   "**/test*/unit*/",
20   "**/test*/xpcshell/",
23 const browserTestPaths = [
24   "**/test*/**/browser/",
27 const mochitestTestPaths = [
28   "**/test*/mochitest/",
31 const chromeTestPaths = [
32   "**/test*/chrome/",
35 module.exports = {
36   // New rules and configurations should generally be added in
37   // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
38   // allow external repositories that use the plugin to pick them up as well.
39   "extends": [
40     "plugin:mozilla/recommended"
41   ],
42   "plugins": [
43     "mozilla"
44   ],
45   "overrides": [{
46       "files": [
47         "*.html",
48         "*.xhtml",
49         "*.xul",
50         "*.xml",
51         "js/src/builtin/**/*.js",
52         "js/src/shell/**/*.js"
53       ],
54       "rules": {
55         // Curly brackets are required for all the tree via recommended.js,
56         // however these files aren't auto-fixable at the moment.
57         "curly": "off"
58       },
59     }, {
60     // These xbl bindings are assumed to be in the browser-window environment,
61     // we would mark it in the files, but ESLint made this more difficult with
62     // our xml processor, so we list them here. Bug 1397874 & co are working
63     // towards removing these files completely.
64     "files": [
65       "browser/base/content/tabbrowser.xml",
66       "browser/base/content/urlbarBindings.xml",
67       "browser/components/search/content/search.xml",
68       "browser/components/translation/translation-infobar.xml",
69       "toolkit/components/prompts/content/tabprompts.xml"
70     ],
71     "env": {
72       "mozilla/browser-window": true
73     }
74   }, {
75     // TODO: Bug 1515949. Enable no-undef for gfx/
76     "files": "gfx/layers/apz/test/mochitest/**",
77     "rules": {
78       "no-undef": "off",
79     }
80   }, {
81     ...removeOverrides(xpcshellTestConfig),
82     "files": xpcshellTestPaths.map(path => `${path}**`),
83     "excludedFiles": "devtools/**"
84   }, {
85     // If it is an xpcshell head file, we turn off global unused variable checks, as it
86     // would require searching the other test files to know if they are used or not.
87     // This would be expensive and slow, and it isn't worth it for head files.
88     // We could get developers to declare as exported, but that doesn't seem worth it.
89     "files": xpcshellTestPaths.map(path => `${path}head*.js`),
90     "rules": {
91       "no-unused-vars": ["error", {
92         "args": "none",
93         "vars": "local",
94       }],
95     },
96   }, {
97     ...browserTestConfig,
98     "files": browserTestPaths.map(path => `${path}**`),
99     "excludedFiles": "devtools/**"
100   }, {
101     ...removeOverrides(mochitestTestConfig),
102     "files": mochitestTestPaths.map(path => `${path}**`),
103     "excludedFiles": [
104       "devtools/**",
105       "security/manager/ssl/tests/mochitest/browser/**",
106       "testing/mochitest/**",
107     ],
108   }, {
109     ...removeOverrides(chromeTestConfig),
110     "files": chromeTestPaths.map(path => `${path}**`),
111     "excludedFiles": [
112       "devtools/**",
113     ],
114   }, {
115     "env": {
116       // Ideally we wouldn't be using the simpletest env here, but our uses of
117       // js files mean we pick up everything from the global scope, which could
118       // be any one of a number of html files. So we just allow the basics...
119       "mozilla/simpletest": true,
120     },
121     "files": [
122       ...mochitestTestPaths.map(path => `${path}/**/*.js`),
123       ...chromeTestPaths.map(path => `${path}/**/*.js`),
124     ],
125   }, {
126     "files": [
127       "extensions/permissions/test/**",
128       "extensions/spellcheck/**",
129       "extensions/universalchardet/tests/**",
130     ],
131     "rules": {
132       "mozilla/reject-importGlobalProperties": "off",
133       "mozilla/use-default-preference-values": "off",
134       "mozilla/use-services": "off",
135       "no-array-constructor": "off",
136       "no-undef": "off",
137       "no-unused-vars": "off",
138       "no-redeclare": "off",
139       "no-global-assign": "off",
140     }
141   }, {
142     "files": [
143       "image/**",
144     ],
145     "rules": {
146       "mozilla/consistent-if-bracing": "off",
147       "mozilla/use-chromeutils-generateqi": "off",
148       "mozilla/use-services": "off",
149       "no-array-constructor": "off",
150       "no-implied-eval": "off",
151       "no-redeclare": "off",
152       "no-self-assign": "off",
153       "no-throw-literal": "off",
154       "no-undef": "off",
155       "no-unneeded-ternary": "off",
156       "no-unused-vars": "off",
157     }
158   }, {
159     "files": [
160       "netwerk/cookie/test/browser/**",
161       "netwerk/test/browser/**",
162       "netwerk/test/mochitests/**",
163       "netwerk/test/unit*/**",
164     ],
165     "rules": {
166       "mozilla/consistent-if-bracing": "off",
167       "mozilla/reject-importGlobalProperties": "off",
168       "mozilla/no-arbitrary-setTimeout": "off",
169       "mozilla/no-define-cc-etc": "off",
170       "mozilla/use-default-preference-values": "off",
171       "mozilla/use-services": "off",
172       "consistent-return": "off",
173       "no-array-constructor": "off",
174       "no-eval": "off",
175       "no-global-assign": "off",
176       "no-nested-ternary": "off",
177       "no-new-wrappers": "off",
178       "no-redeclare": "off",
179       "no-return-await": "off",
180       "no-sequences": "off",
181       "no-shadow": "off",
182       "no-throw-literal": "off",
183       "no-undef": "off",
184       "no-unreachable": "off",
185       "no-unused-vars": "off",
186       "no-useless-return": "off",
187     }
188   }, {
189     "files": [
190       "layout/**",
191     ],
192     "rules": {
193       "object-shorthand": "off",
194       "mozilla/avoid-removeChild": "off",
195       "mozilla/consistent-if-bracing": "off",
196       "mozilla/reject-importGlobalProperties": "off",
197       "mozilla/no-arbitrary-setTimeout": "off",
198       "mozilla/no-define-cc-etc": "off",
199       "mozilla/use-chromeutils-generateqi": "off",
200       "mozilla/use-default-preference-values": "off",
201       "mozilla/use-includes-instead-of-indexOf": "off",
202       "mozilla/use-services": "off",
203       "mozilla/use-ownerGlobal": "off",
204       "complexity": "off",
205       "consistent-return": "off",
206       "no-array-constructor": "off",
207       "no-caller": "off",
208       "no-cond-assign": "off",
209       "no-extra-boolean-cast": "off",
210       "no-eval": "off",
211       "no-func-assign": "off",
212       "no-global-assign": "off",
213       "no-implied-eval": "off",
214       "no-lonely-if": "off",
215       "no-nested-ternary": "off",
216       "no-new-wrappers": "off",
217       "no-redeclare": "off",
218       "no-restricted-globals": "off",
219       "no-return-await": "off",
220       "no-sequences": "off",
221       "no-throw-literal": "off",
222       "no-useless-concat": "off",
223       "no-undef": "off",
224       "no-unreachable": "off",
225       "no-unsanitized/method": "off",
226       "no-unsanitized/property": "off",
227       "no-unsafe-negation": "off",
228       "no-unused-vars": "off",
229       "no-useless-return": "off",
230     }
231   }, {
232     "files": [
233       "dom/animation/**",
234       "dom/base/test/*.*",
235       "dom/base/test/unit/test_serializers_entities*.js",
236       "dom/base/test/unit_ipc/**",
237       "dom/base/test/jsmodules/**",
238       "dom/base/*.*",
239       "dom/canvas/**",
240       "dom/encoding/**",
241       "dom/events/**",
242       "dom/fetch/**",
243       "dom/file/**",
244       "dom/html/**",
245       "dom/jsurl/**",
246       "dom/media/tests/**",
247       "dom/media/webaudio/**",
248       "dom/media/webspeech/**",
249       "dom/messagechannel/**",
250       "dom/midi/**",
251       "dom/network/**",
252       "dom/payments/**",
253       "dom/performance/**",
254       "dom/permission/**",
255       "dom/quota/**",
256       "dom/security/test/cors/**",
257       "dom/security/test/csp/**",
258       "dom/security/test/general/**",
259       "dom/security/test/mixedcontentblocker/**",
260       "dom/security/test/sri/**",
261       "dom/serviceworkers/**",
262       "dom/smil/**",
263       "dom/tests/mochitest/**",
264       "dom/u2f/**",
265       "dom/vr/**",
266       "dom/webauthn/**",
267       "dom/webgpu/**",
268       "dom/websocket/**",
269       "dom/workers/**",
270       "dom/worklet/**",
271       "dom/xbl/**",
272       "dom/xml/**",
273       "dom/xslt/**",
274       "dom/xul/**",
275     ],
276     "rules": {
277       "consistent-return": "off",
278       "dot-notation": "off",
279       "object-shorthand": "off",
280       "mozilla/avoid-removeChild": "off",
281       "mozilla/consistent-if-bracing": "off",
282       "mozilla/no-arbitrary-setTimeout": "off",
283       "mozilla/no-compare-against-boolean-literals": "off",
284       "mozilla/no-define-cc-etc": "off",
285       "mozilla/no-useless-parameters": "off",
286       "mozilla/no-useless-run-test": "off",
287       "mozilla/reject-importGlobalProperties": "off",
288       "mozilla/use-cc-etc": "off",
289       "mozilla/use-chromeutils-generateqi": "off",
290       "mozilla/use-chromeutils-import": "off",
291       "mozilla/use-includes-instead-of-indexOf": "off",
292       "mozilla/use-ownerGlobal": "off",
293       "mozilla/use-services": "off",
294       "no-array-constructor": "off",
295       "no-caller": "off",
296       "no-cond-assign": "off",
297       "no-control-regex": "off",
298       "no-debugger": "off",
299       "no-else-return": "off",
300       "no-empty": "off",
301       "no-eval": "off",
302       "no-extra-boolean-cast": "off",
303       "no-func-assign": "off",
304       "no-global-assign": "off",
305       "no-implied-eval": "off",
306       "no-lone-blocks": "off",
307       "no-lonely-if": "off",
308       "no-nested-ternary": "off",
309       "no-new-object": "off",
310       "no-new-wrappers": "off",
311       "no-octal": "off",
312       "no-redeclare": "off",
313       "no-return-await": "off",
314       "no-restricted-globals": "off",
315       "no-self-assign": "off",
316       "no-self-compare": "off",
317       "no-sequences": "off",
318       "no-shadow": "off",
319       "no-shadow-restricted-names": "off",
320       "no-sparse-arrays": "off",
321       "no-throw-literal": "off",
322       "no-unneeded-ternary": "off",
323       "no-unreachable": "off",
324       "no-unsanitized/method": "off",
325       "no-unsanitized/property": "off",
326       "no-undef": "off",
327       "no-unused-vars": "off",
328       "no-useless-call": "off",
329       "no-useless-concat": "off",
330       "no-useless-return": "off",
331       "no-with": "off",
332     }
333   }]