Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] jsx-pascal-case: Support unicode characters #2557

Merged
merged 1 commit into from Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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