Skip to content

Commit e24b53f

Browse files
committed
Add tests and examples with multiple spreads
1 parent 558576c commit e24b53f

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

docs/rules/jsx-sort-default-props.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,25 @@ StatelessComponentWithSpreadInPropTypes.defaultProps = {
6565
a: "a",
6666
...defaults,
6767
};
68+
69+
export default class ClassWithSpreadInPropTypes extends BaseClass {
70+
static propTypes = {
71+
a: PropTypes.string,
72+
b: PropTypes.string,
73+
c: PropTypes.string,
74+
d: PropTypes.string,
75+
e: PropTypes.string,
76+
f: PropTypes.string
77+
}
78+
static defaultProps = {
79+
b: "b",
80+
a: "a",
81+
...c.defaultProps,
82+
f: "f",
83+
e: "e",
84+
...d.defaultProps
85+
}
86+
}
6887
```
6988
7089
The following patterns are considered okay and do **not** cause warnings:
@@ -126,6 +145,25 @@ StatelessComponentWithSpreadInPropTypes.defaultProps = {
126145
c: "c",
127146
...defaults,
128147
};
148+
149+
export default class ClassWithSpreadInPropTypes extends BaseClass {
150+
static propTypes = {
151+
a: PropTypes.string,
152+
b: PropTypes.string,
153+
c: PropTypes.string,
154+
d: PropTypes.string,
155+
e: PropTypes.string,
156+
f: PropTypes.string
157+
}
158+
static defaultProps = {
159+
a: "a",
160+
b: "b",
161+
...c.defaultProps,
162+
e: "e",
163+
f: "f",
164+
...d.defaultProps
165+
}
166+
}
129167
```
130168

131169
## Rule Options

tests/lib/rules/jsx-sort-default-props.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,28 @@ ruleTester.run('jsx-sort-default-props', rule, {
262262
'}'
263263
].join('\n'),
264264
parser: 'babel-eslint'
265+
}, {
266+
code: [
267+
'export default class ClassWithSpreadInPropTypes extends BaseClass {',
268+
' static propTypes = {',
269+
' a: PropTypes.string,',
270+
' b: PropTypes.string,',
271+
' c: PropTypes.string,',
272+
' d: PropTypes.string,',
273+
' e: PropTypes.string,',
274+
' f: PropTypes.string',
275+
' }',
276+
' static defaultProps = {',
277+
' a: "a",',
278+
' b: "b",',
279+
' ...c.defaultProps,',
280+
' e: "e",',
281+
' f: "f",',
282+
' ...d.defaultProps',
283+
' }',
284+
'}'
285+
].join('\n'),
286+
parser: 'babel-eslint'
265287
}, {
266288
code: [
267289
'const defaults = {',
@@ -537,6 +559,29 @@ ruleTester.run('jsx-sort-default-props', rule, {
537559
column: 5,
538560
type: 'Property'
539561
}]
562+
}, {
563+
code: [
564+
'export default class ClassWithSpreadInPropTypes extends BaseClass {',
565+
' static propTypes = {',
566+
' a: PropTypes.string,',
567+
' b: PropTypes.string,',
568+
' c: PropTypes.string,',
569+
' d: PropTypes.string,',
570+
' e: PropTypes.string,',
571+
' f: PropTypes.string',
572+
' }',
573+
' static defaultProps = {',
574+
' b: "b",',
575+
' a: "a",',
576+
' ...c.defaultProps,',
577+
' f: "f",',
578+
' e: "e",',
579+
' ...d.defaultProps',
580+
' }',
581+
'}'
582+
].join('\n'),
583+
parser: 'babel-eslint',
584+
errors: 2
540585
}, {
541586
code: [
542587
'const defaults = {',

0 commit comments

Comments
 (0)