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(eslint-plugin): [unified-signatures] no parameters function #6940

Conversation

u-abyss
Copy link
Contributor

@u-abyss u-abyss commented Apr 20, 2023

PR Checklist

Overview

Add guard clause because b.params[i].type is not accessible when comparing to a function with no parameters

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @oxyu8!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@netlify
Copy link

netlify bot commented Apr 20, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit ad154ff
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/644600dba3b21c0008a71a6c
😎 Deploy Preview https://deploy-preview-6940--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented Apr 20, 2023

Codecov Report

Merging #6940 (47286f7) into main (05ed60e) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 47286f7 differs from pull request most recent head ad154ff. Consider uploading reports for the commit ad154ff to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6940   +/-   ##
=======================================
  Coverage   87.37%   87.37%           
=======================================
  Files         386      386           
  Lines       13194    13194           
  Branches     3867     3867           
=======================================
  Hits        11528    11528           
  Misses       1300     1300           
  Partials      366      366           
Flag Coverage Δ
unittest 87.37% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ages/eslint-plugin/src/rules/unified-signatures.ts 92.05% <100.00%> (ø)

@bradzacher bradzacher added the bug Something isn't working label Apr 20, 2023
@bradzacher bradzacher changed the title fix: [unified-signatures] no parameters function fix(eslint-plugin): [unified-signatures] no parameters function Apr 20, 2023
Comment on lines 216 to 218
if (b.params.length === 0) {
return false;
}
Copy link
Member

Choose a reason for hiding this comment

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

You need to check that every b.params[i] is defined. Test case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Josh-Cena
I fixed it in 47286f7

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

I'll just apply a quick lil refactor myself - the code & tests look great. Cheers!

@@ -215,6 +215,7 @@ export default util.createRule<Options, MessageIds>({
if (ignoreDifferentlyNamedParameters) {
for (let i = 0; i < a.params.length; i += 1) {
if (
b.params[i] &&
Copy link
Member

Choose a reason for hiding this comment

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

[Refactor] Asking for an element out of bounds of an array is a little confusing. It looks like this code is asking whether b.params[i] is a falsy element - even though the type of b.params indicates that not to be doable. I'm also under the impression accessing elements out of an array's bounds can cause a performance deoptimization (though this code almost certainly wouldn't suffer meaningfully).

I think a more proper fix would be capping the i to Math.min(a.params.length, b.params.length).

Copy link
Member

Choose a reason for hiding this comment

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

Just applied - normally I'd let you have the pleasure, but I feel bad taking up your time on such a small change 😄

@JoshuaKGoldberg JoshuaKGoldberg merged commit 2970861 into typescript-eslint:main Apr 24, 2023
35 of 38 checks passed
@JoshuaKGoldberg
Copy link
Member

(sorry for jumping in @Josh-Cena - really want this merged in time for our Monday release)

andersk added a commit to andersk/xo that referenced this pull request Apr 25, 2023
Among other improvements, this fixes a crash in the
@typescript-eslint/unified-signatures rule:
typescript-eslint/typescript-eslint#6940.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Apr 27, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.57.1` -> `5.59.1`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/5.57.1/5.59.1) |
| [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint) | devDependencies | minor | [`5.57.1` -> `5.59.1`](https://renovatebot.com/diffs/npm/@typescript-eslint%2fparser/5.57.1/5.59.1) |

---

### Release Notes

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/eslint-plugin)</summary>

### [`v5.59.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;5591-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5590v5591-2023-04-24)

[Compare Source](typescript-eslint/typescript-eslint@v5.59.0...v5.59.1)

##### Bug Fixes

-   **eslint-plugin:** \[prefer-regexp-exec] skip malformed regexes ([#&#8203;6935](typescript-eslint/typescript-eslint#6935)) ([05ed60e](typescript-eslint/typescript-eslint@05ed60e))
-   **eslint-plugin:** \[unified-signatures] no parameters function ([#&#8203;6940](typescript-eslint/typescript-eslint#6940)) ([2970861](typescript-eslint/typescript-eslint@2970861))

### [`v5.59.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;5590-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5580v5590-2023-04-17)

[Compare Source](typescript-eslint/typescript-eslint@v5.58.0...v5.59.0)

##### Bug Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] allow nullish coalescing for naked type parameter ([#&#8203;6910](typescript-eslint/typescript-eslint#6910)) ([3e5f858](typescript-eslint/typescript-eslint@3e5f858))

##### Features

-   **eslint-plugin:** \[ban-types] add NonNullable suggestion and allow custom suggestions ([#&#8203;6876](typescript-eslint/typescript-eslint#6876)) ([ff65235](typescript-eslint/typescript-eslint@ff65235))

### [`v5.58.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#&#8203;5580-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5571v5580-2023-04-10)

[Compare Source](typescript-eslint/typescript-eslint@v5.57.1...v5.58.0)

##### Bug Fixes

-   **eslint-plugin:** \[unified-signatures] allow overloads with different named and different number of parameters ([#&#8203;6877](typescript-eslint/typescript-eslint#6877)) ([939d665](typescript-eslint/typescript-eslint@939d665))

##### Features

-   **eslint-plugin:** \[no-unsafe-enum-comparison] add rule ([#&#8203;6107](typescript-eslint/typescript-eslint#6107)) ([915f9c2](typescript-eslint/typescript-eslint@915f9c2))

#### [5.57.1](typescript-eslint/typescript-eslint@v5.57.0...v5.57.1) (2023-04-03)

##### Bug Fixes

-   **eslint-plugin:** \[strict-boolean-expressions] support mixed enums in allowNullableEnum option ([#&#8203;6740](typescript-eslint/typescript-eslint#6740)) ([49be8a8](typescript-eslint/typescript-eslint@49be8a8))

</details>

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/parser)</summary>

### [`v5.59.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#&#8203;5591-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5590v5591-2023-04-24)

[Compare Source](typescript-eslint/typescript-eslint@v5.59.0...v5.59.1)

**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)

### [`v5.59.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#&#8203;5590-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5580v5590-2023-04-17)

[Compare Source](typescript-eslint/typescript-eslint@v5.58.0...v5.59.0)

**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)

### [`v5.58.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#&#8203;5580-httpsgithubcomtypescript-eslinttypescript-eslintcomparev5571v5580-2023-04-10)

[Compare Source](typescript-eslint/typescript-eslint@v5.57.1...v5.58.0)

##### Bug Fixes

-   update getLib for new TypeScript targets ES2021, ES2022 ([#&#8203;6782](typescript-eslint/typescript-eslint#6782)) ([1c04664](typescript-eslint/typescript-eslint@1c04664))

#### [5.57.1](typescript-eslint/typescript-eslint@v5.57.0...v5.57.1) (2023-04-03)

**Note:** Version bump only for package [@&#8203;typescript-eslint/parser](https://github.com/typescript-eslint/parser)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS40MC4wIiwidXBkYXRlZEluVmVyIjoiMzUuNjEuMCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1858
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [unified-signatures] Crash in rule implementation
4 participants