Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [prefer-readonly-parameter-types] added an optional type allowlist#4436
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
feat(eslint-plugin): [prefer-readonly-parameter-types] added an optional type allowlist#4436
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@marekdedic! 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 onhttps://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitorsper day. |
netlifybot commentedJan 12, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site settings. |
packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
codecovbot commentedJan 12, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@## v6 #4436 +/- ##==========================================- Coverage 85.64% 85.25% -0.40%========================================== Files 372 373 +1 Lines 12675 12764 +89 Branches 3747 3791 +44 ==========================================+ Hits 10856 10882 +26- Misses 1461 1501 +40- Partials 358 381 +23
Flags with carried forward coverage won't be shown.Click here to find out more.
|
RebeccaStevens commentedJan 13, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
With regard to complex types; we'd probably want to mix typescript-eslint/packages/type-utils/src/isTypeReadonly.ts Lines 202 to 213 in491c7bb
|
…wlist between internal and configurable
…e with non-null assertion
Hi, Originally, I wanted to be able to extend the feature of checking whether a type belongs to the standard lib to these types as well - so you'd have something like So I split the allowlist between internal, which checks stdlib, and user-configurable. Let me know what you think of this or if you see any better approach. |
… everywhere in deep readonlyness checks
…l allowlist from rule
…ns and schema of rule and util
…ocs for option treatMethodsAsReadonly
marekdedic commentedJan 16, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi,
|
JoshuaKGoldberg commentedJan 24, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Yup, that's... pretty much what I'd do 😄. Checking whether it's
How about empty? We generally try not to put forward opinions like which internal types do or don't match up with specific rule options. I don't think we want
Indeed,#4335 😢... it's better than it was, but still not fully fixed, on |
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.
Looks good so far, thanks!
packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
marekdedic commentedJan 24, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I found a better way! We could usehttps://github.com/microsoft/TypeScript/blob/b9efc3b6141f06d926b4067d086ed5f03f221c49/src/compiler/types.ts#L4018-L4019 if it weren't internal... Let's merge this and improve it if I can get TS to make it public, would that be okay? |
I don't think that should be the default. Given that certain types are basically impossible to pass in a readonly fashion, reporting for e.g. I'm in favor of being conservative and not whitelisting anything where there's any chance of it being an actionable report, but I feel that for some types this is just not helpful. |
…ons and internalExceptions together to create a universal allowlist API
🎉 Only took a year and a bit :D Thanks for all the feedback and collaboration getting this ready and merged. |
Yes! It took a while but the result is fantastic - thankyou@marekdedic for working with us! |
Uh oh!
There was an error while loading.Please reload this page.
BREAKING CHANGE:
Changes arguments to a public API
PR Checklist
Overview
I have added an option type whitelist to the rule
prefer-readonly-parameter-types
.This PR is not yet ready:✔️JQueryStatic
(which leads toReadonlyDeep
does not work for objects with call signatures sindresorhus/type-fest#337)