Skip to content

Commit 598277e

Browse files
Svishljharb
authored andcommitted
[New] jsx-pascal-case: Support unicode characters
Fixes #1654
1 parent 43e466c commit 598277e

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/rules/jsx-pascal-case.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66
'use strict';
77

88
const elementType = require('jsx-ast-utils/elementType');
9+
const XRegExp = require('xregexp');
910
const docsUrl = require('../util/docsUrl');
1011
const jsxUtil = require('../util/jsx');
1112

1213
// ------------------------------------------------------------------------------
1314
// Constants
1415
// ------------------------------------------------------------------------------
1516

16-
const PASCAL_CASE_REGEX = /^(.*[.])*([A-Z]|[A-Z]+[a-z0-9]+(?:[A-Z0-9]+[a-z0-9]*)*)$/;
17-
const ALL_CAPS_TAG_REGEX = /^[A-Z0-9]+([A-Z0-9_]*[A-Z0-9]+)?$/;
17+
// eslint-disable-next-line no-new
18+
const hasU = (function hasU() { try { new RegExp('o', 'u'); return true; } catch (e) { return false; } }());
19+
20+
const PASCAL_CASE_REGEX = XRegExp('^(.*[.])*([\\p{Lu}]|[\\p{Lu}]+[\\p{Ll}0-9]+(?:[\\p{Lu}0-9]+[\\p{Ll}0-9]*)*)$', hasU ? 'u' : '');
21+
const ALL_CAPS_TAG_REGEX = XRegExp('^[\\p{Lu}0-9]+([\\p{Lu}0-9_]*[\\p{Lu}0-9]+)?$', hasU ? 'u' : '');
1822

1923
// ------------------------------------------------------------------------------
2024
// Rule Definition

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"object.values": "^1.1.1",
3838
"prop-types": "^15.7.2",
3939
"resolve": "^1.14.2",
40-
"string.prototype.matchall": "^4.0.2"
40+
"string.prototype.matchall": "^4.0.2",
41+
"xregexp": "^4.2.4"
4142
},
4243
"devDependencies": {
4344
"@types/eslint": "^6.1.3",

tests/lib/rules/jsx-pascal-case.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ ruleTester.run('jsx-pascal-case', rule, {
4747
}, {
4848
code: '<T3StComp0Nent />'
4949
}, {
50-
code: '<T />'
50+
code: '<Éurströmming />'
51+
}, {
52+
code: '<Año />'
53+
}, {
54+
code: '<Søknad />'
5155
}, {
5256
code: '<T />',
5357
parser: parsers.BABEL_ESLINT

0 commit comments

Comments
 (0)