Skip to content

fix(no-base-to-string): check base types for ignoredTypeNames#796

Merged
camc314 merged 2 commits intooxc-project:mainfrom
younggglcy:younggglcy/no-base-to-string-extends
Mar 16, 2026
Merged

fix(no-base-to-string): check base types for ignoredTypeNames#796
camc314 merged 2 commits intooxc-project:mainfrom
younggglcy:younggglcy/no-base-to-string-extends

Conversation

@younggglcy
Copy link
Copy Markdown
Contributor

Summary

Fixes #749

The rule was only checking the type's own name against ignoredTypeNames, so classes that extend an ignored type (e.g., class Foo extends Error {}) were incorrectly flagged as violations.

  • Add matchesTypeOrBaseType to recursively walk the class hierarchy via getBaseTypes, matching the upstream typescript-eslint implementation in baseTypeUtils.ts
  • Handle TypeReference types by dereferencing through .Target() before checking ClassOrInterface flags, to avoid panics on array/tuple reference types

Test plan

  • Added valid test case for class Foo extends Error {} (non-generic)
  • Added valid test case for class Foo<T> extends Error {} (generic)
  • All existing tests pass

The rule was only checking the type's own name against ignoredTypeNames,
missing classes that extend ignored types (e.g., `class Foo extends Error {}`).

Add `matchesTypeOrBaseType` to recursively walk the class hierarchy via
`getBaseTypes`, matching the upstream typescript-eslint implementation in
`baseTypeUtils.ts`. Handle TypeReference types by dereferencing through
`.Target()` before checking ClassOrInterface flags to avoid panics on
array/tuple reference types.

Closes oxc-project#749
@camc314 camc314 self-assigned this Mar 16, 2026
Copy link
Copy Markdown
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

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

thank you!

@camc314 camc314 enabled auto-merge (squash) March 16, 2026 19:15
@camc314 camc314 merged commit f04fe8a into oxc-project:main Mar 16, 2026
7 checks passed
@younggglcy younggglcy deleted the younggglcy/no-base-to-string-extends branch March 17, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-base-to-string: false positive with extends error

2 participants