Skip to content

feat(analyze/js): implement noShadow - #5761

Merged
dyc3 merged 1 commit into
mainfrom
dyc3/no-shadow
Apr 30, 2025
Merged

dyc3 merged 1 commit into
mainfrom
dyc3/no-shadow

Conversation

@dyc3

@dyc3 dyc3 commented Apr 24, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR implements noShadow, which is a port of eslint's no-shadow rule.

It doesn't include any options for the time being (as usual for new rules).

closes #5346

Test Plan

Added some snapshot tests. I also briefly went through the eslint rule to pick up some edge cases that I hadn't thought about.

@github-actions github-actions Bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages A-Diagnostic Area: diagnostocis labels Apr 24, 2025
@dyc3
dyc3 marked this pull request as ready for review April 24, 2025 15:45
@dyc3
dyc3 requested review from a team April 24, 2025 15:45
@github-actions github-actions Bot added A-CLI Area: CLI A-Project Area: project labels Apr 24, 2025
@codspeed

codspeed Bot commented Apr 24, 2025 •

Copy link
Copy Markdown
Contributor

CodSpeed Performance Report

Merging #5761 will not alter performance

Comparing dyc3/no-shadow (9054a3f) with main (1af2395)

Summary

✅ 95 untouched benchmarks

@dyc3

This comment was marked as resolved.

@dyc3
dyc3 force-pushed the dyc3/no-shadow branch 2 times, most recently from 37e5887 to f324591 Compare April 25, 2025 19:23
@github-actions

github-actions Bot commented Apr 25, 2025 •

Copy link
Copy Markdown
Contributor

Parser conformance results on

js/262

Test result main count This PR count Difference
Total 50451 50451 0
Passed 49136 49136 0
Failed 1315 1315 0
Panics 0 0 0
Coverage 97.39% 97.39% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 40 40 0
Passed 37 37 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.50% 92.50% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 6647 6647 0
Passed 2229 2229 0
Failed 4418 4418 0
Panics 0 0 0
Coverage 33.53% 33.53% 0.00%

ts/babel

Test result main count This PR count Difference
Total 807 807 0
Passed 718 718 0
Failed 89 89 0
Panics 0 0 0
Coverage 88.97% 88.97% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 18698 18698 0
Passed 14346 14346 0
Failed 4352 4352 0
Panics 0 0 0
Coverage 76.72% 76.72% 0.00%

Comment thread crates/biome_js_analyze/src/lint/nursery/no_shadow.rs
Comment thread crates/biome_js_analyze/src/lint/suspicious/no_shadow_restricted_names.rs Outdated
Comment thread crates/biome_js_analyze/tests/specs/nursery/noShadow/invalid.js
Comment thread .changeset/twenty-meals-reply.md Outdated
@dyc3
dyc3 force-pushed the dyc3/no-shadow branch 2 times, most recently from 6174383 to 15b8296 Compare April 29, 2025 22:32
Comment on lines +65 to +68
RuleSource::Eslint("no-shadow"),
// uncomment when we can handle the test cases from typescript-eslint
// RuleSource::EslintTypeScript("no-shadow"),
],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have excluded the unit tests from typescript-eslint, and therefore the rule source here, because of #5822.

Comment on lines +140 to +146
if is_declaration(&binding)
&& is_declaration(&upper_binding)
&& upper_binding.syntax().text_range().start() >= binding.scope().range().end()
{
// the shadowed binding must be declared before the shadowing one
continue;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is probably the most dubious one here because I don't have a source for it. I'm not entirely sure which part of the JS spec would be relevant.

@dyc3

dyc3 commented Apr 29, 2025

Copy link
Copy Markdown
Contributor Author

I'm not sure why the windows test job is failing. Doesn't feel related to this PR.

@ematipico ematipico left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! 🚀 I think we can merge it as first phase of the implementation until we fix the sematic model for TS types. I leave the merge to you, because I'm not sure if you want to close the original issue or not

@dyc3

dyc3 commented Apr 30, 2025

Copy link
Copy Markdown
Contributor Author

I think its fine to close the issue. We can just leave the rule in nursery until the TS cases are fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Diagnostic Area: diagnostocis A-Linter Area: linter A-Project Area: project L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📎 Port no-shadow from eslint

2 participants