Skip to content

Commit

Permalink
[New] jsx-pascal-case: Support unicode characters
Browse files Browse the repository at this point in the history
Fixes #1654
  • Loading branch information
Svish authored and ljharb committed Jan 29, 2020
1 parent 43e466c commit 598277e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/rules/jsx-pascal-case.js
Expand Up @@ -6,15 +6,19 @@
'use strict';

const elementType = require('jsx-ast-utils/elementType');
const XRegExp = require('xregexp');
const docsUrl = require('../util/docsUrl');
const jsxUtil = require('../util/jsx');

// ------------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------------

const PASCAL_CASE_REGEX = /^(.*[.])*([A-Z]|[A-Z]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/;
const ALL_CAPS_TAG_REGEX = /^[A-Z0-9]+([A-Z0-9_]*[A-Z0-9]+)?$/;
// eslint-disable-next-line no-new
const hasU = (function hasU() { try { new RegExp('o', 'u'); return true; } catch (e) { return false; } }());

const PASCAL_CASE_REGEX = XRegExp('^(.*[.])*([\\p{Lu}]|[\\p{Lu}]+[\\p{Ll}0-9]+(?:[\\p{Lu}0-9]+[\\p{Ll}0-9]*)*)$', hasU ? 'u' : '');
const ALL_CAPS_TAG_REGEX = XRegExp('^[\\p{Lu}0-9]+([\\p{Lu}0-9_]*[\\p{Lu}0-9]+)?$', hasU ? 'u' : '');

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -37,7 +37,8 @@
"object.values": "^1.1.1",
"prop-types": "^15.7.2",
"resolve": "^1.14.2",
"string.prototype.matchall": "^4.0.2"
"string.prototype.matchall": "^4.0.2",
"xregexp": "^4.2.4"
},
"devDependencies": {
"@types/eslint": "^6.1.3",
Expand Down
6 changes: 5 additions & 1 deletion tests/lib/rules/jsx-pascal-case.js
Expand Up @@ -47,7 +47,11 @@ ruleTester.run('jsx-pascal-case', rule, {
}, {
code: '<T3StComp0Nent />'
}, {
code: '<T />'
code: '<Éurströmming />'
}, {
code: '<Año />'
}, {
code: '<Søknad />'
}, {
code: '<T />',
parser: parsers.BABEL_ESLINT
Expand Down

0 comments on commit 598277e

Please sign in to comment.