Skip to content

Commit

Permalink
added test cases issue #2318
Browse files Browse the repository at this point in the history
  • Loading branch information
ROSSROSALES committed Jul 5, 2022
1 parent 7a7bb99 commit 4160f18
Show file tree
Hide file tree
Showing 2 changed files with 310 additions and 1 deletion.
131 changes: 130 additions & 1 deletion tests/lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ruleTester.run('jsx-indent', rule, {
{
code: `
<App>
</App>
</App>
`,
},
{
Expand Down Expand Up @@ -3001,6 +3001,135 @@ const Component = () => (
},
],
},
{
code: `
const IndexPage = () => (
<h1>
{"Hi people"}
<button/>
</h1>
);
`,
output: `
const IndexPage = () => (
<h1>
{"Hi people"}
<button/>
</h1>
);
`,
options:[2],
errors: [
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
{
messageId: 'wrongIndent',
data: {
needed: 10,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
],
},
// Would be nice to handle in one pass, but multipass works fine.
{
code: `
const IndexPage = () => (
<h1>
Hi people
<button/>
</h1>
);
`,

output: `
const IndexPage = () => (
<h1>
Hi people
<button/>
</h1>
);
`,
options:[2],
errors: [
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
{
messageId: 'wrongIndent',
data: {
needed: 10,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
],
},
{
code: `
const IndexPage = () => (
<h1>
Hi people
<button/>
</h1>
);
`,

output: `
const IndexPage = () => (
<h1>
Hi people
<button/>
</h1>
);
`,
options:[2],
errors: [
{
messageId: 'wrongIndent',
data: {
needed: 12,
type: 'space',
characters: 'characters',
gotten: 8,
},
},
],
},
semver.satisfies(eslintVersion, '> 4') ? {
code: `
import React from 'react';
Expand Down
180 changes: 180 additions & 0 deletions tests/lib/rules/jsx-one-expression-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -1389,5 +1389,185 @@ a
],
parserOptions,
},
{
// TODO: handle in a single pass
code: `
const IndexPage = () => (
<h1>{"Hi people"}<button/></h1>
);
`,
output: `
const IndexPage = () => (
<h1>
{"Hi people"}<button/></h1>
);
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: '{"Hi people"}' },
},
{
messageId: 'moveToNewLine',
data: { descriptor: 'button' },
},
],
parserOptions,
},
{
code: `
const IndexPage = () => (
<h1>
{"Hi people"}<button/></h1>
);
`,
output: `
const IndexPage = () => (
<h1>
{"Hi people"}
<button/>
</h1>
);
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: 'button' },
},
],
parserOptions,
},
// TODO: handle in a single pass (see above)
{
code: `
<Layout>
<p>Welcome to your new Gatsby site.</p>
<p>Now go build something great.</p>
<h1>Hi people<button/></h1>
</Layout>
`,
output: `
<Layout>
<p>
Welcome to your new Gatsby site.
</p>
<p>
Now go build something great.
</p>
<h1>
Hi people<button/></h1>
</Layout>
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: 'Welcome to your new Gatsby site.' },
},
{
messageId: 'moveToNewLine',
data: { descriptor: 'Now go build something great.' },
},
{
messageId: 'moveToNewLine',
data: { descriptor: 'Hi people' },
},
{
messageId: 'moveToNewLine',
data: { descriptor: 'button' },
},
],
parserOptions,
},
{
code: `
<Layout>
<p>
Welcome to your new Gatsby site.
</p>
<p>
Now go build something great.
</p>
<h1>
Hi people<button/></h1>
</Layout>
`,
output: `
<Layout>
<p>
Welcome to your new Gatsby site.
</p>
<p>
Now go build something great.
</p>
<h1>
Hi people
<button/>
</h1>
</Layout>
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: 'button' },
},
],
parserOptions,
},
// TODO: handle in a single pass
{
code: `
<Layout>
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
<Image />
</div><Link to="/page-2/">Go to page 2</Link>
</Layout>
`,
output: `
<Layout>
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
<Image />
</div>
<Link to="/page-2/">Go to page 2</Link>
</Layout>
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: 'Link' },
},
{
messageId: 'moveToNewLine',
data: { descriptor: 'Go to page 2' },
},
],
parserOptions,
},
{
code: `
<Layout>
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
<Image />
</div>
<Link to="/page-2/">Go to page 2</Link>
</Layout>
`,
output: `
<Layout>
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
<Image />
</div>
<Link to="/page-2/">
Go to page 2
</Link>2
</Layout>
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: 'Go to page 2' },
},
],
parserOptions,
},
]),
});

0 comments on commit 4160f18

Please sign in to comment.