Bug 1550197 [wpt PR 16330] - HTML: ensure BarProps are visible for noopener/noreferre...
[gecko.git] / .eslintrc.js
blob509e7d9b5125cf1093819a0d6d4eb19b73450fb2
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   // The html plugin is enabled via a command line option on eslint. To avoid
46   // bad interactions with the xml preprocessor in eslint-plugin-mozilla, we
47   // turn off processing of the html plugin for .xml files.
48   "settings": {
49     "html/xml-extensions": [ ".xhtml" ]
50   },
52   "overrides": [{
53     // eslint-plugin-html handles eol-last slightly different - it applies to
54     // each set of script tags, so we turn it off here.
55     "files": "**/*.*html",
56     "rules": {
57       "eol-last": "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 1513639. Temporarily turn off reject-importGlobalProperties
76     // due to other ESLint enabling happening in DOM.
77     "files": "dom/**",
78     "rules": {
79       "mozilla/reject-importGlobalProperties": "off",
80     }
81   }, {
82     // TODO: Bug 1515949. Enable no-undef for gfx/
83     "files": "gfx/layers/apz/test/mochitest/**",
84     "rules": {
85       "no-undef": "off",
86     }
87   }, {
88     ...removeOverrides(xpcshellTestConfig),
89     "files": xpcshellTestPaths.map(path => `${path}**`),
90     "excludedFiles": "devtools/**"
91   }, {
92     // If it is an xpcshell head file, we turn off global unused variable checks, as it
93     // would require searching the other test files to know if they are used or not.
94     // This would be expensive and slow, and it isn't worth it for head files.
95     // We could get developers to declare as exported, but that doesn't seem worth it.
96     "files": xpcshellTestPaths.map(path => `${path}head*.js`),
98     "rules": {
99       "no-unused-vars": ["error", {
100         "args": "none",
101         "vars": "local",
102       }],
103     },
104   }, {
105     ...browserTestConfig,
106     "files": browserTestPaths.map(path => `${path}**`),
107     "excludedFiles": "devtools/**"
108   }, {
109     ...removeOverrides(mochitestTestConfig),
110     "files": mochitestTestPaths.map(path => `${path}**`),
111     "excludedFiles": [
112       "devtools/**",
113       "security/manager/ssl/tests/mochitest/browser/**",
114       "testing/mochitest/**",
115     ],
116   }, {
117     ...removeOverrides(chromeTestConfig),
118     "files": chromeTestPaths.map(path => `${path}**`),
119     "excludedFiles": [
120       "devtools/**",
121     ],
122   }, {
123     "env": {
124       // Ideally we wouldn't be using the simpletest env here, but our uses of
125       // js files mean we pick up everything from the global scope, which could
126       // be any one of a number of html files. So we just allow the basics...
127       "mozilla/simpletest": true,
128     },
129     "files": [
130       ...mochitestTestPaths.map(path => `${path}/**/*.js`),
131       ...chromeTestPaths.map(path => `${path}/**/*.js`),
132     ],
133   }, {
134     "files": [
135       "extensions/permissions/test/**",
136       "extensions/spellcheck/**",
137       "extensions/universalchardet/tests/**",
138     ],
139     "rules": {
140       "mozilla/reject-importGlobalProperties": "off",
141       "mozilla/use-default-preference-values": "off",
142       "mozilla/use-services": "off",
143       "no-array-constructor": "off",
144       "no-undef": "off",
145       "no-unused-vars": "off",
146       "no-redeclare": "off",
147       "no-global-assign": "off",
149       // Not enabling the rules below for now pending prettier roll-out.
150       "brace-style": "off",
151       "comma-dangle": "off",
152       "linebreak-style": "off",
153       "no-tabs": "off",
154       "no-mixed-spaces-and-tabs": "off",
155       "no-multi-spaces": "off",
156       "no-trailing-spaces": "off",
157       "padded-blocks": "off",
158       "quotes": "off",
159       "semi": "off",
160       "space-infix-ops": "off",
161     }
162   }, {
163     "files": [
164       "image/**",
165     ],
166     "rules": {
167       "mozilla/consistent-if-bracing": "off",
168       "mozilla/use-chromeutils-generateqi": "off",
169       "mozilla/use-services": "off",
170       "no-array-constructor": "off",
171       "no-implied-eval": "off",
172       "no-redeclare": "off",
173       "no-self-assign": "off",
174       "no-throw-literal": "off",
175       "no-undef": "off",
176       "no-unneeded-ternary": "off",
177       "no-unused-vars": "off",
179       // Not enabling the rules below for now pending prettier roll-out.
180       "brace-style": "off",
181       "comma-dangle": "off",
182       "comma-spacing": "off",
183       "key-spacing": "off",
184       "keyword-spacing": "off",
185       "no-extra-semi": "off",
186       "no-tabs": "off",
187       "no-mixed-spaces-and-tabs": "off",
188       "no-multi-spaces": "off",
189       "no-trailing-spaces": "off",
190       "padded-blocks": "off",
191       "quotes": "off",
192       "semi": "off",
193       "space-before-function-paren": "off",
194       "space-infix-ops": "off",
195     }
196   }, {
197     "files": [
198       "netwerk/cookie/test/browser/**",
199       "netwerk/test/browser/**",
200       "netwerk/test/mochitests/**",
201       "netwerk/test/unit*/**",
202     ],
203     "rules": {
204       "object-shorthand": "off",
205       "mozilla/consistent-if-bracing": "off",
206       "mozilla/reject-importGlobalProperties": "off",
207       "mozilla/no-arbitrary-setTimeout": "off",
208       "mozilla/no-define-cc-etc": "off",
209       "mozilla/no-useless-parameters": "off",
210       "mozilla/no-useless-run-test": "off",
211       "mozilla/use-chromeutils-generateqi": "off",
212       "mozilla/use-chromeutils-import": "off",
213       "mozilla/use-default-preference-values": "off",
214       "mozilla/use-services": "off",
215       "consistent-return": "off",
216       "no-array-constructor": "off",
217       "no-extra-boolean-cast": "off",
218       "no-eval": "off",
219       "no-else-return": "off",
220       "no-global-assign": "off",
221       "no-lonely-if": "off",
222       "no-nested-ternary": "off",
223       "no-new-wrappers": "off",
224       "no-redeclare": "off",
225       "no-return-await": "off",
226       "no-sequences": "off",
227       "no-shadow": "off",
228       "no-throw-literal": "off",
229       "no-undef": "off",
230       "no-unreachable": "off",
231       "no-unused-vars": "off",
232       "no-useless-return": "off",
234       // Not enabling the rules below for now pending prettier roll-out.
235       "arrow-spacing": "off",
236       "block-spacing": "off",
237       "brace-style": "off",
238       "comma-dangle": "off",
239       "comma-spacing": "off",
240       "comma-style": "off",
241       "eol-last": "off",
242       "func-call-spacing": "off",
243       "generator-star-spacing": "off",
244       "key-spacing": "off",
245       "keyword-spacing": "off",
246       "no-extra-semi": "off",
247       "no-tabs": "off",
248       "no-mixed-spaces-and-tabs": "off",
249       "no-multi-spaces": "off",
250       "no-trailing-spaces": "off",
251       "no-whitespace-before-property": "off",
252       "padded-blocks": "off",
253       "quotes": "off",
254       "rest-spread-spacing": "off",
255       "semi": "off",
256       "space-before-blocks": "off",
257       "space-before-function-paren": "off",
258       "space-infix-ops": "off",
259       "space-unary-ops": "off",
260       "spaced-comment": "off",
261     }
262   }, {
263     "files": [
264       "layout/**",
265     ],
266     "rules": {
267       "object-shorthand": "off",
268       "mozilla/avoid-removeChild": "off",
269       "mozilla/consistent-if-bracing": "off",
270       "mozilla/reject-importGlobalProperties": "off",
271       "mozilla/no-arbitrary-setTimeout": "off",
272       "mozilla/no-define-cc-etc": "off",
273       "mozilla/no-useless-parameters": "off",
274       "mozilla/no-useless-run-test": "off",
275       "mozilla/use-chromeutils-generateqi": "off",
276       "mozilla/use-chromeutils-import": "off",
277       "mozilla/use-default-preference-values": "off",
278       "mozilla/use-includes-instead-of-indexOf": "off",
279       "mozilla/use-services": "off",
280       "mozilla/use-ownerGlobal": "off",
281       "complexity": "off",
282       "consistent-return": "off",
283       "dot-notation": "off",
284       "no-array-constructor": "off",
285       "no-caller": "off",
286       "no-cond-assign": "off",
287       "no-extra-boolean-cast": "off",
288       "no-eval": "off",
289       "no-else-return": "off",
290       "no-func-assign": "off",
291       "no-global-assign": "off",
292       "no-implied-eval": "off",
293       "no-lonely-if": "off",
294       "no-nested-ternary": "off",
295       "no-new-wrappers": "off",
296       "no-redeclare": "off",
297       "no-restricted-globals": "off",
298       "no-return-await": "off",
299       "no-sequences": "off",
300       "no-throw-literal": "off",
301       "no-useless-concat": "off",
302       "no-undef": "off",
303       "no-unreachable": "off",
304       "no-unsanitized/method": "off",
305       "no-unsanitized/property": "off",
306       "no-unsafe-negation": "off",
307       "no-unused-vars": "off",
308       "no-useless-return": "off",
310       // Not enabling the rules below for now pending prettier roll-out.
311       "arrow-spacing": "off",
312       "block-spacing": "off",
313       "brace-style": "off",
314       "comma-dangle": "off",
315       "comma-spacing": "off",
316       "comma-style": "off",
317       "eol-last": "off",
318       "func-call-spacing": "off",
319       "generator-star-spacing": "off",
320       "linebreak-style": "off",
321       "key-spacing": "off",
322       "keyword-spacing": "off",
323       "no-extra-semi": "off",
324       "no-tabs": "off",
325       "no-mixed-spaces-and-tabs": "off",
326       "no-multi-spaces": "off",
327       "no-trailing-spaces": "off",
328       "no-unexpected-multiline": "off",
329       "no-whitespace-before-property": "off",
330       "padded-blocks": "off",
331       "quotes": "off",
332       "rest-spread-spacing": "off",
333       "semi": "off",
334       "space-before-blocks": "off",
335       "space-before-function-paren": "off",
336       "space-infix-ops": "off",
337       "space-unary-ops": "off",
338       "spaced-comment": "off",
339     }
340   }]