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 610a29d commit 1d0494f
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 41 deletions.
15 changes: 14 additions & 1 deletion tests/lib/rules/forbid-prop-types.js
Expand Up @@ -572,6 +572,19 @@ 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')
}],

invalid: [{
Expand Down Expand Up @@ -713,7 +726,7 @@ ruleTester.run('forbid-prop-types', rule, {
code: [
'var First = createReactClass({',
' propTypes: {',
' s: PropTypes.shape({,',
' s: PropTypes.shape({',
' o: PropTypes.object',
' })',
' },',
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/jsx-closing-bracket-location.js
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
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
31 changes: 15 additions & 16 deletions tests/lib/rules/jsx-indent.js
Expand Up @@ -1120,7 +1120,12 @@ const Component = () => (
].join('\n'),
options: [2],
errors: [{message: 'Expected indentation of 2 space characters but found 4.'}]
}, {
}, /*
// The detection logic only thinks <App> is indented wrong, not the other
// 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
{
code: [
'function App() {',
' return (',
Expand All @@ -1130,22 +1135,9 @@ const Component = () => (
' );',
'}'
].join('\n'),
// The detection logic only thinks <App> is indented wrong, not the other
// 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: [
'function App() {',
' return (',
' <App>',
' <Foo />',
' </App>',
' );',
'}'
].join('\n'), */
options: [2],
errors: [{message: 'Expected indentation of 4 space characters but found 0.'}]
}, {
}, */ {
code: [
'<App>',
' {test}',
Expand Down Expand Up @@ -1781,7 +1773,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
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
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
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
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
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 1d0494f

Please sign in to comment.