Skip to content

✨ Quality: Ignore decorators in throw-new-error rule#2917

Open
tang-vu wants to merge 1 commit intosindresorhus:mainfrom
tang-vu:contribai/improve/quality/ignore-decorators-in-throw-new-error-rul
Open

✨ Quality: Ignore decorators in throw-new-error rule#2917
tang-vu wants to merge 1 commit intosindresorhus:mainfrom
tang-vu:contribai/improve/quality/ignore-decorators-in-throw-new-error-rul

Conversation

@tang-vu
Copy link
Copy Markdown

@tang-vu tang-vu commented Mar 25, 2026

✨ Code Quality

Problem

The throw-new-error rule enforces that PascalCase functions containing the word "Error" are called with new. However, decorator factories like @RegisterServiceError() are conventionally PascalCase and should not require new. We need to exclude CallExpressions that are the direct child of a Decorator node from being evaluated by this rule.

Severity: high
File: rules/throw-new-error.js

Solution

The throw-new-error rule enforces that PascalCase functions containing the word "Error" are called with new. However, decorator factories like @RegisterServiceError() are conventionally PascalCase and should not require new. We need to exclude CallExpressions that are the direct child of a Decorator node from being evaluated by this rule.

Changes

  • rules/throw-new-error.js (modified)

🤖 About this PR

This pull request was generated by ContribAI, an AI agent
that helps improve open source projects. The change was:

  1. Discovered by automated code analysis
  2. Generated by AI with context-aware code generation
  3. Self-reviewed by AI quality checks

If you have questions or feedback about this PR, please comment below.
We appreciate your time reviewing this contribution!

Closes #2360

The `throw-new-error` rule enforces that PascalCase functions containing the word "Error" are called with `new`. However, decorator factories like `@RegisterServiceError()` are conventionally PascalCase and should not require `new`. We need to exclude `CallExpression`s that are the direct child of a `Decorator` node from being evaluated by this rule.

Affected files: throw-new-error.js

Signed-off-by: Tang Vu <vuminhtang2212@gmail.com>
@github-actions github-actions Bot changed the title ✨ Quality: Ignore decorators in throw-new-error rule ✨ Quality: Ignore decorators in throw-new-error rule Mar 25, 2026
@sindresorhus
Copy link
Copy Markdown
Owner

This looks correct to me, but I think it needs a regression test before merging.

@sindresorhus sindresorhus force-pushed the main branch 4 times, most recently from 814b622 to 0e023e3 Compare April 2, 2026 12:41
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.

throw-new-error false positive on decorator calls

2 participants