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(experimental-utils): support immutable members #3844

Merged
merged 6 commits into from Dec 15, 2021

Conversation

rafaelss95
Copy link
Contributor

This PR is basically to provide support for immutable in some other members/functions besides of #3830.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @rafaelss95!

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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day.

@rafaelss95
Copy link
Contributor Author

rafaelss95 commented Sep 5, 2021

PS 1: I tried to change Range from:

export type Range = [number, number];

to:

export type Range = readonly [number, number]; 

but it didn't work as it actually needs to be mutated in places like:

result.range[0] = varToken!.getStart(this.ast);

So in this case I opted out for just typing the necessary functions as Readonly<AST.Range>.

PS 2: The lint failure seems to be unrelated to this change.
Since Array.isArray doesn't work properly with readonly T[] as reported in microsoft/TypeScript#17002, I used the type annotation in no-magic-numbers to avoid the no-unsafe-assignment report.

@codecov
Copy link

codecov bot commented Sep 7, 2021

Codecov Report

Merging #3844 (0606673) into main (475caa4) will increase coverage by 0.15%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #3844      +/-   ##
==========================================
+ Coverage   93.33%   93.49%   +0.15%     
==========================================
  Files         152      192      +40     
  Lines        8014     8672     +658     
  Branches     2568     2683     +115     
==========================================
+ Hits         7480     8108     +628     
- Misses        180      351     +171     
+ Partials      354      213     -141     
Flag Coverage Δ
unittest 93.49% <100.00%> (+0.15%) ⬆️

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

Impacted Files Coverage Δ
...kages/eslint-plugin/src/rules/no-empty-function.ts 80.00% <ø> (ø)
...ges/experimental-utils/src/ts-eslint/RuleTester.ts 100.00% <ø> (ø)
...ckages/eslint-plugin/src/rules/no-magic-numbers.ts 84.31% <100.00%> (+1.96%) ⬆️
packages/eslint-plugin/src/rules/array-type.ts 97.18% <0.00%> (-1.33%) ⬇️
packages/eslint-plugin/src/rules/brace-style.ts 95.34% <0.00%> (ø)
packages/eslint-plugin/src/rules/no-redeclare.ts 91.89% <0.00%> (ø)
...ackages/eslint-plugin/src/rules/no-extra-parens.ts 90.41% <0.00%> (ø)
...ackages/eslint-plugin/src/util/getWrappingFixer.ts 100.00% <0.00%> (ø)
...kages/eslint-plugin/src/rules/naming-convention.ts 81.09% <0.00%> (ø)
... and 101 more

@rafaelss95
Copy link
Contributor Author

This PR was accidentally closed earlier and I had forgotten to reopen it.

Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

One change - otherwise LGTM
Thanks for your work!

@@ -209,13 +209,13 @@ interface RuleContext<
* the root of the AST and continuing through the direct parent of the current node.
* This array does not include the currently-traversed node itself.
*/
getAncestors(): TSESTree.Node[];
getAncestors(): readonly TSESTree.Node[];
Copy link
Member

Choose a reason for hiding this comment

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

This would be a breaking change because it's not uncommon for people to do getAncestors().reverse()

Also - it isn't necessary because getAncestors returns a new array each invocation:
https://github.com/eslint/eslint/blob/d867f8100737bb82742debee2b5dc853c5f07c91/lib/linter/linter.js#L789-L797

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Oct 3, 2021
bradzacher
bradzacher previously approved these changes Oct 29, 2021
Copy link
Member

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

@bradzacher bradzacher added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Oct 29, 2021
armano2
armano2 previously approved these changes Dec 15, 2021
Copy link
Member

@bradzacher bradzacher left a comment

Choose a reason for hiding this comment

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

the lint error is actually legit.
repro

Found this TS issue: microsoft/TypeScript#17002
It's a TS bug :(

Which I see you already found and mentioned above!!

@bradzacher bradzacher dismissed stale reviews from armano2 and themself via 0606673 December 15, 2021 07:19
@netlify
Copy link

netlify bot commented Dec 15, 2021

❌ Deploy Preview for typescript-eslint failed.

🔨 Explore the source changes: 0606673

🔍 Inspect the deploy log: https://app.netlify.com/sites/typescript-eslint/deploys/61b996f7e97b010008cc27a8

@bradzacher bradzacher merged commit 3d33a77 into typescript-eslint:main Dec 15, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants