Skip to content

Commit

Permalink
[Tests] jsx-indent, jsx-one-expression-per-line: add passing test…
Browse files Browse the repository at this point in the history
… cases

Closes #2318
  • Loading branch information
ROSSROSALES authored and ljharb committed Jun 29, 2022
1 parent 1948765 commit 437fe3c
Show file tree
Hide file tree
Showing 3 changed files with 312 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,10 +14,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

### Changed
* [Refactor] [`jsx-indent-props`]: improved readability of the checkNodesIndent function ([#3315][] @caroline223)
* [Tests] [`jsx-indent`], [`jsx-one-expression-per-line`]: add passing test cases ([#3314][] @ROSSROSALES)

[#3320]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3320
[#3317]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3317
[#3315]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3315
[#3314]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3314
[#3311]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3311

## [7.30.1] - 2022.06.23
Expand Down
131 changes: 130 additions & 1 deletion tests/lib/rules/jsx-indent.js
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
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 437fe3c

Please sign in to comment.