Skip to content

Commit

Permalink
[Fix] jsx-pascal-case: Handle single character namespaced component
Browse files Browse the repository at this point in the history
  • Loading branch information
daviferreira authored and ljharb committed Sep 10, 2020
1 parent 9a569f7 commit 7cf4ceb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
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

0 comments on commit 7cf4ceb

Please sign in to comment.