-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix jsx-no-bind reporting errors on render functions #676
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-no-bind reporting errors on render functions #676
Conversation
var propName = require('jsx-ast-utils/propName'); | ||
|
||
// ----------------------------------------------------------------------------- | ||
// Rule Definition | ||
// ----------------------------------------------------------------------------- | ||
|
||
module.exports = function(context) { | ||
function renderReturnsJSX(node, utils) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems like it might be common behavior that all the rules could use - and that some may already have implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Sounds like we should move it to the utils
provided by the Components
utility? What should it be named? There is already a isReturningJSX
that does the bulk of this work but this deals with finding the ReturnStatement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason that isReturningJSX
isn't already checking for a return statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It currently expects a ReturnStatement
or a ArrowFunctionExpression
to be passed in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make the default for the case statement to find a return the ReturnStatement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense for "is returning JSX" to accept any kind of function, and it should be able to accurately return a boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it to make isReturningJSX
to handle more nodes.
be3d26a
to
025305e
Compare
{ | ||
code: [ | ||
'const foo = {', | ||
' render: function() {', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we also cover the render() {
case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
JSX (Fixes jsx-eslint#663) Enhance isReturningJSX to handle more node types
025305e
to
cf0ff04
Compare
Merged, thanks! |
Fix jsx-no-bind reporting errors on render functions that don't return JSX (Fixes #663)