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

fix(eslint-plugin): [consistent-generic-constructors] ignore when constructor is typed array#10477

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

Open
mdm317 wants to merge11 commits intotypescript-eslint:main
base:main
Choose a base branch
Loading
frommdm317:fix/issue-10445-consistent-generic-constructors

Conversation

mdm317
Copy link
Contributor

PR Checklist

Overview

Hard-code the typed arrays and added code to skip check if the type is a typed array.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@mdm317!

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.

@mdm317mdm317 marked this pull request as draftDecember 9, 2024 09:33
@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedDec 9, 2024
edited
Loading

View yourCI Pipeline Execution ↗ for commit91b65ae.

CommandStatusDurationResult
nx test eslint-plugin✅ Succeeded7m 47sView ↗
nx run eslint-plugin:test -- --coverage✅ Succeeded6m 14sView ↗
nx test eslint-plugin --coverage=false✅ Succeeded6m 24sView ↗
nx run rule-tester:test -- --coverage✅ Succeeded<1sView ↗
nx run types:build✅ Succeeded<1sView ↗
nx run-many --target=build --exclude website --...✅ Succeeded14sView ↗
nx test utils✅ Succeeded<1sView ↗
nx run-many --target=clean✅ Succeeded12sView ↗
Additional runs (25)✅ Succeeded...View ↗

☁️Nx Cloud last updated this comment at2025-03-14 17:13:59 UTC

@netlifyNetlify
Copy link

netlifybot commentedDec 9, 2024
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit91b65ae
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/67d4606c0cd7bc0009565010
😎 Deploy Previewhttps://deploy-preview-10477--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 99 (🟢 up 6 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify site configuration.

@codecovCodecov
Copy link

codecovbot commentedDec 9, 2024
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.58%. Comparing base(7469e72) to head(91b65ae).
Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@##             main   #10477   +/-   ##=======================================  Coverage   87.58%   87.58%           =======================================  Files         470      470             Lines       16095    16096    +1       Branches     4668     4669    +1     =======================================+ Hits        14097    14098    +1  Misses       1642     1642             Partials      356      356
FlagCoverage Δ
unittest87.58% <100.00%> (+<0.01%)⬆️

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

Files with missing linesCoverage Δ
...lugin/src/rules/consistent-generic-constructors.ts90.69% <100.00%> (+0.22%)⬆️
🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mdm317mdm317 marked this pull request as ready for reviewDecember 9, 2024 15:56
return true;
}
return false;
};
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldbergDec 14, 2024
edited
Loading

Choose a reason for hiding this comment

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

[Bug] It's not enough to just look at the name. If someone happens to redeclare their own class, such asclass Uint8Array<T>, the rule should know to check that:

https://deploy-preview-10477--typescript-eslint.netlify.app/play/#ts=5.7.2&fileType=.ts&code=MYGwhgzhAECqCWA7ALgDgIICdNgJ4B4AVAPmgG8AoaaAehugDomKBfCikAU2WjAC44SNFhwEReAEIBXAGYzOmADLwA1p1IBeaIk4B3QSgzY8ACgCUAbnacAHgAcA9ph5kWQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6MgeyeUuX0Ra0A5gMRUytTt3xwy%2BDtFQZIY6AsjgwAXxBagA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkqyARhWANqTokBMADJwMyQAugBpwNSPFgATAK4Zm7Lr06RRNKCTyZk0PADk5qAMIALdNADWZSlpno14vAENMAc3R4FHHv0hiAviD%2BQA&tokens=false

classUint8Array<T>{// ...}leta:Uint8Array<ArrayBufferLike>=newUint8Array();export{}

You'll want to use the scope manager to see whether the identifier is referencing something declared or imported in the file vs. a global. Searching oncontext.sourceCode.getScope should get you some good starting points.

mdm317 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.

A good start! 🚀

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelDec 14, 2024
@Josh-Cena
Copy link
Member

FWIW, my personal preference is still "we should not special case built-ins". These types of declarations can legitimately happen with user-defined types, so we should just create a generic allowlist of types.

mdm317 reacted with thumbs up emoji

@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelDec 17, 2024
@mdm317
Copy link
ContributorAuthor

mdm317 commentedDec 17, 2024
edited
Loading

Should we avoid dealing specifically with the built-in array-likes?

@JoshuaKGoldbergJoshuaKGoldberg changed the titlefix: ignore when constructor is typed arrayfix(eslint-plugin): [consistent-generic-constructors] ignore when constructor is typed arrayJan 13, 2025
@JoshuaKGoldberg
Copy link
Member

@Josh-Cena just confirming, what do you suggest we do here?

@Josh-Cena
Copy link
Member

This:

we should just create a generic allowlist of types.

Like a new option calledignore orallow where the types would just be ignored for consistency checks.

JoshuaKGoldberg reacted with thumbs up emoji

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelMar 3, 2025
@mdm317
Copy link
ContributorAuthor

Like a new option called ignore or allow where the types would just be ignored for consistency checks.

I added an allow option to ignore consistency checks.

Should I add TypedArray to the default option?

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.

Sorry for the back-and-forth on this rule's option(s)! It looks like we have a bit of design/discussion work to do before we're settled?

@@ -77,7 +96,8 @@ export default createRule<Options, MessageIds>({
lhs &&
(lhs.type !== AST_NODE_TYPES.TSTypeReference ||
lhs.typeName.type !== AST_NODE_TYPES.Identifier ||
lhs.typeName.name !== rhs.callee.name)
lhs.typeName.name !== rhs.callee.name ||
options?.ignore?.includes(lhs.typeName.name))
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldbergMar 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

Threading#10477 (comment):

Should I add TypedArray to the default option?

It looks like we don't have consensus on this yet?

One concern with having default values in the default list is that it gets inconvenient to add to the list rather than replace it. If the default type includes, say,Proxy and all theUint*Arrays, then that's a lot of manual re-typing for folks to write if they want to keep ignoring them.

We're previously had options likeban-types >extendDefaults to get around this, but they're kind of clunky.

@Josh-Cena I think what's confusing me here is:

  • What benefit is there to reporting onUint8Array and similar? I.e.: in what situations would one want the rule to report on them?
  • If there are none, why not hardcode the rule to always ignore them?

cc@kirkwaiblinger

Copy link
Member

Choose a reason for hiding this comment

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

  • What benefit is there to reporting onUint8Array and similar? I.e.: in what situations would one want the rule to report on them?

There's none; I would expect them to be ignored by default.

If there are none, why not hardcode the rule to always ignore them?

Therule should be generic. Any library-specific logic (even those related to native objects) should be injected via options. Built-in objects should not be distinguishable from user-defined objects.

Choose a reason for hiding this comment

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

Ok great I think we're aligned? Just confirming, I'm of the opinion that:

  • The rule should not report those things by default
  • The list should be empty ([]) by default

...so the rule should not provide a way to now report on those built-ins?

ignore: {
type: 'array',
description:
'A list of constructor names to ignore when enforcing the rule.',

Choose a reason for hiding this comment

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

IMO if we do go with a list then we'd want to useTypeOrValueSpecifier. Otherwise it'll have the same issue as#10477 (comment) with coincidentally matching names.

But, I'm not sure this is the right step. I started a thread later in this file about it.

mdm317 reacted with thumbs up emoji
@JoshuaKGoldbergJoshuaKGoldberg added the triageWaiting for team members to take a look labelMar 31, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg requested changes

@Josh-CenaJosh-CenaJosh-Cena left review comments

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Labels
awaiting responseIssues waiting for a reply from the OP or another partytriageWaiting for team members to take a look
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: [consistent-generic-constructors] improper fix intonew Uint8Array<ArrayBufferLike>()
3 participants
@mdm317@Josh-Cena@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp