Skip to content

Commit

Permalink
Merge pull request #1669 from justinanastos/fix/sort-prop-types-shape…
Browse files Browse the repository at this point in the history
…-no-properties-1668

fix(sort-prop-types): Fix sortShapeProp when shape is not an object literal
  • Loading branch information
ljharb committed Jan 31, 2018
2 parents cfd3959 + 17ac433 commit d818f2b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rules/sort-prop-types.js
Expand Up @@ -77,6 +77,12 @@ module.exports = {
* @returns {void}
*/
function checkSorted(declarations) {
// Declarations will be `undefined` if the `shape` is not a literal. For
// example, if it is a propType imported from another file.
if (!declarations) {
return;
}

declarations.reduce((prev, curr, idx, decls) => {
if (/SpreadProperty$/.test(curr.type)) {
return decls[idx + 1];
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/sort-prop-types.js
Expand Up @@ -365,6 +365,24 @@ ruleTester.run('sort-prop-types', rule, {
options: [{
sortShapeProp: true
}]
}, {
code: `
class Component extends React.Component {
render() {
return <div />;
}
}
Component.propTypes = {
a: PropTypes.any,
b: PropTypes.any,
c: PropTypes.shape(
importedPropType,
),
};
`,
options: [{
sortShapeProp: true
}]
}],

invalid: [{
Expand Down

0 comments on commit d818f2b

Please sign in to comment.