Skip to content

Commit d818f2b

Browse files
authored
Merge pull request #1669 from justinanastos/fix/sort-prop-types-shape-no-properties-1668
fix(sort-prop-types): Fix sortShapeProp when shape is not an object literal
2 parents cfd3959 + 17ac433 commit d818f2b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/rules/sort-prop-types.js

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ module.exports = {
7777
* @returns {void}
7878
*/
7979
function checkSorted(declarations) {
80+
// Declarations will be `undefined` if the `shape` is not a literal. For
81+
// example, if it is a propType imported from another file.
82+
if (!declarations) {
83+
return;
84+
}
85+
8086
declarations.reduce((prev, curr, idx, decls) => {
8187
if (/SpreadProperty$/.test(curr.type)) {
8288
return decls[idx + 1];

tests/lib/rules/sort-prop-types.js

+18
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,24 @@ ruleTester.run('sort-prop-types', rule, {
365365
options: [{
366366
sortShapeProp: true
367367
}]
368+
}, {
369+
code: `
370+
class Component extends React.Component {
371+
render() {
372+
return <div />;
373+
}
374+
}
375+
Component.propTypes = {
376+
a: PropTypes.any,
377+
b: PropTypes.any,
378+
c: PropTypes.shape(
379+
importedPropType,
380+
),
381+
};
382+
`,
383+
options: [{
384+
sortShapeProp: true
385+
}]
368386
}],
369387

370388
invalid: [{

0 commit comments

Comments
 (0)