Skip to content

Commit 9ce69a2

Browse files
AriPerkkioljharb
authored andcommitted
[Fix] jsx-handler-names: handle whitespace
Fixes #2785
1 parent de2ec66 commit 9ce69a2

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1313
* [`function-component-definition`]: ignore object properties ([#2771][] @stefan-wullems)
1414
* [`forbid-component-props`]: Implemented support for "namespaced" components ([#2767][] @mnn)
1515
* [`prefer-read-only-props`]: support Flow `$ReadOnly` ([#2772][], [#2779][], [#2770][] @karolina-benitez)
16+
* [`jsx-handler-names`]: handle whitespace ([#2789][] @AriPerkkio)
1617

18+
[#2789]: https://github.com/yannickcr/eslint-plugin-react/pull/2789
1719
[#2779]: https://github.com/yannickcr/eslint-plugin-react/pull/2779
1820
[#2772]: https://github.com/yannickcr/eslint-plugin-react/pull/2772
1921
[#2771]: https://github.com/yannickcr/eslint-plugin-react/pull/2771

lib/rules/jsx-handler-names.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ module.exports = {
121121
const expression = node.value.expression;
122122
const propValue = context.getSourceCode()
123123
.getText(checkInlineFunction && isInlineHandler(node) ? expression.body.callee : expression)
124+
.replace(/\s*/g, '')
124125
.replace(/^this\.|.*::/, '');
125126

126127
if (propKey === 'ref') {

tests/lib/rules/jsx-handler-names.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ ruleTester.run('jsx-handler-names', rule, {
3232
code: '<TestComponent onChange={this.handleChange} />'
3333
}, {
3434
code: '<TestComponent onChange={this.props.onChange} />'
35+
},
36+
{
37+
code: `<TestComponent
38+
onChange={
39+
this
40+
.handleChange
41+
} />`
42+
}, {
43+
code: `<TestComponent
44+
onChange={
45+
this
46+
.props
47+
.handleChange
48+
} />`
3549
}, {
3650
code: '<TestComponent onChange={handleChange} />',
3751
options: [{

0 commit comments

Comments
 (0)