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

feat(linter): eslint/no-else-return #4305

Merged
merged 24 commits into from
Oct 1, 2024

Conversation

poyoho
Copy link
Contributor

@poyoho poyoho commented Jul 16, 2024

No description provided.

@github-actions github-actions bot added the A-linter Area - Linter label Jul 16, 2024
Copy link

graphite-app bot commented Jul 16, 2024

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

Add the label “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.

@poyoho poyoho changed the title WIP: feat: no else return WIP: feat: eslint/no-else-return Jul 20, 2024
@poyoho poyoho changed the title WIP: feat: eslint/no-else-return feat: eslint/no-else-return Jul 20, 2024
@poyoho poyoho marked this pull request as ready for review July 20, 2024 08:17
Copy link

codspeed-hq bot commented Jul 20, 2024

CodSpeed Performance Report

Merging #4305 will not alter performance

Comparing poyoho:feat/no-else-return (b301068) with main (a949ecb)

Summary

✅ 29 untouched benchmarks

@rzvxa
Copy link
Contributor

rzvxa commented Jul 20, 2024

Hi, First off thanks for your contribution😍

I have some thoughts on this, I know the eslint rule is implemented in the same way you've implemented this one. But the performance isn't so great with this approach.
That's why I was thinking maybe we can use the control flow graph for this purpose instead. But that would require a major change in what you've already done.

So before going with that - or ruling it out - is it possible for you to do these 2 experiments to see the benchmark for it?

  1. running the rule on return statements and going up to see if we are in an if statement or not(which IMHO I think wouldn't improve the performance or even worse it might degrade it further)
  2. running the rule on node.is_function_likes and check they contain an appropriate if statement to lint(+ checking the top-level ifs with return)

@mysteryven @DonIsaac Do you guys want to chime in?

Side note: It seems like this PR still is a work in progress, It would be better if you keep a WIP PR as Draft and only mark it for review when it is ready to be reviewed and merged.

@poyoho
Copy link
Contributor Author

poyoho commented Jul 20, 2024

I tinker repeatedly executing always_return on the same if_stmt to make the performace bad. may be I can save the if_stmt the result of always_return the reduce run this function?

As you said, use the node.is_function_like reduce the Rule::run function exec, and cache the alway_returns(if_stmt) run result.

@poyoho poyoho changed the title feat: eslint/no-else-return feat(linter): eslint/no-else-return Jul 23, 2024
@DonIsaac
Copy link
Contributor

hey @poyoho 👋 thanks so much for your PR! Do you need some help getting this PR over the finish line?

@poyoho
Copy link
Contributor Author

poyoho commented Aug 5, 2024

I will try again

@DonIsaac
Copy link
Contributor

👏 👏 👏

@poyoho
Copy link
Contributor Author

poyoho commented Aug 11, 2024

Do you know how to fix CI / Test (ubuntu-latest) and CI / Test (macos-14) @DonIsaac

@DonIsaac
Copy link
Contributor

You need to specify a fix kind in declare_oxc_lint. Check out other rules for examples.

@DonIsaac DonIsaac merged commit a089e19 into oxc-project:main Oct 1, 2024
27 checks passed
@DonIsaac
Copy link
Contributor

DonIsaac commented Oct 1, 2024

🎉🎉🎉

@poyoho poyoho deleted the feat/no-else-return branch October 2, 2024 14:51
This was referenced Oct 7, 2024
Boshen added a commit that referenced this pull request Oct 8, 2024
## [0.9.10] - 2024-10-07

### Features

- f272137 editors/vscode: Clear diagnostics on file deletion (#6326)
(dalaoshu)
- 1a5f293 editors/vscode: Update VSCode extention to use project's
language server (#6132) (dalaoshu)
- 376cc09 linter: Implement `no-throw-literal` (#6144) (dalaoshu)
- 5957214 linter: Allow fixing in files with source offsets (#6197)
(camchenry)
- a089e19 linter: Eslint/no-else-return (#4305) (yoho)
- 183739f linter: Implement prefer-await-to-callbacks (#6153) (dalaoshu)
- ae539af linter: Implement no-return-assign (#6108) (Radu Baston)

### Bug Fixes

- 9e9808b linter: Fix regression when parsing ts in vue files (#6336)
(Boshen)
- 93c6db6 linter: Improve docs and diagnostics message for
no-else-return (#6327) (DonIsaac)
- e0a3378 linter: Correct false positive in
`unicorn/prefer-string-replace-all` (#6263) (H11)
- ea28ee9 linter: Improve the fixer of `prefer-namespace-keyword`
(#6230) (dalaoshu)
- f6a3450 linter: Get correct source offsets for astro files (#6196)
(camchenry)
- be0030c linter: Allow whitespace control characters in
`no-control-regex` (#6140) (camchenry)
- e7e8ead linter: False positive in `no-return-assign` (#6128)
(DonIsaac)

### Performance

- ac0a82a linter: Reuse allocator when there are multiple source texts
(#6337) (Boshen)
- 50a0029 linter: Do not concat vec in `no-useless-length-check` (#6276)
(camchenry)

### Documentation

- 7ca70dd linter: Add docs for `ContextHost` and `LintContext` (#6272)
(camchenry)
- a949ecb linter: Improve docs for `eslint/getter-return` (#6229)
(DonIsaac)
- 14ba263 linter: Improve docs for `eslint-plugin-import` rules (#6131)
(dalaoshu)

### Refactor

- 642725c linter: Rename vars from `ast_node_id` to `node_id` (#6305)
(overlookmotel)
- 8413175 linter: Move shared function from utils to rule (#6127)
(dalaoshu)
- ba9c372 linter: Make jest/vitest rule mapping more clear (#6273)
(camchenry)
- 82b8f21 linter: Add schemars and serde traits to AllowWarnDeny and
RuleCategories (#6119) (DonIsaac)
- ea908f7 linter: Consolidate file loading logic (#6130) (DonIsaac)
- db751f0 linter: Use regexp AST visitor in `no-control-regex` (#6129)
(camchenry)
- 3aa7e42 linter: Use RegExp AST visitor for `no-hex-escape` (#6117)
(camchenry)
- 9d5b44a linter: Use regex visitor in `no-regex-spaces` (#6063)
(camchenry)
- 0d44cf7 linter: Use regex visitor in `no-useless-escape` (#6062)
(camchenry)
- eeb8873 linter: Use regex visitor in `no-empty-character-class`
(#6058) (camchenry)

### Testing

- d883562 linter: Invalid `eslint/no-unused-vars` options (#6228)
(DonIsaac)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants