Skip to content

Commit 6b42731

Browse files
apbarreroljharb
authored andcommitted
[Fix] display-name: fix identifying _ as a capital letter
Fixes #3334
1 parent 87fb344 commit 6b42731

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1515
* [`jsx-key`]: avoid a crash from optional chaining from [#3320][] ([#3327][] @ljharb)
1616
* [`jsx-key`]: avoid a crash on a non-array node.body from [#3320][] ([#3328][] @ljharb)
1717
* [`display-name`]: fix false positive for assignment of function returning null ([#3331][] @apbarrero)
18+
* [`display-name`]: fix identifying `_` as a capital letter ([#3335][] @apbarrero)
1819

1920
### Changed
2021
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
@@ -23,6 +24,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2324
* [Docs] `sort-comp`: add class component examples ([#3339][] @maurer2)
2425

2526
[#3339]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3339
27+
[#3335]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3335
2628
[#3331]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3331
2729
[#3328]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3328
2830
[#3327]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3327

lib/util/isFirstLetterCapitalized.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @returns {Boolean} True if first letter is capitalized.
77
*/
88
function isFirstLetterCapitalized(word) {
9-
if (!word) {
9+
if (!word || word.charAt(0) === '_') {
1010
return false;
1111
}
1212
const firstLetter = word.charAt(0);

tests/lib/rules/display-name.js

+18
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,24 @@ ruleTester.run('display-name', rule, {
597597
return f(a);
598598
};`,
599599
},
600+
{
601+
// issue #3334
602+
code: `
603+
obj._property = (a) => {
604+
if (a == null) return null;
605+
return f(a);
606+
};
607+
`,
608+
},
609+
{
610+
// issue #3334
611+
code: `
612+
_variable = (a) => {
613+
if (a == null) return null;
614+
return f(a);
615+
};
616+
`,
617+
},
600618
{
601619
// issue #3303
602620
code: `

tests/util/isFirstLetterCapitalized.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ describe('isFirstLetterCapitalized', () => {
1414
it('should return false for uncapitalized string', () => {
1515
assert.equal(isFirstLetterCapitalized('isCapitalized'), false);
1616
assert.equal(isFirstLetterCapitalized('lowercase'), false);
17+
assert.equal(isFirstLetterCapitalized('_startsWithUnderscore'), false);
18+
assert.equal(isFirstLetterCapitalized('_StartsWithUnderscore'), false);
1719
});
1820

1921
it('should return true for capitalized string', () => {

0 commit comments

Comments
 (0)