Skip to content
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

[Fix] jsx-pascal-case: Handle single character namespaced component #2791

Merged
merged 1 commit into from Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,7 +15,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`prefer-read-only-props`]: support Flow `$ReadOnly` ([#2772][], [#2779][], [#2770][] @karolina-benitez)
* [`jsx-handler-names`]: handle whitespace ([#2789][] @AriPerkkio)
* [`prop-types`]: Detect TypeScript types for destructured default prop values ([#2780][] @sunghyunjo)
* [`jsx-pascal-case`]: Handle single character namespaced component ([#2791][] @daviferreira)

[#2791]: https://github.com/yannickcr/eslint-plugin-react/pull/2791
[#2789]: https://github.com/yannickcr/eslint-plugin-react/pull/2789
[#2780]: https://github.com/yannickcr/eslint-plugin-react/pull/2780
[#2779]: https://github.com/yannickcr/eslint-plugin-react/pull/2779
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/jsx-pascal-case.js
Expand Up @@ -97,7 +97,6 @@ module.exports = {
if (isCompatTag) return undefined;

let name = elementType(node);
if (name.length === 1) return undefined;

// Get JSXIdentifier if the type is JSXNamespacedName or JSXMemberExpression
if (name.lastIndexOf(':') > -1) {
Expand All @@ -106,6 +105,8 @@ module.exports = {
name = name.substring(name.lastIndexOf('.') + 1);
}

if (name.length === 1) return undefined;

const isPascalCase = testPascalCase(name);
const isAllowedAllCaps = allowAllCaps && testAllCaps(name);
const isIgnored = ignore.indexOf(name) !== -1;
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/jsx-pascal-case.js
Expand Up @@ -82,6 +82,8 @@ ruleTester.run('jsx-pascal-case', rule, {
code: '<_ />'
}, {
code: '<H1>Hello!</H1>'
}, {
code: '<Typography.P />'
}],

invalid: [{
Expand Down