Skip to content

fix(restrict-plus-operands): report actual type instead of always reporting RegExp#786

Merged
camc314 merged 3 commits intooxc-project:mainfrom
younggglcy:candied-toaster
Mar 10, 2026
Merged

fix(restrict-plus-operands): report actual type instead of always reporting RegExp#786
camc314 merged 3 commits intooxc-project:mainfrom
younggglcy:candied-toaster

Conversation

@younggglcy
Copy link
Copy Markdown
Contributor

Summary

  • Fix checkInvalidPlusOperand to return the actual type string (baseTypeString) instead of always returning globalRegexpType for any invalid object-like operand.
  • Add test cases for Date type operands ('' + new Date(), d + '', new Date() + new Date()).
  • Add CLAUDE.md symlink to AGENTS.md.

Ref #518 (fixes the first part: error message reporting RegExp instead of the actual type)

Test plan

  • go test ./internal/rules/restrict_plus_operands/... passes
  • go test ./internal/... passes
  • Snapshot diffs show correct type names (e.g. Date, never[], {}, Valued, A) instead of RegExp

younggglcy and others added 2 commits March 10, 2026 23:40
…orting RegExp

When an invalid object-like operand (e.g. Date, Array, plain object) was
used in a '+' operation, the error message always reported the type as
'RegExp' regardless of the actual type. This was because
`checkInvalidPlusOperand` unconditionally returned `globalRegexpType` for
any invalid object type.

Now the function returns `baseTypeString` (the actual type) instead,
so `'' + new Date()` correctly reports `Date` in the diagnostic.

Ref oxc-project#518
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 10, 2026 17:28
@camc314 camc314 self-assigned this Mar 10, 2026
@camc314 camc314 merged commit 168d402 into oxc-project:main Mar 10, 2026
7 checks passed
@younggglcy younggglcy deleted the candied-toaster branch March 10, 2026 17:38
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.

2 participants