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] jsx-handler-names: handle whitespace #2789

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,7 +13,9 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
* [`function-component-definition`]: ignore object properties ([#2771][] @stefan-wullems)
* [`forbid-component-props`]: Implemented support for "namespaced" components ([#2767][] @mnn)
* [`prefer-read-only-props`]: support Flow `$ReadOnly` ([#2772][], [#2779][], [#2770][] @karolina-benitez)
* [`jsx-handler-names`]: handle whitespace ([#2789][] @AriPerkkio)

[#2789]: https://github.com/yannickcr/eslint-plugin-react/pull/2789
[#2779]: https://github.com/yannickcr/eslint-plugin-react/pull/2779
[#2772]: https://github.com/yannickcr/eslint-plugin-react/pull/2772
[#2771]: https://github.com/yannickcr/eslint-plugin-react/pull/2771
Expand Down
1 change: 1 addition & 0 deletions lib/rules/jsx-handler-names.js
Expand Up @@ -121,6 +121,7 @@ module.exports = {
const expression = node.value.expression;
const propValue = context.getSourceCode()
.getText(checkInlineFunction && isInlineHandler(node) ? expression.body.callee : expression)
.replace(/\s*/g, '')
.replace(/^this\.|.*::/, '');

if (propKey === 'ref') {
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/jsx-handler-names.js
Expand Up @@ -32,6 +32,20 @@ ruleTester.run('jsx-handler-names', rule, {
code: '<TestComponent onChange={this.handleChange} />'
}, {
code: '<TestComponent onChange={this.props.onChange} />'
},
{
code: `<TestComponent
onChange={
this
.handleChange
} />`
}, {
code: `<TestComponent
onChange={
this
.props
.handleChange
} />`
}, {
code: '<TestComponent onChange={handleChange} />',
options: [{
Expand Down