-
-
Notifications
You must be signed in to change notification settings - Fork 2.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 our terms of service and privacy 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
Conversation
…nal type whitelist
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 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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
packages/eslint-plugin/src/rules/prefer-readonly-parameter-types.ts
Outdated
Show resolved
Hide resolved
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.
|
With regard to complex types; we'd probably want to mix typescript-eslint/packages/type-utils/src/isTypeReadonly.ts Lines 202 to 213 in 491c7bb
|
…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
Hi,
|
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
Outdated
Show resolved
Hide resolved
I found a better way! We could use https://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 - thank you @marekdedic for working with us! |
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)