Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
JoshuaKGoldberg merged 79 commits intotypescript-eslint:v6frommarekdedic:prefer-readonly-parameter-types-whitelist
Mar 20, 2023
Merged

feat(eslint-plugin): [prefer-readonly-parameter-types] added an optional type allowlist#4436

JoshuaKGoldberg merged 79 commits intotypescript-eslint:v6frommarekdedic:prefer-readonly-parameter-types-whitelist
Mar 20, 2023

Conversation

marekdedic
Copy link
Contributor

@marekdedicmarekdedic commentedJan 12, 2022
edited by JoshuaKGoldberg
Loading

BREAKING CHANGE:
Changes arguments to a public API

PR Checklist

Overview

I have added an option type whitelist to the ruleprefer-readonly-parameter-types.

This PR is not yet ready: ✔️

tbergquist-godaddy, JoshuaKGoldberg, and andriyor reacted with thumbs up emojijklmli and JoshuaKGoldberg reacted with heart emoji
@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlifybot commentedJan 12, 2022
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit3d465cc
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/64186a8bf4aabf00087aee72
😎 Deploy Previewhttps://deploy-preview-4436--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 yourNetlify site settings.

@bradzacherbradzacher added the enhancement: plugin rule optionNew rule option for an existing eslint-plugin rule labelJan 12, 2022
@codecov
Copy link

codecovbot commentedJan 12, 2022
edited
Loading

Codecov Report

Merging#4436 (3d465cc) intov6 (bd273dd) willdecrease coverage by0.40%.
The diff coverage is92.10%.

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
FlagCoverage Δ
unittest85.25% <92.10%> (-0.40%)⬇️

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

Impacted FilesCoverage Δ
packages/type-utils/src/TypeOrValueSpecifier.ts89.28% <89.28%> (ø)
...lugin/src/rules/prefer-readonly-parameter-types.ts100.00% <100.00%> (ø)
packages/type-utils/src/isTypeReadonly.ts87.03% <100.00%> (+1.03%)⬆️

... and6 files with indirect coverage changes

@RebeccaStevens
Copy link
Contributor

RebeccaStevens commentedJan 13, 2022
edited
Loading

With regard to complex types; we'd probably want to mixallowlist with the following part of#4429

// Special case for handling arrays/tuples (as readonly arrays/tuples always have mutable methods).
if(
type.types.some(t=>checker.isArrayType(t)||checker.isTupleType(t))
){
constallReadonlyParts=type.types.every(
t=>
seenTypes.has(t)||
isTypeReadonlyRecurser(checker,t,options,seenTypes)===
Readonlyness.Readonly,
);
returnallReadonlyParts ?Readonlyness.Readonly :Readonlyness.Mutable;
}

marekdedic reacted with thumbs up emoji

@marekdedic
Copy link
ContributorAuthor

Hi,
in the end, some types not from the standard lib need to be whitelisted - for exampleJQueryStatic from@types/jquery AFAIK cannot be made readonly due tosindresorhus/type-fest#337.

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 likeallowlist: [["HTMLElement", "DOM"], ["JQueryStatic", "@types/jquery"]]. However, after digging through the is-standard-lib-check code, I found no easy way to specify the "package" from where the type is (I gues you could check for declaration file name substring, but that seems brittle).

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.

@bradzacherbradzacher changed the titlefeat(eslint-plugin): [prefer-readonly-parameter-types] Added an optional type whitelistfeat(eslint-plugin): [prefer-readonly-parameter-types] Added an optional type allowlistJan 13, 2022
@marekdedic
Copy link
ContributorAuthor

marekdedic commentedJan 16, 2022
edited
Loading

Hi,
I think the PR is basically ready, with some outstanding points I don't know how to resolve myself

  • What to do with internal vs. external allowlist - seefeat(eslint-plugin): [prefer-readonly-parameter-types] added an optional type allowlist #4436 (comment)
  • I needed to addlib: dom to the testtsconfig.json, however, that broke one existing test. Could the lib be set per-test? I'd also like to test a custom type that happens to have the same name as an internal-whitelisted one (but isn't internal, so shouldn't actually be whitelisted)
  • What should the internal whitelist look like? Currently, it's just["HTMLElement"], do you know of any other types causing issues?
  • There's something strange going on with the netlify deployment - Ithink I didn't break it, so 🤷

@marekdedicmarekdedic marked this pull request as ready for reviewJanuary 16, 2022 13:29
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commentedJan 24, 2022
edited
Loading

after digging through the is-standard-lib-check code, I found no easy way to specify the "package" from where the type is (I guess you could check for declaration file name substring, but that seems brittle).

Yup, that's... pretty much what I'd do 😄. Checking whether it'snode_modules/package/ ornode_modules/@types/package is the best I can think of. This is part of why we generally prefer not to include these kinds of allowlists; names such asNode can be re-used and quite ambiguous. Long term we may want to build off of this PR and set up a standard format for how rules can specify type locations...

internal whitelist look like

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"HTMLElement" or any others by default.

Netlify

Indeed,#4335 😢... it's better than it was, but still not fully fixed, onmain.

marekdedic reacted with thumbs up emoji

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a 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!

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelJan 24, 2022
@marekdedic
Copy link
ContributorAuthor

marekdedic commentedJan 24, 2022
edited
Loading

after digging through the is-standard-lib-check code, I found no easy way to specify the "package" from where the type is (I guess you could check for declaration file name substring, but that seems brittle).

Yup, that's... pretty much what I'd do smile. Checking whether it'snode_modules/package/ ornode_modules/@types/package is the best I can think of.

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?

@marekdedic
Copy link
ContributorAuthor

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"HTMLElement" or any others by default.

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.HTMLElement is almost always pointless - there is just no way around this and everyone who stumbles upon this can either add it to the whitelist or disable the rule for that line. The only way it's justalmost pointless is that I can imagine you rewrite some functions to not take the full element as parameter, but something else (like its text contents or whatever...) See#4185 or#2699

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
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@typescript-eslinttypescript-eslint deleted a comment fromnx-cloudbotMar 20, 2023
@JoshuaKGoldbergJoshuaKGoldberg merged commitc9427b7 intotypescript-eslint:v6Mar 20, 2023
@marekdedic
Copy link
ContributorAuthor

🎉 Only took a year and a bit :D

Thanks for all the feedback and collaboration getting this ready and merged.

JoshuaKGoldberg reacted with laugh emojiJoshuaKGoldberg and RebeccaStevens reacted with hooray emoji

@marekdedicmarekdedic deleted the prefer-readonly-parameter-types-whitelist branchMarch 20, 2023 15:11
@JoshuaKGoldberg
Copy link
Member

Yes! It took a while but the result is fantastic - thankyou@marekdedic for working with us!

marekdedic reacted with heart emoji

@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMar 28, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

@RebeccaStevensRebeccaStevensRebeccaStevens approved these changes

@bradzacherbradzacherbradzacher approved these changes

@Josh-CenaJosh-CenaAwaiting requested review from Josh-Cena

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we mergebreaking changeThis change will require a new major version to be releasedenhancement: plugin rule optionNew rule option for an existing eslint-plugin rule
Projects
None yet
Milestone
6.0.0
Development

Successfully merging this pull request may close these issues.

[prefer-readonly-parameter-types] Proposal: Add type allowlist
5 participants
@marekdedic@RebeccaStevens@JoshuaKGoldberg@Josh-Cena@bradzacher

[8]ページ先頭

©2009-2025 Movatter.jp