Skip to content

Commit 7cf4ceb

Browse files
daviferreiraljharb
authored andcommitted
[Fix] jsx-pascal-case: Handle single character namespaced component
1 parent 9a569f7 commit 7cf4ceb

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1515
* [`prefer-read-only-props`]: support Flow `$ReadOnly` ([#2772][], [#2779][], [#2770][] @karolina-benitez)
1616
* [`jsx-handler-names`]: handle whitespace ([#2789][] @AriPerkkio)
1717
* [`prop-types`]: Detect TypeScript types for destructured default prop values ([#2780][] @sunghyunjo)
18+
* [`jsx-pascal-case`]: Handle single character namespaced component ([#2791][] @daviferreira)
1819

20+
[#2791]: https://github.com/yannickcr/eslint-plugin-react/pull/2791
1921
[#2789]: https://github.com/yannickcr/eslint-plugin-react/pull/2789
2022
[#2780]: https://github.com/yannickcr/eslint-plugin-react/pull/2780
2123
[#2779]: https://github.com/yannickcr/eslint-plugin-react/pull/2779

lib/rules/jsx-pascal-case.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ module.exports = {
9797
if (isCompatTag) return undefined;
9898

9999
let name = elementType(node);
100-
if (name.length === 1) return undefined;
101100

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

108+
if (name.length === 1) return undefined;
109+
109110
const isPascalCase = testPascalCase(name);
110111
const isAllowedAllCaps = allowAllCaps && testAllCaps(name);
111112
const isIgnored = ignore.indexOf(name) !== -1;

tests/lib/rules/jsx-pascal-case.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ ruleTester.run('jsx-pascal-case', rule, {
8282
code: '<_ />'
8383
}, {
8484
code: '<H1>Hello!</H1>'
85+
}, {
86+
code: '<Typography.P />'
8587
}],
8688

8789
invalid: [{

0 commit comments

Comments
 (0)