Skip to content

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

Merged

Conversation

petersendidit
Copy link
Contributor

Fix jsx-no-bind reporting errors on render functions that don't return JSX (Fixes #663)

var propName = require('jsx-ast-utils/propName');

// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------

module.exports = function(context) {
function renderReturnsJSX(node, utils) {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Member

@ljharb ljharb Jul 12, 2016

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.

Copy link
Contributor Author

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.

@petersendidit petersendidit force-pushed the jsx-no-bind-rendermethods branch from be3d26a to 025305e Compare July 12, 2016 16:05
{
code: [
'const foo = {',
' render: function() {',
Copy link
Member

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?

Copy link
Contributor Author

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
@petersendidit petersendidit force-pushed the jsx-no-bind-rendermethods branch from 025305e to cf0ff04 Compare July 13, 2016 13:57
@yannickcr yannickcr merged commit ae5a43b into jsx-eslint:master Jul 14, 2016
@yannickcr
Copy link
Member

Merged, thanks!

@petersendidit petersendidit deleted the jsx-no-bind-rendermethods branch August 8, 2016 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants