-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new ESLint rule: prefer-primordials #35448
Conversation
I'm +1 on this. It should be doable after #35499 |
This comment has been minimized.
This comment has been minimized.
Codecov Report
@@ Coverage Diff @@
## master #35448 +/- ##
==========================================
- Coverage 96.87% 96.40% -0.48%
==========================================
Files 212 220 +8
Lines 69641 73735 +4094
==========================================
+ Hits 67466 71085 +3619
- Misses 2175 2650 +475
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to say thanks for doing this. Definitely +1, but don't have time for a proper review at the moment. Very happy to see this!
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM based on the added unit tests and changes in lib
. I am not familiar with writing ESLint rules.
@nodejs/collaborators Could you help me with reviewing this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, let's land this! 🎉
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I added a new custom ESLint rule to fix these problems. We have a lot of replaceable codes with primordials. Accessing built-in objects is restricted by existing rule (no-restricted-globals), but accessing property in the built-in objects is not restricted right now. We manually review codes that can be replaced by primordials, but there's a lot of code that actually needs to be fixed. We have often made pull requests to replace the primordials with. Restrict accessing global built-in objects such as `Promise`. Restrict calling static methods such as `Array.from` or `Symbol.for`. Don't restrict prototype methods to prevent false-positive.
I found a new lint error while landing. I fixed the error. |
Landed in cef1444 |
I added a new custom ESLint rule to fix these problems. We have a lot of replaceable codes with primordials. Accessing built-in objects is restricted by existing rule (no-restricted-globals), but accessing property in the built-in objects is not restricted right now. We manually review codes that can be replaced by primordials, but there's a lot of code that actually needs to be fixed. We have often made pull requests to replace the primordials with. Restrict accessing global built-in objects such as `Promise`. Restrict calling static methods such as `Array.from` or `Symbol.for`. Don't restrict prototype methods to prevent false-positive. PR-URL: #35448 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ben Coe <[email protected]>
Int16Array, | ||
Int32Array, | ||
Int8Array, | ||
JSON, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON
, Math
and Reflect
don’t actually exist on primordials
, only their methods.
I’m fixing that in #36016.
Refs: nodejs#35448 Refs: nodejs#36003 Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object Co-authored-by: Antoine du Hamel <[email protected]>
Refs: #35448 Refs: #36003 Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object Co-authored-by: Antoine du Hamel <[email protected]> PR-URL: #36016 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
I added a new custom ESLint rule to fix these problems. We have a lot of replaceable codes with primordials. Accessing built-in objects is restricted by existing rule (no-restricted-globals), but accessing property in the built-in objects is not restricted right now. We manually review codes that can be replaced by primordials, but there's a lot of code that actually needs to be fixed. We have often made pull requests to replace the primordials with. Restrict accessing global built-in objects such as `Promise`. Restrict calling static methods such as `Array.from` or `Symbol.for`. Don't restrict prototype methods to prevent false-positive. PR-URL: #35448 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ben Coe <[email protected]>
Refs: #35448 Refs: #36003 Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object Co-authored-by: Antoine du Hamel <[email protected]> PR-URL: #36016 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
I added a new custom ESLint rule to fix these problems. We have a lot of replaceable codes with primordials. Accessing built-in objects is restricted by existing rule (no-restricted-globals), but accessing property in the built-in objects is not restricted right now. We manually review codes that can be replaced by primordials, but there's a lot of code that actually needs to be fixed. We have often made pull requests to replace the primordials with. Restrict accessing global built-in objects such as `Promise`. Restrict calling static methods such as `Array.from` or `Symbol.for`. Don't restrict prototype methods to prevent false-positive. PR-URL: #35448 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ben Coe <[email protected]>
I added a new custom ESLint rule to fix these problems. We have a lot of replaceable codes with primordials. Accessing built-in objects is restricted by existing rule (no-restricted-globals), but accessing property in the built-in objects is not restricted right now. We manually review codes that can be replaced by primordials, but there's a lot of code that actually needs to be fixed. We have often made pull requests to replace the primordials with. Restrict accessing global built-in objects such as `Promise`. Restrict calling static methods such as `Array.from` or `Symbol.for`. Don't restrict prototype methods to prevent false-positive. PR-URL: #35448 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ben Coe <[email protected]>
Refs: #35448 Refs: #36003 Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object Co-authored-by: Antoine du Hamel <[email protected]> PR-URL: #36016 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
I added a new custom ESLint rule to fix these problems. We have a lot of replaceable codes with primordials. Accessing built-in objects is restricted by existing rule (no-restricted-globals), but accessing property in the built-in objects is not restricted right now. We manually review codes that can be replaced by primordials, but there's a lot of code that actually needs to be fixed. We have often made pull requests to replace the primordials with. Restrict accessing global built-in objects such as `Promise`. Restrict calling static methods such as `Array.from` or `Symbol.for`. Don't restrict prototype methods to prevent false-positive. PR-URL: #35448 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Daijiro Wachi <[email protected]> Reviewed-By: Ben Coe <[email protected]>
Refs: #35448 Refs: #36003 Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object Co-authored-by: Antoine du Hamel <[email protected]> PR-URL: #36016 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Shingo Inoue <[email protected]>
Fixed #35449
Rule option
A rule option has a required key and optional keys
string
Number
,Symbol
,Array
string[]
stackTraceLimit
string
Number
(ex. If this rule find code that is usingparseInt
globally, it will reportconst { NumberParseInt } = primordials; ...
)Ignored properties of Error
I marked some of properties of Error as ignored.
Error.stackTraceLimit, Error.captureStackTrace
A lot of tests are failed when I replace these props with primordials.
Error.prepareStackTrace
View failed tests output
actual - expected
'Uncaught Error: Whoops!\n' +
' at REPL1::\n' +
' at d (REPL1::)\n' +
' at c (REPL1::)\n' +
' at b (REPL1::)\n' +
' at a (REPL1::)\n'
node:internal/main/runmain_module:17:47--->
Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:72:12)--->
Function.Module._load (node:internal/modules/cjs/loader:778:14)--->
Module.load (node:internal/modules/cjs/loader:937:32)--->
Object.Module._extensions..js (node:internal/modules/cjs/loader:1101:10)--->
Module._compile (node:internal/modules/cjs/loader:1072:30)--->
Object. (/Users/leko/ghq/github.com/Leko/node/test/parallel/test-repl-pretty-custom-stack.js:74:7)--->
Array.forEach ()--->
run (/Users/leko/ghq/github.com/Leko/node/test/parallel/test-repl-pretty-custom-stack.js:27:10)] {
generatedMessage: true,
code: 'ERR_ASSERTION',
actual: 'Uncaught Error: Whoops!\n' +
' at REPL1::\n' +
' at d (REPL1::)\n' +
' at c (REPL1::)\n' +
' at b (REPL1::)\n' +
' at a (REPL1::)\n',
expected: 'Uncaught Error: Whoops!--->\n' +
'REPL1::--->\n' +
'd (REPL1::)--->\n' +
'c (REPL1::)--->\n' +
'b (REPL1::)--->\n' +
'a (REPL1::_)\n',
operator: 'strictEqual'
}
Error.isPrototypeOf
View failed tests output
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes