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): Don't mark binding rest elements as unused in TS function overloads #5470

Merged

Conversation

camchenry
Copy link
Contributor

This implements a fix for the BindingRestElement symbol, which is currently unhandled and gets automatically marked as unused. If we happen to find that it is a child of declaration, then we will automatically allow the binding rest element.

The code for this was based on what we currently do in is_allowed_param_because_of_method:

if matches!(parent, AstKind::Function(f) if f.r#type == FunctionType::TSDeclareFunction) {

I opted not to refactor this to re-use the same code though, as I think the duplication is still incidental and the implementations could diverge in the future.

Copy link

graphite-app bot commented Sep 5, 2024

Your org has enabled the Graphite merge queue for merging into main

Add the label “0-merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix.

You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link.

@github-actions github-actions bot added the A-linter Area - Linter label Sep 5, 2024
@Boshen Boshen requested review from DonIsaac and camc314 September 5, 2024 05:16
Copy link

codspeed-hq bot commented Sep 5, 2024

CodSpeed Performance Report

Merging #5470 will not alter performance

Comparing camchenry:no-unused-vars-rest-elements-fix (621c4d4) with main (fce549e)

Summary

✅ 29 untouched benchmarks

Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

can't we just check if the funciton is TS syntax

pub fn is_typescript_syntax(&self) -> bool {
matches!(
self.r#type,
FunctionType::TSDeclareFunction | FunctionType::TSEmptyBodyFunctionExpression
) || self.body.is_none()
|| self.declare
}
and skip checking it?

@DonIsaac DonIsaac self-assigned this Sep 5, 2024
@DonIsaac DonIsaac added the C-bug Category - Bug label Sep 5, 2024
@camchenry
Copy link
Contributor Author

@camc314 Thanks for the tip. Since we are looking at whether a given symbol is allowed, I changed it to check if the binding rest element is a child of a Function. If so, if is_typescript_syntax() is true, then we will allow it, otherwise it fails. I think this makes it a lot simpler, let me know if this makes sense.

@camchenry camchenry requested a review from camc314 September 5, 2024 17:34
@camc314
Copy link
Contributor

camc314 commented Sep 5, 2024

one last comment then this looks good to me.

thanks for contributing!

Copy link
Contributor

@DonIsaac DonIsaac left a comment

Choose a reason for hiding this comment

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

See: Cam's comment thread

@DonIsaac
Copy link
Contributor

DonIsaac commented Sep 5, 2024

@camchenry run just fix to auto-fix clippy/rustfmt/etc issues.

@camc314
Copy link
Contributor

camc314 commented Sep 5, 2024

interestingly enough @DonIsaac this isn't an error 🤔 (the arg argument)

Screenshot 2024-09-05 at 20 40 55

fyi camchenry, lets not try to fix this (if we should) in this PR

@camc314 camc314 dismissed DonIsaac’s stale review September 6, 2024 07:27

changes resolved

Copy link
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

Thank you!

@camc314 camc314 merged commit ff88c1f into oxc-project:main Sep 6, 2024
23 checks passed
@oxc-bot oxc-bot mentioned this pull request Sep 7, 2024
Boshen added a commit that referenced this pull request Sep 7, 2024
## [0.9.3] - 2024-09-07

### Features

- be3a432 linter: Implement typescript/no-magic-numbers (#4745)
(Alexander S.)
- 09aa86d linter/eslint: Implement `sort-vars` rule (#5430) (Jelle van
der Waa)
- 2ec2f7d linter/eslint: Implement no-alert (#5535) (Edwin Lim)
- a786acf linter/import: Add no-dynamic-require rule (#5389) (Jelle van
der Waa)
- 4473779 linter/node: Implement no-exports-assign (#5370) (dalaoshu)
- b846432 linter/oxc: Add fixer for `erasing-op` (#5377) (camc314)
- aff2c71 linter/react: Implement `self-closing-comp` (#5415) (Jelle van
der Waa)

### Bug Fixes

- 0df1d9d ast, codegen, linter: Panics in fixers. (#5431) (rzvxa)
- cdd1a91 linter: Typescript/no-magic-numbers: remove double minus for
reporting negative bigint numbers (#5565) (Alexander S.)
- ff88c1f linter: Don't mark binding rest elements as unused in TS
function overloads (#5470) (Cam McHenry)
- 088733b linter: Handle loops in `getter-return` rule (#5517) (Cam
McHenry)
- 82c0a16 linter: `tree_shaking/no_side_effects_in_initialization`
handle JSX correctly (#5450) (overlookmotel)
- 6285a02 linter: `eslint/radix` rule correctly check for unbound
symbols (#5446) (overlookmotel)
- c8ab353 linter/tree-shaking: Align JSXMemberExpression's report
(#5548) (mysteryven)
- 5187f38 linter/tree-shaking: Detect the correct export symbol
resolution (#5467) (mysteryven)

### Performance

- 8170954 linter/react: Add should_run conditions for react rules
(#5402) (Jelle van der Waa)

### Documentation

- a540215 linter: Update docs `Examples` for linter rules (#5513)
(dalaoshu)
- 7414190 linter: Update docs `Example` for linter rules (#5479)
(heygsc)

### Refactor

- 0ac420d linter: Use meaningful names for diagnostic parameters (#5564)
(Don Isaac)
- 81a394d linter: Deduplicate code in `oxc/no-async-await` (#5549)
(DonIsaac)
- 979c16c linter: Reduce nested if statements in
eslint/no_this_before_super (#5485) (IWANABETHATGUY)
- 1d3e973 linter: Simplify `eslint/radix` rule (#5445) (overlookmotel)
- fdb8857 linter: Use "parsed pattern" in `no_div_regex` rule. (#5417)
(rzvxa)
- 2ccbd93 linter: `react/jsx_no_undef` rule `get_member_ident` do not
return Option (#5411) (overlookmotel)

### Styling

- 2a43fa4 linter: Introduce the writing style from PR #5491 and reduce
the if nesting (#5512) (dalaoshu)- d8b29e7 Add trailing line breaks to
JSON files (#5544) (overlookmotel)- 694f032 Add trailing line breaks to
`package.json` files (#5542) (overlookmotel)

### Testing

- 340b535 linter/no-unused-vars: Arrow functions in tagged templates
(#5510) (Don Isaac)
- af69393 linter/no-useless-spread: Ensure spreads on identifiers pass
(#5561) (DonIsaac)- dc92489 Add trailing line breaks to conformance
fixtures (#5541) (overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

linter: no-unused-vars false positive w/TS overload
3 participants