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): [restrict-template-expressions] check base types in allow list#11764

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

Conversation

@Higangssh
Copy link
Contributor

Fixes#11759

PR Checklist

Overview

This PR fixes an issue where therestrict-template-expressions rule incorrectly rejects derived class instances
in template literals when their base class is in the allow list.

Problem

Currently, when a base class is included in theallow option, derived classes extending it are still flagged as
errors, violating the Liskov Substitution Principle where subtypes should be substitutable for their supertypes.

Example:

// Configuration: { allow: [{ from: 'file', name: 'Base' }]}classBase{}classDerivedextendsBase{}constbar=newDerived();`${bar}`;// Error: Invalid type "Derived"

Solution

Implemented recursive base type checking following the pattern established in the no-base-to-string rule:

  1. Added hasBaseTypes() helper function to identify types with base types (Interface or Class)
  2. Added isAllowedTypeOrBase() function that recursively checks if a type or its base types match the allow list
  3. Included cycle detection using a Set to prevent infinite recursion
  4. Updated recursivelyCheckType() to utilize the new base type checking mechanism

Changes

  • packages/eslint-plugin/src/rules/restrict-template-expressions.ts: Added base type checking logic
  • packages/eslint-plugin/tests/rules/restrict-template-expressions.test.ts: Added test case for inheritance
    scenario

Allow derived types in template expressions when base types are in allow listFixestypescript-eslint#11759
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@Higangssh!

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.

@netlify
Copy link

netlifybot commentedNov 16, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit80be898
🔍 Latest deploy loghttps://app.netlify.com/projects/typescript-eslint/deploys/6929e382d0018100097b0a67
😎 Deploy Previewhttps://deploy-preview-11764--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: 81 (🔴 down 17 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (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 project configuration.

@nx-cloud
Copy link

nx-cloudbot commentedNov 16, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commit80be898

CommandStatusDurationResult
nx test eslint-plugin --coverage=false✅ Succeeded5m 31sView ↗
nx run-many -t lint✅ Succeeded3m 17sView ↗
nx run-many -t typecheck✅ Succeeded2m 8sView ↗
nx run types:build✅ Succeeded1sView ↗
nx run integration-tests:test✅ Succeeded6sView ↗
nx test typescript-estree --coverage=false✅ Succeeded2sView ↗
nx test eslint-plugin-internal --coverage=false✅ Succeeded3sView ↗
nx run generate-configs✅ Succeeded5sView ↗
Additional runs (29)✅ Succeeded...View ↗

☁️Nx Cloud last updated this comment at2025-11-28 18:12:06 UTC

@HigangsshHigangssh changed the title fix(restrict-template-expressions): check base types in allow listfix(eslint-plugin): [restrict-template-expressions] check base types in allow listNov 16, 2025
@codecov
Copy link

codecovbot commentedNov 16, 2025
edited
Loading

Codecov Report

❌ Patch coverage is93.10345% with4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.48%. Comparing base (16cf0f7) to head (80be898).
⚠️ Report is 1 commits behind head on main.

Files with missing linesPatch %Lines
packages/eslint-plugin/src/util/baseTypeUtils.ts90.90%4 Missing⚠️
Additional details and impacted files
@@            Coverage Diff             @@##             main   #11764      +/-   ##==========================================- Coverage   90.49%   90.48%   -0.01%==========================================  Files         522      523       +1       Lines       53367    53393      +26       Branches     8918     8919       +1     ==========================================+ Hits        48293    48315      +22- Misses       5059     5063       +4  Partials       15       15
FlagCoverage Δ
unittest90.48% <93.10%> (-0.01%)⬇️

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

Files with missing linesCoverage Δ
...kages/eslint-plugin/src/rules/no-base-to-string.ts99.01% <100.00%> (-0.07%)⬇️
...-plugin/src/rules/restrict-template-expressions.ts100.00% <100.00%> (ø)
packages/eslint-plugin/src/util/baseTypeUtils.ts90.90% <90.90%> (ø)
🚀 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.

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelNov 17, 2025
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment
edited
Loading

Choose a reason for hiding this comment

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

Looks good! ✨

Just a few cleanup/refactor requests, nothing on the core logic. Thanks for getting this started!

- Remove unnecessary test comments- Extract hasBaseTypes to shared util- Create matchesTypeOrBaseType with matcher pattern
@Higangssh
Copy link
ContributorAuthor

Thanks for the review! I've addressed all the feedback:

  • Removed unnecessary test comments
  • Extracted hasBaseTypes to shared util
  • Created matchesTypeOrBaseType with matcher pattern

@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelNov 18, 2025

Choose a reason for hiding this comment

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

[Testing] Oh, sory, I just realized - this is missing test coverage for extending multiple classes.

  • A extends B, C whereB is listed
  • A extends B, C whereC is listed
  • A extends B, C +B extends D, E whereE is listed

etc.

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, a bit more testing please

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelNov 18, 2025
@Higangssh
Copy link
ContributorAuthor

@JoshuaKGoldberg Added tests for multiple interface inheritance. Thanks for the thorough review - really
appreciate you taking the time to guide me through this! Let me know if there's anything else that needs
adjusting

JoshuaKGoldberg reacted with heart emoji

@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelNov 28, 2025
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesNov 28, 2025
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.

💯 thanks! Very thorough, nicely done.

Higangssh reacted with heart emoji
@JoshuaKGoldbergJoshuaKGoldberg merged commit906cc3c intotypescript-eslint:mainNov 28, 2025
64 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Bug: [restrict-template-expressions] should check if superclass is ignored

2 participants

@Higangssh@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp