diff --git a/CHANGELOG.md b/CHANGELOG.md index b08d587b56..6b8a610a50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/lib/rules/jsx-indent.js b/tests/lib/rules/jsx-indent.js index ce4733d8fa..0823b406e4 100644 --- a/tests/lib/rules/jsx-indent.js +++ b/tests/lib/rules/jsx-indent.js @@ -45,7 +45,7 @@ ruleTester.run('jsx-indent', rule, { { code: ` - + `, }, { @@ -3001,6 +3001,135 @@ const Component = () => ( }, ], }, + { + code: ` + const IndexPage = () => ( +

+ {"Hi people"} +

+ ); + `, + output: ` + const IndexPage = () => ( +

+ {"Hi people"} +

+ ); + `, + 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 = () => ( +

+ Hi people +

+ ); + `, + + output: ` + const IndexPage = () => ( +

+ Hi people +

+ ); + `, + 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 = () => ( +

+ Hi people +

+ ); + `, + + output: ` + const IndexPage = () => ( +

+ Hi people +

+ ); + `, + options: [2], + errors: [ + { + messageId: 'wrongIndent', + data: { + needed: 12, + type: 'space', + characters: 'characters', + gotten: 8, + }, + }, + ], + }, semver.satisfies(eslintVersion, '> 4') ? { code: ` import React from 'react'; diff --git a/tests/lib/rules/jsx-one-expression-per-line.js b/tests/lib/rules/jsx-one-expression-per-line.js index a8ba820d02..0c684c7da5 100644 --- a/tests/lib/rules/jsx-one-expression-per-line.js +++ b/tests/lib/rules/jsx-one-expression-per-line.js @@ -1389,5 +1389,185 @@ a ], parserOptions, }, + { + // TODO: handle in a single pass + code: ` + const IndexPage = () => ( +

{"Hi people"}

+ ); + `, + output: ` + const IndexPage = () => ( +

+{"Hi people"}

+ ); + `, + errors: [ + { + messageId: 'moveToNewLine', + data: { descriptor: '{"Hi people"}' }, + }, + { + messageId: 'moveToNewLine', + data: { descriptor: 'button' }, + }, + ], + parserOptions, + }, + { + code: ` + const IndexPage = () => ( +

+{"Hi people"}

+ ); + `, + output: ` + const IndexPage = () => ( +

+{"Hi people"} +

+ ); + `, + errors: [ + { + messageId: 'moveToNewLine', + data: { descriptor: 'button' }, + }, + ], + parserOptions, + }, + // TODO: handle in a single pass (see above) + { + code: ` + +

Welcome to your new Gatsby site.

+

Now go build something great.

+

Hi people

+
+ `, + output: ` + +

+Welcome to your new Gatsby site. +

+

+Now go build something great. +

+

+Hi people

+
+ `, + 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: ` + +

+Welcome to your new Gatsby site. +

+

+Now go build something great. +

+

+Hi people

+
+ `, + output: ` + +

+Welcome to your new Gatsby site. +

+

+Now go build something great. +

+

+Hi people +

+
+ `, + errors: [ + { + messageId: 'moveToNewLine', + data: { descriptor: 'button' }, + }, + ], + parserOptions, + }, + // TODO: handle in a single pass + { + code: ` + +
+ +
Go to page 2 +
+ `, + output: ` + +
+ +
+Go to page 2 +
+ `, + errors: [ + { + messageId: 'moveToNewLine', + data: { descriptor: 'Link' }, + }, + { + messageId: 'moveToNewLine', + data: { descriptor: 'Go to page 2' }, + }, + ], + parserOptions, + }, + { + code: ` + +
+ +
+Go to page 2 +
+ `, + output: ` + +
+ +
+ +Go to page 2 + +
+ `, + errors: [ + { + messageId: 'moveToNewLine', + data: { descriptor: 'Go to page 2' }, + }, + ], + parserOptions, + }, ]), });