Skip to content

Commit

Permalink
Add more tests with spread, add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
b0gok committed Jan 15, 2018
1 parent ba394d2 commit 558576c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/rules/jsx-sort-default-props.md
Expand Up @@ -47,6 +47,24 @@ Component.defaultProps = {
y: "y",
a: "a"
};

const defaults = {
b: "b"
};
const types = {
a: PropTypes.string,
b: PropTypes.string,
c: PropTypes.string'
};
function StatelessComponentWithSpreadInPropTypes({ a, b, c }) {
return <div>{a}{b}{c}</div>;
}
StatelessComponentWithSpreadInPropTypes.propTypes = types;
StatelessComponentWithSpreadInPropTypes.defaultProps = {
c: "c",
a: "a",
...defaults,
};
```
The following patterns are considered okay and do **not** cause warnings:
Expand Down Expand Up @@ -90,6 +108,24 @@ Component.defaultProps = {
y: "y",
z: "z"
};
const defaults = {
b: "b"
};
const types = {
a: PropTypes.string,
b: PropTypes.string,
c: PropTypes.string'
};
function StatelessComponentWithSpreadInPropTypes({ a, b, c }) {
return <div>{a}{b}{c}</div>;
}
StatelessComponentWithSpreadInPropTypes.propTypes = types;
StatelessComponentWithSpreadInPropTypes.defaultProps = {
a: "a",
c: "c",
...defaults,
};
```

## Rule Options
Expand Down
70 changes: 70 additions & 0 deletions tests/lib/rules/jsx-sort-default-props.js
Expand Up @@ -262,6 +262,27 @@ ruleTester.run('jsx-sort-default-props', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'const defaults = {',
' b: "b"',
'};',
'const types = {',
' a: PropTypes.string,',
' b: PropTypes.string,',
' c: PropTypes.string',
'};',
'function StatelessComponentWithSpreadInPropTypes({ a, b, c }) {',
' return <div>{a}{b}{c}</div>;',
'}',
'StatelessComponentWithSpreadInPropTypes.propTypes = types;',
'StatelessComponentWithSpreadInPropTypes.defaultProps = {',
' c: "c",',
' ...defaults,',
' a: "a"',
'};'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'const propTypes = require(\'./externalPropTypes\')',
Expand Down Expand Up @@ -494,5 +515,54 @@ ruleTester.run('jsx-sort-default-props', rule, {
column: 3,
type: 'Property'
}]
}, {
code: [
'export default class ClassWithSpreadInPropTypes extends BaseClass {',
' static propTypes = {',
' b: PropTypes.string,',
' ...c.propTypes,',
' a: PropTypes.string',
' }',
' static defaultProps = {',
' b: "b",',
' a: "a",',
' ...c.defaultProps',
' }',
'}'
].join('\n'),
parser: 'babel-eslint',
errors: [{
message: ERROR_MESSAGE,
line: 9,
column: 5,
type: 'Property'
}]
}, {
code: [
'const defaults = {',
' b: "b"',
'};',
'const types = {',
' a: PropTypes.string,',
' b: PropTypes.string,',
' c: PropTypes.string',
'};',
'function StatelessComponentWithSpreadInPropTypes({ a, b, c }) {',
' return <div>{a}{b}{c}</div>;',
'}',
'StatelessComponentWithSpreadInPropTypes.propTypes = types;',
'StatelessComponentWithSpreadInPropTypes.defaultProps = {',
' c: "c",',
' a: "a",',
' ...defaults,',
'};'
].join('\n'),
parser: 'babel-eslint',
errors: [{
message: ERROR_MESSAGE,
line: 15,
column: 3,
type: 'Property'
}]
}]
});

0 comments on commit 558576c

Please sign in to comment.