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