Skip to content

Commit

Permalink
Fix propTypes detection when declared before the component (fixes #472)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Feb 29, 2016
1 parent 45b3c27 commit 1b0caca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Components() {
*
* @param {ASTNode} node The AST node being added.
* @param {Number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes)
* @returns {Object} Added component object
*/
Components.prototype.add = function(node, confidence) {
var id = this._getId(node);
Expand All @@ -33,12 +34,13 @@ Components.prototype.add = function(node, confidence) {
} else {
this._list[id].confidence = Math.max(this._list[id].confidence, confidence);
}
return;
return this._list[id];
}
this._list[id] = {
node: node,
confidence: confidence
};
return this._list[id];
};

/**
Expand Down Expand Up @@ -333,7 +335,7 @@ function componentRule(rule, context) {
}

// Return the component
return components.get(node);
return components.add(node, 1);
}
};

Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,20 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'Card.propTypes = {',
' title: PropTypes.string.isRequired,',
' children: PropTypes.element.isRequired,',
' footer: PropTypes.node',
'}',
'function Card ({ title, children, footer }) {',
' return (',
' <div/>',
' )',
'}'
].join('\n'),
parserOptions: parserOptions
}
],

Expand Down

0 comments on commit 1b0caca

Please sign in to comment.