Skip to content

Commit be2a470

Browse files
committed
Fix props that where not assigned to the right component (fixes #591)
1 parent 6affab3 commit be2a470

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/util/Components.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ Components.prototype.list = function() {
9090
node = this._list[i].node;
9191
while (!component && node.parent) {
9292
node = node.parent;
93+
// Stop moving up if we reach a decorator
94+
if (node.type === 'Decorator') {
95+
break;
96+
}
9397
component = this.get(node);
9498
}
9599
if (component) {
@@ -270,9 +274,15 @@ function componentRule(rule, context) {
270274
var scope = context.getScope();
271275
while (scope) {
272276
var node = scope.block;
277+
var isClass = node.type === 'ClassExpression';
273278
var isFunction = /Function/.test(node.type); // Ignore non functions
274279
var isNotMethod = !node.parent || node.parent.type !== 'MethodDefinition'; // Ignore classes methods
275280
var isNotArgument = !node.parent || node.parent.type !== 'CallExpression'; // Ignore arguments (callback, etc.)
281+
// Stop moving up if we reach a class
282+
if (isClass) {
283+
return null;
284+
}
285+
// Return the node if it is a function that is not a class method or an argument (like a callback)
276286
if (isFunction && isNotMethod && isNotArgument) {
277287
return node;
278288
}

tests/lib/rules/prop-types.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,23 @@ ruleTester.run('prop-types', rule, {
12061206
'}'
12071207
].join('\n'),
12081208
parser: 'babel-eslint'
1209+
}, {
1210+
// Should stop at the class when searching for a parent component
1211+
code: [
1212+
'export default (ComposedComponent) => class Something extends SomeOtherComponent {',
1213+
' someMethod = ({width}) => {}',
1214+
'}'
1215+
].join('\n'),
1216+
parser: 'babel-eslint'
1217+
}, {
1218+
// Should stop at the decorator when searching for a parent component
1219+
code: [
1220+
'@asyncConnect([{',
1221+
' promise: ({dispatch}) => {}',
1222+
'}])',
1223+
'class Something extends Component {}'
1224+
].join('\n'),
1225+
parser: 'babel-eslint'
12091226
}
12101227
],
12111228

0 commit comments

Comments
 (0)