sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules
MIT License
3.98k stars 361 forks source link

throw-new-error false positive #2360

Open brokenmass opened 1 month ago

brokenmass commented 1 month ago

after last release throw new error reports any call to function that are PascalCase and contains the word “Error” as invalid.

Example:

‘’’ const ParseError = () => 0;

// this is reported as invalid cont result = ParseError(); ‘’’

In my specific case I’m getting the error when using a class decorator to track custom error classes

‘’’ @RegisterServiceError() class SomeError extends BaseError {} ’’’

easiest solution would be to at least allow a list of name exceptions to the rule.

fregante commented 1 month ago

It's not quite clear why that should be valid. Generally only classes and JSX functions should be in pascal case. RegisterServiceError is neither so it should be registerServiceError and it's automatically ignored by the rule.

brokenmass commented 1 month ago

Using PascalCase for decorators (especially decorators factories) is pretty much standard.

Said so, using PascalCase only for classes and components is a naming convention, not a js requirement. It’s like getting a false positive because the line is indented with tabs instead of with spaces. This plugin should not rely on such conventions and/or allow the user to configure alternative regexes or exceptions