Bug 1805526 - Refactor extension.startup() permissions setup, r=robwu
[gecko.git] / toolkit / components / extensions / .eslintrc.js
blob523cd9c41abb8d16685ca7c597373235cca9cdbe
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   extends: ["plugin:mozilla/valid-jsdoc"],
10   globals: {
11     // These are defined in the WebExtension script scopes by ExtensionCommon.jsm
12     Cc: true,
13     Ci: true,
14     Cr: true,
15     Cu: true,
16     AppConstants: true,
17     ExtensionAPI: true,
18     ExtensionAPIPersistent: true,
19     ExtensionCommon: true,
20     ExtensionUtils: true,
21     extensions: true,
22     global: true,
23     require: false,
24     Services: true,
25     XPCOMUtils: true,
26   },
28   rules: {
29     // Rules from the mozilla plugin
30     "mozilla/balanced-listeners": "error",
31     "mozilla/no-aArgs": "error",
32     "mozilla/var-only-at-top-level": "error",
33     // Disable reject-importGlobalProperties because we don't want to include
34     // these in the sandbox directly as that would potentially mean the
35     // imported properties would be instatiated up-front rather than lazily.
36     "mozilla/reject-importGlobalProperties": "off",
38     // Functions are not required to consistently return something or nothing
39     "consistent-return": "off",
41     // Disallow empty statements. This will report an error for:
42     // try { something(); } catch (e) {}
43     // but will not report it for:
44     // try { something(); } catch (e) { /* Silencing the error because ...*/ }
45     // which is a valid use case.
46     "no-empty": "error",
48     // No expressions where a statement is expected
49     "no-unused-expressions": "error",
51     // No declaring variables that are never used
52     "no-unused-vars": [
53       "error",
54       {
55         args: "none",
56         vars: "all",
57         varsIgnorePattern: "^console$",
58       },
59     ],
61     // No using variables before defined
62     "no-use-before-define": "error",
64     // Disallow using variables outside the blocks they are defined (especially
65     // since only let and const are used, see "no-var").
66     "block-scoped-var": "error",
68     // Warn about cyclomatic complexity in functions.
69     complexity: "error",
71     // Don't warn for inconsistent naming when capturing this (not so important
72     // with auto-binding fat arrow functions).
73     // "consistent-this": ["error", "self"],
75     // Don't require a default case in switch statements. Avoid being forced to
76     // add a bogus default when you know all possible cases are handled.
77     "default-case": "off",
79     // Allow using == instead of ===, in the interest of landing something since
80     // the devtools codebase is split on convention here.
81     eqeqeq: "off",
83     // Don't require function expressions to have a name.
84     // This makes the code more verbose and hard to read. Our engine already
85     // does a fantastic job assigning a name to the function, which includes
86     // the enclosing function name, and worst case you have a line number that
87     // you can just look up.
88     "func-names": "off",
90     // Allow use of function declarations and expressions.
91     "func-style": "off",
93     // Maximum depth callbacks can be nested.
94     "max-nested-callbacks": ["error", 4],
96     // Don't limit the number of parameters that can be used in a function.
97     "max-params": "off",
99     // Don't limit the maximum number of statement allowed in a function. We
100     // already have the complexity rule that's a better measurement.
101     "max-statements": "off",
103     // Don't require a capital letter for constructors, only check if all new
104     // operators are followed by a capital letter. Don't warn when capitalized
105     // functions are used without the new operator.
106     "new-cap": ["off", { capIsNew: false }],
108     // Allow use of bitwise operators.
109     "no-bitwise": "off",
111     // Disallow using the console API.
112     "no-console": "error",
114     // Allow using constant expressions in conditions like while (true)
115     "no-constant-condition": "off",
117     // Allow use of the continue statement.
118     "no-continue": "off",
120     // Allow division operators explicitly at beginning of regular expression.
121     "no-div-regex": "off",
123     // Disallow adding to native types
124     "no-extend-native": "error",
126     // Disallow fallthrough of case statements, except if there is a comment.
127     "no-fallthrough": "error",
129     // Allow comments inline after code.
130     "no-inline-comments": "off",
132     // Disallow use of labels for anything other then loops and switches.
133     "no-labels": ["error", { allowLoop: true }],
135     // Disallow use of multiline strings (use template strings instead).
136     "no-multi-str": "error",
138     // Allow reassignment of function parameters.
139     "no-param-reassign": "off",
141     // Allow string concatenation with __dirname and __filename (not a node env).
142     "no-path-concat": "off",
144     // Allow use of unary operators, ++ and --.
145     "no-plusplus": "off",
147     // Allow using process.env (not a node environment).
148     "no-process-env": "off",
150     // Allow using process.exit (not a node environment).
151     "no-process-exit": "off",
153     // Disallow usage of __proto__ property.
154     "no-proto": "error",
156     // Don't restrict usage of specified node modules (not a node environment).
157     "no-restricted-modules": "off",
159     // Disallow use of assignment in return statement. It is preferable for a
160     // single line of code to have only one easily predictable effect.
161     "no-return-assign": "error",
163     // Don't warn about declaration of variables already declared in the outer scope.
164     "no-shadow": "off",
166     // Allow use of synchronous methods (not a node environment).
167     "no-sync": "off",
169     // Allow the use of ternary operators.
170     "no-ternary": "off",
172     // Allow dangling underscores in identifiers (for privates).
173     "no-underscore-dangle": "off",
175     // Allow use of undefined variable.
176     "no-undefined": "off",
178     // We use var-only-at-top-level instead of no-var as we allow top level
179     // vars.
180     "no-var": "off",
182     // Allow using TODO/FIXME comments.
183     "no-warning-comments": "off",
185     // Don't require method and property shorthand syntax for object literals.
186     // We use this in the code a lot, but not consistently, and this seems more
187     // like something to check at code review time.
188     "object-shorthand": "off",
190     // Allow more than one variable declaration per function.
191     "one-var": "off",
193     // Require use of the second argument for parseInt().
194     radix: "error",
196     // Don't require to sort variables within the same declaration block.
197     // Anyway, one-var is disabled.
198     "sort-vars": "off",
200     // Require "use strict" to be defined globally in the script.
201     strict: ["error", "global"],
203     // Allow vars to be declared anywhere in the scope.
204     "vars-on-top": "off",
206     // Disallow Yoda conditions (where literal value comes first).
207     yoda: "error",
209     // Disallow function or variable declarations in nested blocks
210     "no-inner-declarations": "error",
212     // Disallow labels that share a name with a variable
213     "no-label-var": "error",
214   },
216   overrides: [
217     {
218       files: "test/xpcshell/head*.js",
219       rules: {
220         "no-unused-vars": [
221           "error",
222           {
223             args: "none",
224             vars: "local",
225           },
226         ],
227       },
228     },
229   ],