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): support bind function case for compatibility with promise/no-return-wrap #7232

Merged
merged 7 commits into from
Nov 14, 2024

Conversation

no-yan
Copy link
Contributor

@no-yan no-yan commented Nov 10, 2024

part of #4655

Summary

Logic has been added to handle bind functions, unifying the implementations of unicorn/no-useless-promise-resolve-reject and promise/no-return-wrap.
This enables detection of the following code:

foo().then((function() { return Promise.resolve(4) }).bind(this))

Merging this PR will allow this rule to pass all test cases of promise/no-return-wrap without options. Additionally, merging #7274 will ensure that all test cases are passed.

Copy link

graphite-app bot commented Nov 10, 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 A-linter Area - Linter C-enhancement Category - New feature or request labels Nov 10, 2024
Copy link

codspeed-hq bot commented Nov 10, 2024

CodSpeed Performance Report

Merging #7232 will not alter performance

Comparing no-yan:feat/no-return-wrap (4d37d31) with main (10cdce9)

Summary

✅ 30 untouched benchmarks

Copy link
Collaborator

@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.

is this the same as

declare_oxc_lint!(
/// ### What it does
///
/// Disallows returning values wrapped in `Promise.resolve` or `Promise.reject` in an async function or a `Promise#then`/`catch`/`finally` callback.
///
/// ### Why is this bad?
///
/// Wrapping a return value in `Promise.resolve` in an async function or a `Promise#then`/`catch`/`finally` callback is unnecessary as all return values in async functions and promise callback functions are already wrapped in a `Promise`. Similarly, returning an error wrapped in `Promise.reject` is equivalent to simply `throw`ing the error. This is the same for `yield`ing in async generators as well.
///
/// ### Examples
///
/// Examples of **incorrect** code for this rule:
/// ```javascript
/// async () => Promise.resolve(bar);
/// ```
///
/// Examples of **correct** code for this rule:
/// ```javascript
/// async () => bar;
/// ```
NoUselessPromiseResolveReject,
pedantic,
fix
);
?

@no-yan
Copy link
Contributor Author

no-yan commented Nov 11, 2024

is this the same as no_useless_promise_resolve_reject.rs?

Good point!
I’ll migrate the test cases to the unicorn rule tomorrow and check if everything works as expected.
Since this rule includes an option to allow reject, we may need to add a setting on the unicorn side to unify the implementation.

@no-yan no-yan marked this pull request as draft November 12, 2024 03:47
@no-yan no-yan changed the title feat(linter): add promise/no-return-wrap feat(linter): add bind function case for compatibility with promise/no-return-wrap Nov 13, 2024
@no-yan no-yan marked this pull request as ready for review November 13, 2024 18:00
@no-yan no-yan requested a review from camc314 November 13, 2024 18:00
@no-yan no-yan changed the title feat(linter): add bind function case for compatibility with promise/no-return-wrap feat(linter): support bind function case for compatibility with promise/no-return-wrap Nov 13, 2024
Copy link
Collaborator

@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!

@Boshen Boshen merged commit 755a31b into oxc-project:main Nov 14, 2024
29 checks passed
camc314 pushed a commit that referenced this pull request Nov 14, 2024
Dunqing pushed a commit that referenced this pull request Nov 17, 2024
…ise/no-return-wrap` (#7232)

part of #4655

### Summary

Logic has been added to handle bind functions, unifying the
implementations of `unicorn/no-useless-promise-resolve-reject` and
`promise/no-return-wrap`.
This enables detection of the following code:

```javascript
foo().then((function() { return Promise.resolve(4) }).bind(this))
```

Merging this PR will allow this rule to pass all test cases of
promise/no-return-wrap without options. Additionally, merging #7274 will
ensure that all test cases are passed.
Dunqing pushed a commit that referenced this pull request Nov 17, 2024
Dunqing pushed a commit that referenced this pull request Nov 18, 2024
…ise/no-return-wrap` (#7232)

part of #4655

### Summary

Logic has been added to handle bind functions, unifying the
implementations of `unicorn/no-useless-promise-resolve-reject` and
`promise/no-return-wrap`.
This enables detection of the following code:

```javascript
foo().then((function() { return Promise.resolve(4) }).bind(this))
```

Merging this PR will allow this rule to pass all test cases of
promise/no-return-wrap without options. Additionally, merging #7274 will
ensure that all test cases are passed.
Dunqing pushed a commit that referenced this pull request Nov 18, 2024
Dunqing pushed a commit that referenced this pull request Nov 18, 2024
…ise/no-return-wrap` (#7232)

part of #4655

### Summary

Logic has been added to handle bind functions, unifying the
implementations of `unicorn/no-useless-promise-resolve-reject` and
`promise/no-return-wrap`.
This enables detection of the following code:

```javascript
foo().then((function() { return Promise.resolve(4) }).bind(this))
```

Merging this PR will allow this rule to pass all test cases of
promise/no-return-wrap without options. Additionally, merging #7274 will
ensure that all test cases are passed.
Dunqing pushed a commit that referenced this pull request Nov 18, 2024
Boshen added a commit that referenced this pull request Nov 20, 2024
## [0.12.0] - 2024-11-20

- 20d9080 linter: [**BREAKING**] Override plugins array when passed in
config file (#7303) (camchenry)

### Features

- 1d9f528 linter: Implement `unicorn/prefer-string-raw` lint rule
(#7335) (Ryan Walker)
- d445e0f linter: Implement `unicorn/consistent-existence-index-check`
(#7262) (Ryan Walker)
- 01ddf37 linter: Add `allowReject` option to
`no-useless-promise-resolve-reject` (#7274) (no-yan)
- 755a31b linter: Support bind function case for compatibility with
`promise/no-return-wrap` (#7232) (no-yan)
- 428770e linter: Add `import/no-namespace` rule (#7229) (Dmitry
Zakharov)
- 9c91151 linter: Implement typescript/no-empty-object-type (#6977)
(Orenbek)
- 2268a0e linter: Support `overrides` config field (#6974) (DonIsaac)
- 3dcac1a linter: React/exhaustive-deps (#7151) (camc314)
- d3a0119 oxlint: Add `cwd` property to `LintRunner` (#7352) (Alexander
S.)

### Bug Fixes

- ba0b2ff editor: Reload workspace configuration after change (#7302)
(Alexander S.)
- bc0e72c linter: Handle user variables correctly for import/no_commonjs
(#7316) (Dmitry Zakharov)
- bf839c1 linter: False positive in `jest/expect-expect` (#7341)
(dalaoshu)
- ff2a1d4 linter: Move `exhaustive-deps` to `react` (#7251) (camc314)
- df5c535 linter: Revert unmatched rule error (#7257) (Cameron A
McHenry)
- c4ed230 linter: Fix false positive in eslint/no-cond-assign (#7241)
(camc314)
- ef847da linter: False positive in `jsx-a11y/iframe-has-title` (#7253)
(dalaoshu)
- 62b6327 linter: React/exhaustive-deps update span for unknown deps
diagnostic (#7249) (camc314)

### Documentation

- 4c124a8 editor/vscode: Update VS Code readme with installation
instructions and available features (#7306) (Nicholas Rayburn)

### Refactor

- c6a4868 linter: Temporarily remove unknown rules checking (#7260)
(camchenry)

### Testing

- 5190b7f editor: Add test setup (#7361) (Alexander S.)

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-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants