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

[Fix] display-name: fix identifying _ as a capital letter #3335

Merged
merged 1 commit into from
Jul 18, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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