Skip to content

Commit

Permalink
make jsx-handler-names error messages less specific
Browse files Browse the repository at this point in the history
  • Loading branch information
jakemmarsh committed Dec 2, 2015
1 parent 8e43e51 commit abc8527
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
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\''}]
}]
});

0 comments on commit abc8527

Please sign in to comment.