Skip to content

Commit 151a6ed

Browse files
ROSSROSALESljharb
authored andcommitted
[Tests] jsx-indent, jsx-one-expression-per-line: add passing test cases
Closes #2318
1 parent 1948765 commit 151a6ed

File tree

3 files changed

+312
-1
lines changed

3 files changed

+312
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1414

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

1819
[#3320]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3320
1920
[#3317]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3317
2021
[#3315]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3315
22+
[#3314]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3314
2123
[#3311]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3311
2224

2325
## [7.30.1] - 2022.06.23

tests/lib/rules/jsx-indent.js

+130-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ruleTester.run('jsx-indent', rule, {
4545
{
4646
code: `
4747
<App>
48-
</App>
48+
</App>
4949
`,
5050
},
5151
{
@@ -3001,6 +3001,135 @@ const Component = () => (
30013001
},
30023002
],
30033003
},
3004+
{
3005+
code: `
3006+
const IndexPage = () => (
3007+
<h1>
3008+
{"Hi people"}
3009+
<button/>
3010+
</h1>
3011+
);
3012+
`,
3013+
output: `
3014+
const IndexPage = () => (
3015+
<h1>
3016+
{"Hi people"}
3017+
<button/>
3018+
</h1>
3019+
);
3020+
`,
3021+
options: [2],
3022+
errors: [
3023+
{
3024+
messageId: 'wrongIndent',
3025+
data: {
3026+
needed: 12,
3027+
type: 'space',
3028+
characters: 'characters',
3029+
gotten: 8,
3030+
},
3031+
},
3032+
{
3033+
messageId: 'wrongIndent',
3034+
data: {
3035+
needed: 12,
3036+
type: 'space',
3037+
characters: 'characters',
3038+
gotten: 8,
3039+
},
3040+
},
3041+
{
3042+
messageId: 'wrongIndent',
3043+
data: {
3044+
needed: 10,
3045+
type: 'space',
3046+
characters: 'characters',
3047+
gotten: 8,
3048+
},
3049+
},
3050+
],
3051+
},
3052+
// Would be nice to handle in one pass, but multipass works fine.
3053+
{
3054+
code: `
3055+
const IndexPage = () => (
3056+
<h1>
3057+
Hi people
3058+
<button/>
3059+
</h1>
3060+
);
3061+
`,
3062+
3063+
output: `
3064+
const IndexPage = () => (
3065+
<h1>
3066+
Hi people
3067+
<button/>
3068+
</h1>
3069+
);
3070+
`,
3071+
options: [2],
3072+
errors: [
3073+
{
3074+
messageId: 'wrongIndent',
3075+
data: {
3076+
needed: 12,
3077+
type: 'space',
3078+
characters: 'characters',
3079+
gotten: 8,
3080+
},
3081+
},
3082+
{
3083+
messageId: 'wrongIndent',
3084+
data: {
3085+
needed: 12,
3086+
type: 'space',
3087+
characters: 'characters',
3088+
gotten: 8,
3089+
},
3090+
},
3091+
{
3092+
messageId: 'wrongIndent',
3093+
data: {
3094+
needed: 10,
3095+
type: 'space',
3096+
characters: 'characters',
3097+
gotten: 8,
3098+
},
3099+
},
3100+
],
3101+
},
3102+
{
3103+
code: `
3104+
const IndexPage = () => (
3105+
<h1>
3106+
Hi people
3107+
<button/>
3108+
</h1>
3109+
);
3110+
`,
3111+
3112+
output: `
3113+
const IndexPage = () => (
3114+
<h1>
3115+
Hi people
3116+
<button/>
3117+
</h1>
3118+
);
3119+
`,
3120+
options: [2],
3121+
errors: [
3122+
{
3123+
messageId: 'wrongIndent',
3124+
data: {
3125+
needed: 12,
3126+
type: 'space',
3127+
characters: 'characters',
3128+
gotten: 8,
3129+
},
3130+
},
3131+
],
3132+
},
30043133
semver.satisfies(eslintVersion, '> 4') ? {
30053134
code: `
30063135
import React from 'react';

tests/lib/rules/jsx-one-expression-per-line.js

+180
Original file line numberDiff line numberDiff line change
@@ -1389,5 +1389,185 @@ a
13891389
],
13901390
parserOptions,
13911391
},
1392+
{
1393+
// TODO: handle in a single pass
1394+
code: `
1395+
const IndexPage = () => (
1396+
<h1>{"Hi people"}<button/></h1>
1397+
);
1398+
`,
1399+
output: `
1400+
const IndexPage = () => (
1401+
<h1>
1402+
{"Hi people"}<button/></h1>
1403+
);
1404+
`,
1405+
errors: [
1406+
{
1407+
messageId: 'moveToNewLine',
1408+
data: { descriptor: '{"Hi people"}' },
1409+
},
1410+
{
1411+
messageId: 'moveToNewLine',
1412+
data: { descriptor: 'button' },
1413+
},
1414+
],
1415+
parserOptions,
1416+
},
1417+
{
1418+
code: `
1419+
const IndexPage = () => (
1420+
<h1>
1421+
{"Hi people"}<button/></h1>
1422+
);
1423+
`,
1424+
output: `
1425+
const IndexPage = () => (
1426+
<h1>
1427+
{"Hi people"}
1428+
<button/>
1429+
</h1>
1430+
);
1431+
`,
1432+
errors: [
1433+
{
1434+
messageId: 'moveToNewLine',
1435+
data: { descriptor: 'button' },
1436+
},
1437+
],
1438+
parserOptions,
1439+
},
1440+
// TODO: handle in a single pass (see above)
1441+
{
1442+
code: `
1443+
<Layout>
1444+
<p>Welcome to your new Gatsby site.</p>
1445+
<p>Now go build something great.</p>
1446+
<h1>Hi people<button/></h1>
1447+
</Layout>
1448+
`,
1449+
output: `
1450+
<Layout>
1451+
<p>
1452+
Welcome to your new Gatsby site.
1453+
</p>
1454+
<p>
1455+
Now go build something great.
1456+
</p>
1457+
<h1>
1458+
Hi people<button/></h1>
1459+
</Layout>
1460+
`,
1461+
errors: [
1462+
{
1463+
messageId: 'moveToNewLine',
1464+
data: { descriptor: 'Welcome to your new Gatsby site.' },
1465+
},
1466+
{
1467+
messageId: 'moveToNewLine',
1468+
data: { descriptor: 'Now go build something great.' },
1469+
},
1470+
{
1471+
messageId: 'moveToNewLine',
1472+
data: { descriptor: 'Hi people' },
1473+
},
1474+
{
1475+
messageId: 'moveToNewLine',
1476+
data: { descriptor: 'button' },
1477+
},
1478+
],
1479+
parserOptions,
1480+
},
1481+
{
1482+
code: `
1483+
<Layout>
1484+
<p>
1485+
Welcome to your new Gatsby site.
1486+
</p>
1487+
<p>
1488+
Now go build something great.
1489+
</p>
1490+
<h1>
1491+
Hi people<button/></h1>
1492+
</Layout>
1493+
`,
1494+
output: `
1495+
<Layout>
1496+
<p>
1497+
Welcome to your new Gatsby site.
1498+
</p>
1499+
<p>
1500+
Now go build something great.
1501+
</p>
1502+
<h1>
1503+
Hi people
1504+
<button/>
1505+
</h1>
1506+
</Layout>
1507+
`,
1508+
errors: [
1509+
{
1510+
messageId: 'moveToNewLine',
1511+
data: { descriptor: 'button' },
1512+
},
1513+
],
1514+
parserOptions,
1515+
},
1516+
// TODO: handle in a single pass
1517+
{
1518+
code: `
1519+
<Layout>
1520+
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
1521+
<Image />
1522+
</div><Link to="/page-2/">Go to page 2</Link>
1523+
</Layout>
1524+
`,
1525+
output: `
1526+
<Layout>
1527+
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
1528+
<Image />
1529+
</div>
1530+
<Link to="/page-2/">Go to page 2</Link>
1531+
</Layout>
1532+
`,
1533+
errors: [
1534+
{
1535+
messageId: 'moveToNewLine',
1536+
data: { descriptor: 'Link' },
1537+
},
1538+
{
1539+
messageId: 'moveToNewLine',
1540+
data: { descriptor: 'Go to page 2' },
1541+
},
1542+
],
1543+
parserOptions,
1544+
},
1545+
{
1546+
code: `
1547+
<Layout>
1548+
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
1549+
<Image />
1550+
</div>
1551+
<Link to="/page-2/">Go to page 2</Link>
1552+
</Layout>
1553+
`,
1554+
output: `
1555+
<Layout>
1556+
<div style={{ maxWidth: \`300px\`, marginBottom: \`1.45rem\` }}>
1557+
<Image />
1558+
</div>
1559+
<Link to="/page-2/">
1560+
Go to page 2
1561+
</Link>
1562+
</Layout>
1563+
`,
1564+
errors: [
1565+
{
1566+
messageId: 'moveToNewLine',
1567+
data: { descriptor: 'Go to page 2' },
1568+
},
1569+
],
1570+
parserOptions,
1571+
},
13921572
]),
13931573
});

0 commit comments

Comments
 (0)