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

make jsx-handler-names error messages less specific #348

Merged
merged 1 commit into from
Dec 5, 2015
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
7 changes: 2 additions & 5 deletions lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@ module.exports = function(context) {

var propIsEventHandler = PROP_EVENT_HANDLER_REGEX.test(propKey);
var propFnIsNamedCorrectly = EVENT_HANDLER_REGEX.test(propValue);
var eventName;

if (propIsEventHandler && !propFnIsNamedCorrectly) {
eventName = propKey.split(eventHandlerPropPrefix)[1];
context.report(
node,
'Handler function for ' + propKey + ' prop key must be named ' + eventHandlerPrefix + eventName
'Handler function for ' + propKey + ' prop key must begin with \'' + eventHandlerPrefix + '\''
);
} else if (propFnIsNamedCorrectly && !propIsEventHandler) {
eventName = propValue.split(eventHandlerPrefix)[1];
context.report(
node,
'Prop key for ' + propValue + ' must be named ' + eventHandlerPropPrefix + eventName
'Prop key for ' + propValue + ' must begin with \'' + eventHandlerPropPrefix + '\''
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/rules/jsx-handler-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ ruleTester.run('jsx-handler-names', rule, {
ecmaFeatures: {
jsx: true
},
errors: [{message: 'Handler function for onChange prop key must be named handleChange'}]
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
}, {
code: [
'<TestComponent handleChange={this.handleChange} />'
].join('\n'),
ecmaFeatures: {
jsx: true
},
errors: [{message: 'Prop key for handleChange must be named onChange'}]
errors: [{message: 'Prop key for handleChange must begin with \'on\''}]
}, {
code: [
'<TestComponent onChange={this.onChange} />'
].join('\n'),
ecmaFeatures: {
jsx: true
},
errors: [{message: 'Handler function for onChange prop key must be named handleChange'}]
errors: [{message: 'Handler function for onChange prop key must begin with \'handle\''}]
}]
});