Skip to content

Commit

Permalink
[Tests] fix mistaken error property and add output property
Browse files Browse the repository at this point in the history
  • Loading branch information
toshi-toma authored and ljharb committed May 9, 2020
1 parent 906b474 commit 35030a0
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 43 deletions.
28 changes: 14 additions & 14 deletions tests/lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,20 @@ ruleTester.run('forbid-prop-types', rule, {
' preview: PropTypes.bool,',
'}, componentApi, teaserListProps);'
].join('\n')
}, {
code: [
'var First = createReactClass({',
' propTypes: {',
' s: PropTypes.shape({',
' o: PropTypes.object',
' })',
' },',
' render: function() {',
' return <div />;',
' }',
'});'
].join('\n'),
errors: 0 // TODO: fix #1673 and move this to "invalid"
}],

invalid: [{
Expand Down Expand Up @@ -709,20 +723,6 @@ ruleTester.run('forbid-prop-types', rule, {
'});'
].join('\n'),
errors: 2
}, {
code: [
'var First = createReactClass({',
' propTypes: {',
' s: PropTypes.shape({,',
' o: PropTypes.object',
' })',
' },',
' render: function() {',
' return <div />;',
' }',
'});'
].join('\n'),
errors: 1
}, {
code: [
'var First = createReactClass({',
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-closing-bracket-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
')'
].join('\n'),
options: [{location: 'line-aligned'}],
errors: [MESSAGE_AFTER_TAG]
errors: MESSAGE_AFTER_TAG
}, {
code: [
'<div className={[',
Expand Down Expand Up @@ -1664,7 +1664,7 @@ ruleTester.run('jsx-closing-bracket-location', rule, {
')'
].join('\n'),
options: [{location: 'line-aligned'}],
errors: [MESSAGE_AFTER_TAG]
errors: MESSAGE_AFTER_TAG
}, {
code: [
'<div className={[',
Expand Down
32 changes: 28 additions & 4 deletions tests/lib/rules/jsx-curly-brace-presence.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,14 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
{
code: `<App prop='foo &middot; bar' />`,
errors: [{message: missingCurlyMessage}],
options: [{props: 'always'}]
options: [{props: 'always'}],
output: `<App prop={"foo &middot; bar"} />`
},
{
code: '<App>foo &middot; bar</App>',
errors: [{message: missingCurlyMessage}],
options: [{children: 'always'}]
options: [{children: 'always'}],
output: '<App>{"foo &middot; bar"}</App>'
},
{
code: `<App>{'foo "bar"'}</App>`,
Expand Down Expand Up @@ -689,7 +691,18 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
errors: [
{message: missingCurlyMessage}, {message: missingCurlyMessage}
],
options: ['always']
options: ['always'],
output: [
'<App prop=" ',
' a ',
' b c',
' d',
'">',
' {"a"}',
' {"b c "}',
' {"d "}',
'</App>'
].join('\n')
},
{
code: [
Expand All @@ -706,7 +719,18 @@ ruleTester.run('jsx-curly-brace-presence', rule, {
errors: [
{message: missingCurlyMessage}, {message: missingCurlyMessage}
],
options: ['always']
options: ['always'],
output: [
`<App prop=' `,
' a ',
' b c',
' d',
`'>`,
' {"a"}',
' {"b c "}',
' {"d "}',
'</App>'
].join('\n')
},
{
code: `
Expand Down
17 changes: 12 additions & 5 deletions tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -1134,15 +1134,15 @@ const Component = () => (
// two lines following. I *think* because it incorrectly uses <App>'s indention
// as the baseline for the next two, instead of the realizing the entire three
// lines are wrong together. See #608
/* output: [
output: [
'function App() {',
' return (',
' <App>',
' <Foo />',
' </App>',
' <Foo />',
'</App>',
' );',
'}'
].join('\n'), */
].join('\n'),
options: [2],
errors: [{message: 'Expected indentation of 4 space characters but found 0.'}]
}, {
Expand Down Expand Up @@ -1781,7 +1781,14 @@ const Component = () => (
].join('\n'),
errors: [
{message: 'Expected indentation of 4 space characters but found 2.'}
]
],
output: [
'<p>',
' <div>',
' <SelfClosingTag />Text',
' </div>',
'</p>'
].join('\n')
}, {
code: `
const Component = () => (
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ ruleTester.run('jsx-sort-props', rule, {
},
{
code: '<App a="a" onBar onFoo z x />;',
errors: [shorthandAndCallbackLastArgs],
errors: [expectedError],
options: shorthandLastArgs,
output: '<App a="a" onBar onFoo x z />;'
},
Expand Down
14 changes: 12 additions & 2 deletions tests/lib/rules/jsx-uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,23 @@ ruleTester.run('prefer-const', rulePreferConst, {
let App = <div />;
<App />;
`,
errors: [{message: '\'App\' is never reassigned. Use \'const\' instead.'}]
errors: [{message: '\'App\' is never reassigned. Use \'const\' instead.'}],
output: `
/* eslint jsx-uses-vars:1 */
const App = <div />;
<App />;
`
}, {
code: `
/* eslint jsx-uses-vars:1 */
let filters = 'foo';
<div>{filters}</div>;
`,
errors: [{message: '\'filters\' is never reassigned. Use \'const\' instead.'}]
errors: [{message: '\'filters\' is never reassigned. Use \'const\' instead.'}],
output: `
/* eslint jsx-uses-vars:1 */
const filters = 'foo';
<div>{filters}</div>;
`
}]
});
8 changes: 4 additions & 4 deletions tests/lib/rules/no-typos.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ ruleTester.run('no-typos', rule, {
type: 'MethodDefinition'
}, {
message: ERROR_MESSAGE_LIFECYCLE_METHOD('Render', 'render'),
nodeType: 'MethodDefinition'
type: 'MethodDefinition'
}]
}, {
code: `
Expand Down Expand Up @@ -1616,7 +1616,7 @@ ruleTester.run('no-typos', rule, {
parserOptions,
errors: [{
message: ERROR_MESSAGE_STATIC('getDerivedStateFromProps'),
nodeType: 'MethodDefinition'
type: 'MethodDefinition'
}]
}, {
code: `
Expand All @@ -1628,10 +1628,10 @@ ruleTester.run('no-typos', rule, {
parserOptions,
errors: [{
message: ERROR_MESSAGE_STATIC('GetDerivedStateFromProps'),
nodeType: 'MethodDefinition'
type: 'MethodDefinition'
}, {
message: ERROR_MESSAGE_LIFECYCLE_METHOD('GetDerivedStateFromProps', 'getDerivedStateFromProps'),
nodeType: 'MethodDefinition'
type: 'MethodDefinition'
}]
}, {
code: `
Expand Down
6 changes: 4 additions & 2 deletions tests/lib/rules/no-unknown-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ ruleTester.run('no-unknown-property', rule, {
errors: [{message: 'Unknown property \'clip-path\' found, use \'clipPath\' instead'}]
}, {
code: '<script crossorigin />',
errors: [{message: 'Unknown property \'crossorigin\' found, use \'crossOrigin\' instead'}]
errors: [{message: 'Unknown property \'crossorigin\' found, use \'crossOrigin\' instead'}],
output: '<script crossOrigin />'
}, {
code: '<div crossorigin />',
errors: [{message: 'Unknown property \'crossorigin\' found, use \'crossOrigin\' instead'}]
errors: [{message: 'Unknown property \'crossorigin\' found, use \'crossOrigin\' instead'}],
output: '<div crossOrigin />'
}, {
code: '<div crossOrigin />',
errors: [{message: 'Invalid property \'crossOrigin\' found on tag \'div\', but it is only allowed on: script, img, video, audio, link'}]
Expand Down
80 changes: 71 additions & 9 deletions tests/lib/rules/prefer-read-only-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,24 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
type Props = {
+name: string,
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}
`
},
{
// Props.name is contravariant
code: `
type Props = {
-name: string,
-name: string,
}
class Hello extends React.Component<Props> {
Expand All @@ -169,7 +180,18 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
type Props = {
+name: string,
}
class Hello extends React.Component<Props> {
render () {
return <div>Hello {this.props.name}</div>;
}
}
`
},
{
code: `
Expand All @@ -186,7 +208,18 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
class Hello extends React.Component {
props: {
+name: string,
}
render () {
return <div>Hello {this.props.name}</div>;
}
}
`
},
{
code: `
Expand All @@ -197,7 +230,12 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
function Hello(props: {+name: string}) {
return <div>Hello {props.name}</div>;
}
`
},
{
code: `
Expand All @@ -208,7 +246,12 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
function Hello(props: {|+name: string|}) {
return <div>Hello {props.name}</div>;
}
`
},
{
code: `
Expand All @@ -219,7 +262,12 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
function Hello({name}: {+name: string}) {
return <div>Hello {props.name}</div>;
}
`
},
{
code: `
Expand All @@ -236,7 +284,16 @@ ruleTester.run('prefer-read-only-props', rule, {
message: 'Prop \'firstName\' should be read-only.'
}, {
message: 'Prop \'lastName\' should be read-only.'
}]
}],
output: `
type PropsA = {+firstName: string};
type PropsB = {+lastName: string};
type Props = PropsA & PropsB;
function Hello({firstName, lastName}: Props) {
return <div>Hello {firstName} {lastName}</div>;
}
`
},
{
code: `
Expand All @@ -247,7 +304,12 @@ ruleTester.run('prefer-read-only-props', rule, {
parser: parsers.BABEL_ESLINT,
errors: [{
message: 'Prop \'name\' should be read-only.'
}]
}],
output: `
const Hello = (props: {+name: string}) => (
<div>Hello {props.name}</div>
);
`
}
]
});

0 comments on commit 35030a0

Please sign in to comment.