-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[jsx-pascal-case] Components can with $ or _ #2395
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixes #2394. $ and _ are valid names for components that are neither upper nor lower case. This change ensures the pascal case rule doesn't apply to single letter components
lib/rules/jsx-pascal-case.js
Outdated
@@ -13,7 +13,7 @@ const jsxUtil = require('../util/jsx'); | |||
// Constants | |||
// ------------------------------------------------------------------------------ | |||
|
|||
const PASCAL_CASE_REGEX = /^([A-Z0-9]|[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/; | |||
const PASCAL_CASE_REGEX = /^([$_A-Z0-9]|[$_]?[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe instead of this - which could allow much more complex patterns - we just bail out if [...name].length === 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would certainly work for me. Do we still want to disallow a single lowercase letter as the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since anything that starts lowercase isn't a custom component, it's an html component, i don't think this rule would warn on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cool, in which case I'll make that change. Thanks.
Fixes #2394.
$ and _ are valid names for components that are neither upper nor lower
case. This change ensures the pascal case rule only applies to the rest
of the component name (if any).