Skip to content

Commit

Permalink
[Fix] jsx-pascal-case: fix a false positive with "H1"
Browse files Browse the repository at this point in the history
Fixes #2683; caused by #2636.
  • Loading branch information
ljharb committed Jun 29, 2020
1 parent d2a131a commit c65b79e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/rules/jsx-pascal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ function testPascalCase(name) {
if (!testUpperCase(name.charAt(0))) {
return false;
}
let atLeastOneLowerCase = false;
for (let i = 1; i < name.length; i += 1) {
const char = name.charAt(i);
if (!(char.toLowerCase() !== char.toUpperCase() || testDigit(char))) {
return false;
}
if (!atLeastOneLowerCase) {
atLeastOneLowerCase = testLowerCase(char);
}
const anyNonAlphaNumeric = Array.prototype.some.call(
name.slice(1),
(char) => char.toLowerCase() === char.toUpperCase() && !testDigit(char)
);
if (anyNonAlphaNumeric) {
return false;
}
return atLeastOneLowerCase;
return Array.prototype.some.call(
name.slice(1),
(char) => testLowerCase(char) || testDigit(char)
);
}

function testAllCaps(name) {
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/jsx-pascal-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ ruleTester.run('jsx-pascal-case', rule, {
code: '<$ />'
}, {
code: '<_ />'
}, {
code: '<H1>Hello!</H1>'
}],

invalid: [{
Expand Down

0 comments on commit c65b79e

Please sign in to comment.