diff --git a/lib/rules/jsx-no-bind.js b/lib/rules/jsx-no-bind.js index f16bb5ecde..def107f5f9 100644 --- a/lib/rules/jsx-no-bind.js +++ b/lib/rules/jsx-no-bind.js @@ -81,6 +81,12 @@ module.exports = { node.callee.property.name === 'bind' ) { return 'bindCall'; + } else if ( + nodeType === 'ConditionalExpression' + ) { + return getNodeViolationType(node.test) || + getNodeViolationType(node.consequent) || + getNodeViolationType(node.alternate); } else if ( !configuration.allowArrowFunctions && nodeType === 'ArrowFunctionExpression' @@ -154,7 +160,7 @@ module.exports = { } }, - JSXAttribute: function(node) { + JSXAttribute: function (node) { const isRef = configuration.ignoreRefs && propName(node) === 'ref'; if (isRef || !node.value || !node.value.expression) { return; diff --git a/tests/lib/rules/jsx-no-bind.js b/tests/lib/rules/jsx-no-bind.js index 244acaed56..05f8b264d7 100644 --- a/tests/lib/rules/jsx-no-bind.js +++ b/tests/lib/rules/jsx-no-bind.js @@ -397,6 +397,47 @@ ruleTester.run('jsx-no-bind', rule, { ], parser: 'babel-eslint' }, + { + code: ` + const foo = { + render: ({onClick}) => ( +
Hello
+ ) + }; + `, + errors: [{message: 'JSX props should not use .bind()'}] + }, + { + code: ` + const foo = { + render: ({onClick}) => ( +
Hello
+ ) + }; + `, + errors: [{message: 'JSX props should not use .bind()'}] + }, + { + code: ` + const foo = { + render: ({onClick}) => ( +
Hello
+ ) + }; + `, + errors: [{message: 'JSX props should not use .bind()'}] + }, + { + code: ` + const foo = { + render: ({onClick}) => ( +
Hello
+ ) + }; + `, + errors: [{message: 'JSX props should not use .bind()'}] + }, + // Arrow functions {