Skip to content
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

fix(linter): eslint/radix rule correctly check for unbound symbols #5446

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/oxc_linter/src/rules/eslint/radix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Rule for Radix {
match call_expr.callee.without_parenthesized() {
Expression::Identifier(ident) => {
if ident.name == "parseInt"
&& ctx.symbols().get_symbol_id_from_name("parseInt").is_none()
&& ctx.symbols().is_global_reference(ident.reference_id().unwrap())
Boshen marked this conversation as resolved.
Show resolved Hide resolved
{
Self::check_arguments(self, call_expr, ctx);
}
Expand All @@ -81,7 +81,7 @@ impl Rule for Radix {
{
if ident.name == "Number"
&& member_expr.property.name == "parseInt"
&& ctx.symbols().get_symbol_id_from_name("Number").is_none()
&& ctx.symbols().is_global_reference(ident.reference_id().unwrap())
{
Self::check_arguments(self, call_expr, ctx);
}
Expand All @@ -92,7 +92,7 @@ impl Rule for Radix {
if let Expression::Identifier(ident) = member_expr.object() {
if ident.name == "Number"
&& member_expr.static_property_name() == Some("parseInt")
&& ctx.symbols().get_symbol_id_from_name("Number").is_none()
&& ctx.symbols().is_global_reference(ident.reference_id().unwrap())
{
Self::check_arguments(self, call_expr, ctx);
}
Expand Down Expand Up @@ -224,6 +224,9 @@ fn test() {
(r#"Number?.parseInt("10");"#, None),
(r#"(Number?.parseInt)("10");"#, None),
("function *f(){ yield(Number).parseInt() }", None), // { "ecmaVersion": 6 },
("{ let parseInt; } parseInt();", None),
("{ let Number; } Number.parseInt();", None),
("{ let Number; } (Number?.parseInt)();", None),
];

Tester::new(Radix::NAME, pass, fail).test_and_snapshot();
Expand Down
18 changes: 18 additions & 0 deletions crates/oxc_linter/src/snapshots/radix.snap
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,21 @@ source: crates/oxc_linter/src/tester.rs
1 │ function *f(){ yield(Number).parseInt() }
· ───────────────────
╰────

⚠ eslint(radix): Missing parameters.
╭─[radix.tsx:1:19]
1 │ { let parseInt; } parseInt();
· ──────────
╰────

⚠ eslint(radix): Missing parameters.
╭─[radix.tsx:1:17]
1 │ { let Number; } Number.parseInt();
· ─────────────────
╰────

⚠ eslint(radix): Missing parameters.
╭─[radix.tsx:1:17]
1 │ { let Number; } (Number?.parseInt)();
· ────────────────────
╰────