diff --git a/docs/rules/jsx-no-bind.md b/docs/rules/jsx-no-bind.md index 9218335aba..cc2ca5eee7 100644 --- a/docs/rules/jsx-no-bind.md +++ b/docs/rules/jsx-no-bind.md @@ -18,6 +18,41 @@ The following patterns are not considered warnings:
``` +## Rule Options + +```js +"jsx-no-bind": [, { + "ignoreRefs": || false, + "allowArrowFunctions": || false, + "allowBind": || false +}] +``` + +### `ignoreRefs` + +When `true` the following are not considered warnings: + +```jsx +
this._div = c} /> +
+``` + +### `allowArrowFunctions` + +When `true` the following is not considered a warning: + +```jsx +
alert("1337")} /> +``` + +### `allowBind` + +When `true` the following is not considered a warning: + +```jsx +
+``` + ## Protips ### Lists of Items diff --git a/lib/rules/jsx-no-bind.js b/lib/rules/jsx-no-bind.js index e366a005ce..349741c80e 100644 --- a/lib/rules/jsx-no-bind.js +++ b/lib/rules/jsx-no-bind.js @@ -14,7 +14,8 @@ module.exports = function(context) { return { JSXAttribute: function(node) { - if (!node.value || !node.value.expression) { + var isRef = configuration.ignoreRefs && node.name.name === 'ref'; + if (isRef || !node.value || !node.value.expression) { return; } var valueNode = node.value.expression; @@ -45,6 +46,10 @@ module.exports.schema = [{ allowBind: { default: false, type: 'boolean' + }, + ignoreRefs: { + default: false, + type: 'boolean' } }, additionalProperties: false diff --git a/tests/lib/rules/jsx-no-bind.js b/tests/lib/rules/jsx-no-bind.js index 89e23ae9b1..e751ab32c1 100644 --- a/tests/lib/rules/jsx-no-bind.js +++ b/tests/lib/rules/jsx-no-bind.js @@ -34,6 +34,18 @@ ruleTester.run('jsx-no-bind', rule, { parser: 'babel-eslint' }, + // bind() and arrow functions in refs explicitly ignored + { + code: '
this._input = c}>
', + options: [{ignoreRefs: true}], + parser: 'babel-eslint' + }, + { + code: '
', + options: [{ignoreRefs: true}], + parser: 'babel-eslint' + }, + // bind() explicitly allowed { code: '
', @@ -66,6 +78,11 @@ ruleTester.run('jsx-no-bind', rule, { errors: [{message: 'JSX props should not use .bind()'}], parser: 'babel-eslint' }, + { + code: '
', + errors: [{message: 'JSX props should not use .bind()'}], + parser: 'babel-eslint' + }, // Arrow functions { @@ -82,6 +99,11 @@ ruleTester.run('jsx-no-bind', rule, { code: '
{ first(); second(); }}>
', errors: [{message: 'JSX props should not use arrow functions'}], parser: 'babel-eslint' + }, + { + code: '
this._input = c}>
', + errors: [{message: 'JSX props should not use arrow functions'}], + parser: 'babel-eslint' } ] });