Skip to content

Commit

Permalink
Revert change on COMPAT_TAG_REGEX
Browse files Browse the repository at this point in the history
  • Loading branch information
yacinehmito committed May 9, 2020
1 parent 70184a8 commit f545193
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 4 additions & 10 deletions lib/rules/jsx-pascal-case.js
Expand Up @@ -24,11 +24,6 @@ const ALL_CAPS_TAG_REGEX = XRegExp('^[\\p{Lu}0-9]+([\\p{Lu}0-9_]*[\\p{Lu}0-9]+)?
// Rule Definition
// ------------------------------------------------------------------------------

function testLowerCase(char) {
const lowerCase = char.toLowerCase();
return char === lowerCase && lowerCase !== char.toUpperCase();
}

module.exports = {
meta: {
docs: {
Expand Down Expand Up @@ -59,11 +54,11 @@ module.exports = {

return {
JSXOpeningElement(node) {
const isCompatTag = jsxUtil.isDOMComponent(node);
if (isCompatTag) return undefined;

let name = elementType(node);
if (name.length === 1) return undefined;
if (testLowerCase(name.charAt(0))) {
return undefined;
}

// Get JSXIdentifier if the type is JSXNamespacedName or JSXMemberExpression
if (name.lastIndexOf(':') > -1) {
Expand All @@ -73,11 +68,10 @@ module.exports = {
}

const isPascalCase = PASCAL_CASE_REGEX.test(name);
const isCompatTag = jsxUtil.isDOMComponent(node);
const isAllowedAllCaps = allowAllCaps && ALL_CAPS_TAG_REGEX.test(name);
const isIgnored = ignore.indexOf(name) !== -1;

if (!isPascalCase && !isCompatTag && !isAllowedAllCaps && !isIgnored) {
if (!isPascalCase && !isAllowedAllCaps && !isIgnored) {
let message = `Imported JSX component ${name} must be in PascalCase`;

if (allowAllCaps) {
Expand Down
6 changes: 4 additions & 2 deletions lib/util/jsx.js
Expand Up @@ -6,10 +6,12 @@

const elementType = require('jsx-ast-utils/elementType');

const COMPAT_TAG_REGEX = /^[a-z][a-zA-Z-]*$/;
// See https://github.com/babel/babel/blob/ce420ba51c68591e057696ef43e028f41c6e04cd/packages/babel-types/src/validators/react/isCompatTag.js
// for why we only test for the first character
const COMPAT_TAG_REGEX = /^[a-z]/;

/**
* Checks if a node represents a DOM element.
* Checks if a node represents a DOM element according to React.
* @param {object} node - JSXOpeningElement to check.
* @returns {boolean} Whether or not the node corresponds to a DOM element.
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/jsx-pascal-case.js
Expand Up @@ -56,6 +56,8 @@ ruleTester.run('jsx-pascal-case', rule, {
code: '<Año />'
}, {
code: '<Søknad />'
}, {
code: '<T />'
}, {
code: '<T />',
parser: parsers.BABEL_ESLINT
Expand Down

0 comments on commit f545193

Please sign in to comment.