-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix(eslint-plugin): [unified-signatures] no parameters function #6940
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
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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov Report
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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
if (b.params.length === 0) { | ||
return false; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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] && |
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
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 😄
(sorry for jumping in @Josh-Cena - really want this merged in time for our Monday release) |
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>
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 (@​typescript-eslint/eslint-plugin)</summary> ### [`v5.59.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#​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 ([#​6935](typescript-eslint/typescript-eslint#6935)) ([05ed60e](typescript-eslint/typescript-eslint@05ed60e)) - **eslint-plugin:** \[unified-signatures] no parameters function ([#​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#​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 ([#​6910](typescript-eslint/typescript-eslint#6910)) ([3e5f858](typescript-eslint/typescript-eslint@3e5f858)) ##### Features - **eslint-plugin:** \[ban-types] add NonNullable suggestion and allow custom suggestions ([#​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#​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 ([#​6877](typescript-eslint/typescript-eslint#6877)) ([939d665](typescript-eslint/typescript-eslint@939d665)) ##### Features - **eslint-plugin:** \[no-unsafe-enum-comparison] add rule ([#​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 ([#​6740](typescript-eslint/typescript-eslint#6740)) ([49be8a8](typescript-eslint/typescript-eslint@49be8a8)) </details> <details> <summary>typescript-eslint/typescript-eslint (@​typescript-eslint/parser)</summary> ### [`v5.59.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/parser/CHANGELOG.md#​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 [@​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#​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 [@​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#​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 ([#​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 [@​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>
PR Checklist
Overview
Add guard clause because b.params[i].type is not accessible when comparing to a function with no parameters