Skip to content

Commit

Permalink
Add tests and examples with multiple spreads
Browse files Browse the repository at this point in the history
  • Loading branch information
b0gok committed Jan 15, 2018
1 parent 558576c commit e24b53f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
38 changes: 38 additions & 0 deletions docs/rules/jsx-sort-default-props.md
Expand Up @@ -65,6 +65,25 @@ StatelessComponentWithSpreadInPropTypes.defaultProps = {
a: "a",
...defaults,
};
export default class ClassWithSpreadInPropTypes extends BaseClass {
static propTypes = {
a: PropTypes.string,
b: PropTypes.string,
c: PropTypes.string,
d: PropTypes.string,
e: PropTypes.string,
f: PropTypes.string
}
static defaultProps = {
b: "b",
a: "a",
...c.defaultProps,
f: "f",
e: "e",
...d.defaultProps
}
}
```
The following patterns are considered okay and do **not** cause warnings:
Expand Down Expand Up @@ -126,6 +145,25 @@ StatelessComponentWithSpreadInPropTypes.defaultProps = {
c: "c",
...defaults,
};

export default class ClassWithSpreadInPropTypes extends BaseClass {
static propTypes = {
a: PropTypes.string,
b: PropTypes.string,
c: PropTypes.string,
d: PropTypes.string,
e: PropTypes.string,
f: PropTypes.string
}
static defaultProps = {
a: "a",
b: "b",
...c.defaultProps,
e: "e",
f: "f",
...d.defaultProps
}
}
```

## Rule Options
Expand Down
45 changes: 45 additions & 0 deletions tests/lib/rules/jsx-sort-default-props.js
Expand Up @@ -262,6 +262,28 @@ ruleTester.run('jsx-sort-default-props', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'export default class ClassWithSpreadInPropTypes extends BaseClass {',
' static propTypes = {',
' a: PropTypes.string,',
' b: PropTypes.string,',
' c: PropTypes.string,',
' d: PropTypes.string,',
' e: PropTypes.string,',
' f: PropTypes.string',
' }',
' static defaultProps = {',
' a: "a",',
' b: "b",',
' ...c.defaultProps,',
' e: "e",',
' f: "f",',
' ...d.defaultProps',
' }',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'const defaults = {',
Expand Down Expand Up @@ -537,6 +559,29 @@ ruleTester.run('jsx-sort-default-props', rule, {
column: 5,
type: 'Property'
}]
}, {
code: [
'export default class ClassWithSpreadInPropTypes extends BaseClass {',
' static propTypes = {',
' a: PropTypes.string,',
' b: PropTypes.string,',
' c: PropTypes.string,',
' d: PropTypes.string,',
' e: PropTypes.string,',
' f: PropTypes.string',
' }',
' static defaultProps = {',
' b: "b",',
' a: "a",',
' ...c.defaultProps,',
' f: "f",',
' e: "e",',
' ...d.defaultProps',
' }',
'}'
].join('\n'),
parser: 'babel-eslint',
errors: 2
}, {
code: [
'const defaults = {',
Expand Down

0 comments on commit e24b53f

Please sign in to comment.