Skip to content

Commit 48f67ad

Browse files
committed
Fix variables detection when searching for related components (fixes #303)
1 parent 4787aa0 commit 48f67ad

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/util/Components.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
var util = require('util');
8+
var variableUtil = require('./variable');
89

910
/**
1011
* Components
@@ -265,7 +266,7 @@ function componentRule(rule, context) {
265266
return null;
266267
}
267268
var variableInScope;
268-
var variables = context.getScope().variables;
269+
var variables = variableUtil.variablesInScope(context);
269270
for (i = 0, j = variables.length; i < j; i++) {
270271
if (variables[i].name === variableName) {
271272
variableInScope = variables[i];

tests/lib/rules/prop-types.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,19 @@ ruleTester.run('prop-types', rule, {
904904
'}'
905905
].join('\n'),
906906
parser: 'babel-eslint'
907+
}, {
908+
code: [
909+
'export default function FooBar(props) {',
910+
' const bar = props.bar;',
911+
' return (<div bar={bar}><div {...props}/></div>);',
912+
'}',
913+
'if (process.env.NODE_ENV !== \'production\') {',
914+
' FooBar.propTypes = {',
915+
' bar: React.PropTypes.string',
916+
' }',
917+
'}'
918+
].join('\n'),
919+
parser: 'babel-eslint'
907920
}
908921
],
909922

0 commit comments

Comments
 (0)