From e7f7e89d96b2aa6e250dba05bedee78dfd38de17 Mon Sep 17 00:00:00 2001 From: Harry Mills Date: Wed, 28 Aug 2019 14:23:30 -0400 Subject: [PATCH] [fix] `jsx-pascal-case`: allow one-letter-named components 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 | 1 + tests/lib/rules/jsx-pascal-case.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/rules/jsx-pascal-case.js b/lib/rules/jsx-pascal-case.js index 268755c2e1..fb8ea45427 100644 --- a/lib/rules/jsx-pascal-case.js +++ b/lib/rules/jsx-pascal-case.js @@ -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) { diff --git a/tests/lib/rules/jsx-pascal-case.js b/tests/lib/rules/jsx-pascal-case.js index 0a17cd4ef8..f0965730f2 100644 --- a/tests/lib/rules/jsx-pascal-case.js +++ b/tests/lib/rules/jsx-pascal-case.js @@ -59,6 +59,12 @@ ruleTester.run('jsx-pascal-case', rule, { }, { code: '', options: [{ignore: ['IGNORED']}] + }, { + code: '' + }, { + code: '<$ />' + }, { + code: '<_ />' }], invalid: [{ @@ -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'}] }] });