.eslintrc.mjs (6713B)
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/. */ 4 5 import spidermonkeyJS from "eslint-plugin-spidermonkey-js"; 6 import mozilla from "eslint-plugin-mozilla"; 7 import globals from "globals"; 8 9 export default [ 10 { 11 plugins: { "spidermonkey-js": spidermonkeyJS }, 12 files: ["**/*.js"], 13 processor: "spidermonkey-js/processor", 14 15 rules: { 16 // This rule is not compatible with the spidermonkey-js processor, and we 17 // don't need it anyway, so turn it off. 18 "mozilla/import-globals": "off", 19 // We should fix those at some point, but we use this to detect NaNs. 20 "no-self-compare": "off", 21 "no-lonely-if": "off", 22 // Disabled until we can use let/const to fix those erorrs, and undefined 23 // names cause an exception and abort during runtime initialization. 24 "no-redeclare": "off", 25 // Disallow use of |void 0|. Instead use |undefined|. 26 "no-void": ["error", { allowAsStatement: true }], 27 // Disallow loose equality because of objects with the [[IsHTMLDDA]] 28 // internal slot, aka |document.all|, aka "objects emulating undefined". 29 eqeqeq: "error", 30 // All self-hosted code is implicitly strict mode, so there's no need to 31 // add a strict-mode directive. 32 strict: ["error", "never"], 33 // Disallow syntax not supported in self-hosted code. 34 "no-restricted-syntax": [ 35 "error", 36 { 37 selector: "ClassDeclaration", 38 message: "Class declarations are not allowed", 39 }, 40 { 41 selector: "ClassExpression", 42 message: "Class expressions are not allowed", 43 }, 44 { 45 selector: "Literal[regex]", 46 message: "Regular expression literals are not allowed", 47 }, 48 { 49 selector: "CallExpression > MemberExpression.callee", 50 message: 51 "Direct method calls are not allowed, use callFunction() or callContentFunction()", 52 }, 53 { 54 selector: "NewExpression > MemberExpression.callee", 55 message: 56 "Direct method calls are not allowed, use constructContentFunction()", 57 }, 58 { 59 selector: "YieldExpression[delegate=true]", 60 message: 61 "yield* is not allowed because it can run user-modifiable iteration code", 62 }, 63 { 64 selector: "ForOfStatement > :not(CallExpression).right", 65 message: 66 "for-of loops must use allowContentIter(), allowContentIterWith(), or allowContentIterWithNext()", 67 }, 68 { 69 selector: 70 "ForOfStatement > CallExpression.right > :not(Identifier[name='allowContentIter'], Identifier[name='allowContentIterWith'], Identifier[name='allowContentIterWithNext']).callee", 71 message: 72 "for-of loops must use allowContentIter(), allowContentIterWith(), or allowContentIterWithNext", 73 }, 74 { 75 selector: 76 "CallExpression[callee.name='TO_PROPERTY_KEY'] > :not(Identifier).arguments:first-child", 77 message: 78 "TO_PROPERTY_KEY macro must be called with a simple identifier", 79 }, 80 { 81 selector: "Identifier[name='arguments']", 82 message: 83 "'arguments' is disallowed, use ArgumentsLength(), GetArgument(n), or rest-parameters", 84 }, 85 { 86 selector: "VariableDeclaration[kind='let']", 87 message: 88 "'let' declarations are disallowed to avoid TDZ checks, use 'var' instead", 89 }, 90 { 91 selector: "VariableDeclaration[kind='const']", 92 message: 93 "'const' declarations are disallowed to avoid TDZ checks, use 'var' instead", 94 }, 95 ], 96 // Method signatures are important in builtins so disable unused argument errors. 97 "no-unused-vars": [ 98 "error", 99 { 100 args: "none", 101 caughtErrors: "none", 102 vars: "local", 103 }, 104 ], 105 }, 106 107 languageOptions: { 108 parserOptions: { 109 ecmaVersion: "latest", 110 111 // Self-hosted code defaults to strict mode. 112 ecmaFeatures: { 113 impliedStrict: true, 114 }, 115 116 // Strict mode has to be enabled separately for the Babel parser. 117 babelOptions: { 118 parserOpts: { 119 strictMode: true, 120 }, 121 }, 122 }, 123 124 sourceType: "script", 125 globals: { 126 // Disable all built-in environments. 127 ...mozilla.turnOff(globals.node), 128 ...mozilla.turnOff(globals.browser), 129 ...mozilla.turnOff(globals.builtin), 130 131 // We need to explicitly disable the default environments added from 132 // "tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js". 133 ...mozilla.turnOff(globals.es2021), 134 ...mozilla.turnOff(mozilla.environments.privileged.globals), 135 ...mozilla.turnOff(mozilla.environments.specific.globals), 136 137 // Enable SpiderMonkey's self-hosted environment. 138 ...spidermonkeyJS.environments.environment.globals, 139 140 // The bytecode compiler special-cases these identifiers. 141 ArgumentsLength: "readonly", 142 allowContentIter: "readonly", 143 allowContentIterWith: "readonly", 144 allowContentIterWithNext: "readonly", 145 callContentFunction: "readonly", 146 callFunction: "readonly", 147 constructContentFunction: "readonly", 148 DefineDataProperty: "readonly", 149 forceInterpreter: "readonly", 150 GetArgument: "readonly", 151 GetBuiltinConstructor: "readonly", 152 GetBuiltinPrototype: "readonly", 153 GetBuiltinSymbol: "readonly", 154 getPropertySuper: "readonly", 155 hasOwn: "readonly", 156 IsNullOrUndefined: "readonly", 157 IteratorClose: "readonly", 158 resumeGenerator: "readonly", 159 SetCanonicalName: "readonly", 160 SetIsInlinableLargeFunction: "readonly", 161 ToNumeric: "readonly", 162 ToString: "readonly", 163 DisposeResourcesAsync: "readonly", 164 DisposeResourcesSync: "readonly", 165 166 // We've disabled all built-in environments, which also removed 167 // `undefined` from the list of globals. Put it back because it's 168 // actually allowed in self-hosted code. 169 undefined: "readonly", 170 171 // Disable globals from stage 2/3 proposals for which we have work in 172 // progress patches. Eventually these will be part of a future ES 173 // release, in which case we can remove these extra entries. 174 AsyncIterator: "off", 175 Iterator: "off", 176 Temporal: "off", 177 }, 178 }, 179 }, 180 ];