Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tests] jsx-indent, jsx-one-expression-per-line: add passing test cases #3314

Merged
merged 1 commit into from Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
</Layout>
`,
errors: [
{
messageId: 'moveToNewLine',
data: { descriptor: 'Go to page 2' },
},
],
parserOptions,
},
]),
});