Skip to content

Commit

Permalink
[Tests] add disambiguators to tests with multiple errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 15, 2023
1 parent d73cd51 commit d5178be
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 37 deletions.
32 changes: 16 additions & 16 deletions tests/lib/rules/jsx-equals-spacing.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,70 +91,70 @@ ruleTester.run('jsx-equals-spacing', rule, {
code: '<App foo = {bar} />',
output: '<App foo={bar} />',
errors: [
{ messageId: 'noSpaceBefore' },
{ messageId: 'noSpaceAfter' },
{ messageId: 'noSpaceBefore', type: 'JSXAttribute' },
{ messageId: 'noSpaceAfter', type: 'JSXAttribute' },
],
},
{
code: '<App foo = {bar} />',
output: '<App foo={bar} />',
options: ['never'],
errors: [
{ messageId: 'noSpaceBefore' },
{ messageId: 'noSpaceAfter' },
{ messageId: 'noSpaceBefore', type: 'JSXAttribute' },
{ messageId: 'noSpaceAfter', type: 'JSXAttribute' },
],
},
{
code: '<App foo ={bar} />',
output: '<App foo={bar} />',
options: ['never'],
errors: [{ messageId: 'noSpaceBefore' }],
errors: [{ messageId: 'noSpaceBefore', type: 'JSXAttribute' }],
},
{
code: '<App foo= {bar} />',
output: '<App foo={bar} />',
options: ['never'],
errors: [{ messageId: 'noSpaceAfter' }],
errors: [{ messageId: 'noSpaceAfter', type: 'JSXAttribute' }],
},
{
code: '<App foo= {bar} bar = {baz} />',
output: '<App foo={bar} bar={baz} />',
options: ['never'],
errors: [
{ messageId: 'noSpaceAfter' },
{ messageId: 'noSpaceBefore' },
{ messageId: 'noSpaceAfter' },
{ messageId: 'noSpaceAfter', type: 'JSXAttribute' },
{ messageId: 'noSpaceBefore', type: 'JSXAttribute' },
{ messageId: 'noSpaceAfter', type: 'JSXAttribute' },
],
},
{
code: '<App foo={bar} />',
output: '<App foo = {bar} />',
options: ['always'],
errors: [
{ messageId: 'needSpaceBefore' },
{ messageId: 'needSpaceAfter' },
{ messageId: 'needSpaceBefore', type: 'JSXAttribute' },
{ messageId: 'needSpaceAfter', type: 'JSXAttribute' },
],
},
{
code: '<App foo ={bar} />',
output: '<App foo = {bar} />',
options: ['always'],
errors: [{ messageId: 'needSpaceAfter' }],
errors: [{ messageId: 'needSpaceAfter', type: 'JSXAttribute' }],
},
{
code: '<App foo= {bar} />',
output: '<App foo = {bar} />',
options: ['always'],
errors: [{ messageId: 'needSpaceBefore' }],
errors: [{ messageId: 'needSpaceBefore', type: 'JSXAttribute' }],
},
{
code: '<App foo={bar} bar ={baz} />',
output: '<App foo = {bar} bar = {baz} />',
options: ['always'],
errors: [
{ messageId: 'needSpaceBefore' },
{ messageId: 'needSpaceAfter' },
{ messageId: 'needSpaceAfter' },
{ messageId: 'needSpaceBefore', type: 'JSXAttribute' },
{ messageId: 'needSpaceAfter', type: 'JSXAttribute' },
{ messageId: 'needSpaceAfter', type: 'JSXAttribute' },
],
},
]),
Expand Down
49 changes: 32 additions & 17 deletions tests/lib/rules/jsx-no-useless-fragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
{
code: '<p>moo<>foo</></p>',
output: '<p>moofoo</p>',
errors: [{ messageId: 'NeedsMoreChildren' }, { messageId: 'ChildOfHtmlElement' }],
errors: [
{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' },
{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' },
],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
Expand All @@ -114,13 +117,16 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
{
code: '<p><>{meow}</></p>',
output: '<p>{meow}</p>',
errors: [{ messageId: 'NeedsMoreChildren' }, { messageId: 'ChildOfHtmlElement' }],
errors: [
{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' },
{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' },
],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
code: '<><div/></>',
output: '<div/>',
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' }],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
Expand All @@ -132,12 +138,12 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
output: `
<div/>
`,
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' }],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
code: '<Fragment />',
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXElement' }],
},
{
code: `
Expand All @@ -148,7 +154,7 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
output: `
<Foo />
`,
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXElement' }],
},
{
code: `
Expand All @@ -162,31 +168,34 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
fragment: 'SomeFragment',
},
},
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXElement' }],
},
{
// Not safe to fix this case because `Eeee` might require child be ReactElement
code: '<Eeee><>foo</></Eeee>',
output: null,
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' }],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
code: '<div><>foo</></div>',
output: '<div>foo</div>',
errors: [{ messageId: 'NeedsMoreChildren' }, { messageId: 'ChildOfHtmlElement' }],
errors: [
{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' },
{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' },
],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
code: '<div><>{"a"}{"b"}</></div>',
output: '<div>{"a"}{"b"}</div>',
errors: [{ messageId: 'ChildOfHtmlElement' }],
errors: [{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' }],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old and next test case
},
{
code: '<div><>{"a"}{"b"}</></div>',
output: '<div><>{"a"}{"b"}</></div>',
errors: [{ messageId: 'ChildOfHtmlElement' }],
errors: [{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' }],
features: ['fragment', 'ts-old', 'no-ts-new', 'no-babel', 'no-default'],
},
{
Expand All @@ -202,13 +211,13 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
<Eeee />
{"a"}{"b"}
</section>`,
errors: [{ messageId: 'ChildOfHtmlElement' }],
errors: [{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' }],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
code: '<div><Fragment>{"a"}{"b"}</Fragment></div>',
output: '<div>{"a"}{"b"}</div>',
errors: [{ messageId: 'ChildOfHtmlElement' }],
errors: [{ messageId: 'ChildOfHtmlElement', type: 'JSXElement' }],
},
{
// whitepace tricky case
Expand All @@ -226,13 +235,16 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
git <b>hub</b>
</section>`,
errors: [{ messageId: 'ChildOfHtmlElement' }, { messageId: 'ChildOfHtmlElement' }],
errors: [
{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment', line: 3 },
{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment', line: 7 },
],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
code: '<div>a <>{""}{""}</> a</div>',
output: '<div>a {""}{""} a</div>',
errors: [{ messageId: 'ChildOfHtmlElement' }],
errors: [{ messageId: 'ChildOfHtmlElement', type: 'JSXFragment' }],
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
{
Expand All @@ -250,13 +262,16 @@ ruleTester.run('jsx-no-useless-fragment', rule, {
</html>
);
`,
errors: [{ messageId: 'NeedsMoreChildren' }, { messageId: 'ChildOfHtmlElement' }],
errors: [
{ messageId: 'NeedsMoreChildren', type: 'JSXElement', line: 4 },
{ messageId: 'ChildOfHtmlElement', type: 'JSXElement', line: 4 },
],
},
// Ensure allowExpressions still catches expected violations
{
code: '<><Foo>{moo}</Foo></>',
options: [{ allowExpressions: true }],
errors: [{ messageId: 'NeedsMoreChildren' }],
errors: [{ messageId: 'NeedsMoreChildren', type: 'JSXFragment' }],
output: '<Foo>{moo}</Foo>',
features: ['fragment', 'no-ts-old'], // TODO: FIXME: remove no-ts-old
},
Expand Down
32 changes: 28 additions & 4 deletions tests/lib/rules/no-deprecated.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,20 @@ ruleTester.run('no-deprecated', rule, {
{
code: 'var {createClass, PropTypes} = require(\'react\');',
errors: [
errorMessage('React.createClass', '15.5.0', 'the npm module create-react-class'),
errorMessage('React.PropTypes', '15.5.0', 'the npm module prop-types'),
errorMessage(
'React.createClass',
'15.5.0',
'the npm module create-react-class',
null,
{ type: 'VariableDeclarator', column: 5 }
),
errorMessage(
'React.PropTypes',
'15.5.0',
'the npm module prop-types',
null,
{ type: 'VariableDeclarator', column: 5 }
),
],
},
{
Expand All @@ -252,8 +264,20 @@ ruleTester.run('no-deprecated', rule, {
const {createClass, PropTypes} = React;
`,
errors: [
errorMessage('React.createClass', '15.5.0', 'the npm module create-react-class'),
errorMessage('React.PropTypes', '15.5.0', 'the npm module prop-types'),
errorMessage(
'React.createClass',
'15.5.0',
'the npm module create-react-class',
null,
{ type: 'VariableDeclarator', line: 3, column: 13 }
),
errorMessage(
'React.PropTypes',
'15.5.0',
'the npm module prop-types',
null,
{ type: 'VariableDeclarator', line: 3, column: 13 }
),
],
},
{
Expand Down
Loading

0 comments on commit d5178be

Please sign in to comment.