Skip to content

Commit

Permalink
[Fix] display-name: fix identifying _ as a capital letter
Browse files Browse the repository at this point in the history
Fixes #3334
  • Loading branch information
apbarrero authored and ljharb committed Jul 18, 2022
1 parent 87fb344 commit 6b42731
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
* [`jsx-key`]: avoid a crash from optional chaining from [#3320][] ([#3327][] @ljharb)
* [`jsx-key`]: avoid a crash on a non-array node.body from [#3320][] ([#3328][] @ljharb)
* [`display-name`]: fix false positive for assignment of function returning null ([#3331][] @apbarrero)
* [`display-name`]: fix identifying `_` as a capital letter ([#3335][] @apbarrero)

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

[#3339]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3339
[#3335]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3335
[#3331]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3331
[#3328]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3328
[#3327]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3327
Expand Down
2 changes: 1 addition & 1 deletion lib/util/isFirstLetterCapitalized.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @returns {Boolean} True if first letter is capitalized.
*/
function isFirstLetterCapitalized(word) {
if (!word) {
if (!word || word.charAt(0) === '_') {
return false;
}
const firstLetter = word.charAt(0);
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,24 @@ ruleTester.run('display-name', rule, {
return f(a);
};`,
},
{
// issue #3334
code: `
obj._property = (a) => {
if (a == null) return null;
return f(a);
};
`,
},
{
// issue #3334
code: `
_variable = (a) => {
if (a == null) return null;
return f(a);
};
`,
},
{
// issue #3303
code: `
Expand Down
2 changes: 2 additions & 0 deletions tests/util/isFirstLetterCapitalized.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe('isFirstLetterCapitalized', () => {
it('should return false for uncapitalized string', () => {
assert.equal(isFirstLetterCapitalized('isCapitalized'), false);
assert.equal(isFirstLetterCapitalized('lowercase'), false);
assert.equal(isFirstLetterCapitalized('_startsWithUnderscore'), false);
assert.equal(isFirstLetterCapitalized('_StartsWithUnderscore'), false);
});

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

0 comments on commit 6b42731

Please sign in to comment.