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): [prefer-readonly] report if a member's property is reassigned #6043

Conversation

islandryu
Copy link
Contributor

@islandryu islandryu commented Nov 19, 2022

PR Checklist

Overview

@nx-cloud
Copy link

nx-cloud bot commented Nov 19, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit be983e9. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 47 targets

Sent with 💌 from NxCloud.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @islandryu!

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 Nov 19, 2022

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit be983e9
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6382776df71c450008c5c1f5
😎 Deploy Preview https://deploy-preview-6043--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 Nov 19, 2022

Codecov Report

Merging #6043 (be983e9) into main (d69fdf4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6043   +/-   ##
=======================================
  Coverage   91.27%   91.28%           
=======================================
  Files         366      366           
  Lines       12362    12363    +1     
  Branches     3616     3617    +1     
=======================================
+ Hits        11284    11285    +1     
  Misses        768      768           
  Partials      310      310           
Flag Coverage Δ
unittest 91.28% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
...ackages/eslint-plugin/src/rules/prefer-readonly.ts 99.09% <100.00%> (+<0.01%) ⬆️

@islandryu islandryu marked this pull request as ready for review November 19, 2022 13:17
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.

Code change looks great to start, thanks for sending this in @islandryu! 🙌 Just requesting changes for a bit more test coverage.

messageId: 'preferReadonly',
},
],
},
Copy link
Member

Choose a reason for hiding this comment

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

A few more test cases to consider...

this.testObj.prop;
this.testObj?.prop;
this.testObj!.prop;
this.testObj!.prop = '';
this.testObj.prop.prop = '';
this.testObj.prop.doesSomething();
this.testObj?.prop.prop;
this.testObj?.prop?.prop;
this.testObj.prop?.prop;
this.testObj!.prop?.prop;

For any change to rule logic, it's generally good to try to add both valid and invalid test cases.

Copy link
Member

Choose a reason for hiding this comment

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

@islandryu by "test cases" I do mean cases plural - we generally try to keep these separate, so that each test case tests one case. It's easy to miss incorrect or mismatched errors when they're all lumped together. Could you split them up please?

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Nov 19, 2022
@islandryu
Copy link
Contributor Author

@JoshuaKGoldberg
Thank you!
I've added a test case!

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.

Sorry, I might not have been very clear - I'm hoping for quite a few cases to test this. It's a behavior that has a lot of edge cases we should test for individually. Thanks!

messageId: 'preferReadonly',
},
],
},
Copy link
Member

Choose a reason for hiding this comment

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

@islandryu by "test cases" I do mean cases plural - we generally try to keep these separate, so that each test case tests one case. It's easy to miss incorrect or mismatched errors when they're all lumped together. Could you split them up please?

@islandryu
Copy link
Contributor Author

@JoshuaKGoldberg
Thank you.
Is it correct like this?

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.

Yup, this is great - thanks for sending this in! 🙌

@JoshuaKGoldberg JoshuaKGoldberg enabled auto-merge (squash) November 26, 2022 20:30
@JoshuaKGoldberg JoshuaKGoldberg merged commit 6e079eb into typescript-eslint:main Nov 26, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [prefer-readonly] does not report if a member's property is reassigned
2 participants