Skip to content

Commit

Permalink
[fix] jsx-pascal-case: allow one-letter-named components
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Haegin authored and ljharb committed Aug 28, 2019
1 parent 5f00ad2 commit e7f7e89
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/jsx-pascal-case.js
Expand Up @@ -51,6 +51,7 @@ module.exports = {
return {
JSXOpeningElement(node) {
let name = elementType(node);
if (name.length === 1) return undefined;

// Get namespace if the type is JSXNamespacedName or JSXMemberExpression
if (name.indexOf(':') > -1) {
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/jsx-pascal-case.js
Expand Up @@ -59,6 +59,12 @@ ruleTester.run('jsx-pascal-case', rule, {
}, {
code: '<IGNORED />',
options: [{ignore: ['IGNORED']}]
}, {
code: '<T />'
}, {
code: '<$ />'
}, {
code: '<_ />'
}],

invalid: [{
Expand All @@ -82,5 +88,8 @@ ruleTester.run('jsx-pascal-case', rule, {
code: '<__ />',
options: [{allowAllCaps: true}],
errors: [{message: 'Imported JSX component __ must be in PascalCase or SCREAMING_SNAKE_CASE'}]
}, {
code: '<$a />',
errors: [{message: 'Imported JSX component $a must be in PascalCase'}]
}]
});

0 comments on commit e7f7e89

Please sign in to comment.