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
  • Loading branch information
apbarrero committed Jul 13, 2022
1 parent bdbd2a4 commit 34b54b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/util/isFirstLetterCapitalized.js
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
16 changes: 16 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -597,6 +597,22 @@ 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
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 34b54b0

Please sign in to comment.