diff --git a/docs/rules/jsx-pascal-case.md b/docs/rules/jsx-pascal-case.md index 00af2eb013..462e59876d 100644 --- a/docs/rules/jsx-pascal-case.md +++ b/docs/rules/jsx-pascal-case.md @@ -46,7 +46,16 @@ The following patterns are **not** considered warnings: * `enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0. * `allowAllCaps`: optional boolean set to `true` to allow components name in all caps (default to `false`). -* `ignore`: optional array of components name to ignore during validation. +* `ignore`: optional string-array of component names to ignore during validation. + +### `allowAllCaps` + +The following patterns are **not** considered warnings when `allowAllCaps` is `true`: + +```jsx + + +``` ## When Not To Use It diff --git a/lib/rules/jsx-pascal-case.js b/lib/rules/jsx-pascal-case.js index 34de9ae67b..268755c2e1 100644 --- a/lib/rules/jsx-pascal-case.js +++ b/lib/rules/jsx-pascal-case.js @@ -14,7 +14,7 @@ const jsxUtil = require('../util/jsx'); // ------------------------------------------------------------------------------ const PASCAL_CASE_REGEX = /^([A-Z0-9]|[A-Z0-9]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/; -const ALL_CAPS_TAG_REGEX = /^[A-Z0-9]+$/; +const ALL_CAPS_TAG_REGEX = /^[A-Z0-9]+([A-Z0-9_]*[A-Z0-9]+)?$/; // ------------------------------------------------------------------------------ // Rule Definition @@ -65,10 +65,13 @@ module.exports = { const isIgnored = ignore.indexOf(name) !== -1; if (!isPascalCase && !isCompatTag && !isAllowedAllCaps && !isIgnored) { - context.report({ - node, - message: `Imported JSX component ${name} must be in PascalCase` - }); + let message = `Imported JSX component ${name} must be in PascalCase`; + + if (allowAllCaps) { + message += ' or SCREAMING_SNAKE_CASE'; + } + + context.report({node, message}); } } }; diff --git a/tests/lib/rules/jsx-pascal-case.js b/tests/lib/rules/jsx-pascal-case.js index 38e108dae6..0a17cd4ef8 100644 --- a/tests/lib/rules/jsx-pascal-case.js +++ b/tests/lib/rules/jsx-pascal-case.js @@ -49,6 +49,9 @@ ruleTester.run('jsx-pascal-case', rule, { }, { code: '', options: [{allowAllCaps: true}] + }, { + code: '', + options: [{allowAllCaps: true}] }, { code: '' }, { @@ -67,5 +70,17 @@ ruleTester.run('jsx-pascal-case', rule, { }, { code: '', errors: [{message: 'Imported JSX component YMCA must be in PascalCase'}] + }, { + code: '<_TEST_COMPONENT />', + options: [{allowAllCaps: true}], + errors: [{message: 'Imported JSX component _TEST_COMPONENT must be in PascalCase or SCREAMING_SNAKE_CASE'}] + }, { + code: '', + options: [{allowAllCaps: true}], + errors: [{message: 'Imported JSX component TEST_COMPONENT_ must be in PascalCase or SCREAMING_SNAKE_CASE'}] + }, { + code: '<__ />', + options: [{allowAllCaps: true}], + errors: [{message: 'Imported JSX component __ must be in PascalCase or SCREAMING_SNAKE_CASE'}] }] });