Enable "no-undef" ESLint rule for self-hosted code
Categories
(Core :: JavaScript Engine, task, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox105 | --- | fixed |
People
(Reporter: anba, Assigned: anba)
References
Details
Attachments
(5 files)
Misspelled variable names in self-hosted code currently lead to assertion errors, but only when the relevant code is actually executed. We can improve this situation for ESLint capable editors [1] by providing an ESLint plugin which determines all self-hosted global variables.
[1] Or when manually executing ./mach lint js/src/builtin/
.
Assignee | ||
Comment 1•8 months ago
|
||
Adds a simple ESLint plugin for custom environments.
The plugin has a single exported value named globals
, which is an object with
keys for all globally available self-hosted identifiers. All self-hosted values
are read-only, so we set all properties of globals
to "readonly"
.
BytecodeEmitter special identifiers are added to the .eslintrc.js
file,
because that keeps them closer to the SpiderMonkey source tree when compared
to "tools/lint/eslint/eslint-plugin-spidermonkey-js".
Also see:
- tools/lint/eslint/eslint-plugin-mozilla/lib/environments/
- https://eslint.org/docs/latest/user-guide/configuring/language-options
Assignee | ||
Comment 2•8 months ago
|
||
Enable the "no-undef" ESLint rule for self-hosted code.
The plugin from part 1 can't discover two special cases:
- Dynamically generated RegExp functions.
- The inner
#define
inendOfUnicodeExtensions
.
Add /* global <name> */
comments to declare these names as global identifiers.
HYPHEN
isn't really a global variable, part 5 will clean this up.
Depends on D153337
Assignee | ||
Comment 3•8 months ago
|
||
Standard global identifiers aren't available in self-hosted code. Let's
undefine them, so ESLint-capable editors will warn when they're used.
It seems that names must be undeclared in ".eslintrc.js" files, because any
attempts to undeclare them in the ESLint environment plugin from part 1 didn't
work out.
The Mozilla ESLint plugin enables the "mozilla/privileged" environment by
default, see "tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js".
We don't want it to be enabled for self-hosted code.
Depends on D153338
Assignee | ||
Comment 4•8 months ago
|
||
Self-hosted code is always strict-mode, but ESLint doesn't know about that.
Depends on D153339
Assignee | ||
Comment 5•8 months ago
|
||
charCodeAt
was faster than indexed string lookups when this function was
originally written (bug 1440315). After bug 813836 there isn't anymore any
performance difference, so we might as well use the simpler code.
Depends on D153340
Updated•8 months ago
|
Pushed by andre.bargull@gmail.com: https://hg.mozilla.org/integration/autoland/rev/24470be9cddc Part 1: Add self-hosted code environment plugin. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/405f2f052ffb Part 2: Warn about undeclared variables in self-hosted code. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/aec7a500c04e Part 3: Undefine standard built-ins in self-hosted code. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/9fe496797601 Part 4: Enable strict-mode by default for eslint. r=tcampbell https://hg.mozilla.org/integration/autoland/rev/64beab0dc780 Part 5: Use simple string comparison in endOfUnicodeExtensions. r=tcampbell
Comment 7•8 months ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/24470be9cddc
https://hg.mozilla.org/mozilla-central/rev/405f2f052ffb
https://hg.mozilla.org/mozilla-central/rev/aec7a500c04e
https://hg.mozilla.org/mozilla-central/rev/9fe496797601
https://hg.mozilla.org/mozilla-central/rev/64beab0dc780
Description
•