From 3b5cf97234a10794a5dfcf7be934e44425fbee07 Mon Sep 17 00:00:00 2001 From: Nat Burns Date: Sun, 29 Mar 2015 17:45:03 +0000 Subject: [PATCH] Check for computed property names in prop-types. --- lib/rules/prop-types.js | 2 +- tests/lib/rules/prop-types.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index 763f812c64..ee08c5a923 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -129,7 +129,7 @@ module.exports = function(context) { function markPropTypesAsUsed(node) { var component = getComponent(node); var type; - if (node.parent.property && node.parent.property.name) { + if (node.parent.property && node.parent.property.name && !node.parent.computed) { type = 'direct'; } else if ( node.parent.parent.declarations && diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 3fbadc57f6..0e5ed0c2d5 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -81,6 +81,18 @@ eslintTester.addRuleTest('lib/rules/prop-types', { ecmaFeatures: { jsx: true } + }, { + code: [ + 'var Hello = React.createClass({', + ' render: function() {', + ' var propName = "foo";', + ' return
Hello World {this.props[propName]}
;', + ' }', + '});' + ].join('\n'), + ecmaFeatures: { + jsx: true + } }, { code: [ 'var Hello = React.createClass({',