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");
9 * Some configurations have overrides, which can't be specified within overrides,
10 * so we need to remove them.
12 function removeOverrides(config) {
14 delete config.overrides;
18 const xpcshellTestPaths = [
23 const browserTestPaths = [
24 "**/test*/**/browser/",
27 const mochitestTestPaths = [
28 "**/test*/mochitest/",
31 const chromeTestPaths = [
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.
40 "plugin:mozilla/recommended"
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.
49 "html/xml-extensions": [ ".xhtml" ]
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",
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.
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"
72 "mozilla/browser-window": true
75 // TODO: Bug 1513639. Temporarily turn off reject-importGlobalProperties
76 // due to other ESLint enabling happening in DOM.
79 "mozilla/reject-importGlobalProperties": "off",
82 // TODO: Bug 1515949. Enable no-undef for gfx/
83 "files": "gfx/layers/apz/test/mochitest/**",
88 ...removeOverrides(xpcshellTestConfig),
89 "files": xpcshellTestPaths.map(path => `${path}**`),
90 "excludedFiles": "devtools/**"
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`),
99 "no-unused-vars": ["error", {
105 ...browserTestConfig,
106 "files": browserTestPaths.map(path => `${path}**`),
107 "excludedFiles": "devtools/**"
109 ...removeOverrides(mochitestTestConfig),
110 "files": mochitestTestPaths.map(path => `${path}**`),
113 "security/manager/ssl/tests/mochitest/browser/**",
114 "testing/mochitest/**",
117 ...removeOverrides(chromeTestConfig),
118 "files": chromeTestPaths.map(path => `${path}**`),
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,
130 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
131 ...chromeTestPaths.map(path => `${path}/**/*.js`),
135 "extensions/permissions/test/**",
136 "extensions/spellcheck/**",
137 "extensions/universalchardet/tests/**",
140 "mozilla/reject-importGlobalProperties": "off",
141 "mozilla/use-default-preference-values": "off",
142 "mozilla/use-services": "off",
143 "no-array-constructor": "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",
154 "no-mixed-spaces-and-tabs": "off",
155 "no-multi-spaces": "off",
156 "no-trailing-spaces": "off",
157 "padded-blocks": "off",
160 "space-infix-ops": "off",
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",
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",
187 "no-mixed-spaces-and-tabs": "off",
188 "no-multi-spaces": "off",
189 "no-trailing-spaces": "off",
190 "padded-blocks": "off",
193 "space-before-function-paren": "off",
194 "space-infix-ops": "off",
198 "netwerk/cookie/test/browser/**",
199 "netwerk/test/browser/**",
200 "netwerk/test/mochitests/**",
201 "netwerk/test/unit*/**",
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",
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",
228 "no-throw-literal": "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",
242 "func-call-spacing": "off",
243 "generator-star-spacing": "off",
244 "key-spacing": "off",
245 "keyword-spacing": "off",
246 "no-extra-semi": "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",
254 "rest-spread-spacing": "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",
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",
282 "consistent-return": "off",
283 "dot-notation": "off",
284 "no-array-constructor": "off",
286 "no-cond-assign": "off",
287 "no-extra-boolean-cast": "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",
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",
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",
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",
332 "rest-spread-spacing": "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",