Skip to content

[Docs] jsx-one-expression-per-line #1552

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

Merged
merged 1 commit into from
Nov 19, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Finally, enable all of the rules that you would like to use. Use [our preset](#
* [react/jsx-no-literals](docs/rules/jsx-no-literals.md): Prevent usage of unwrapped JSX strings
* [react/jsx-no-target-blank](docs/rules/jsx-no-target-blank.md): Prevent usage of unsafe `target='_blank'`
* [react/jsx-no-undef](docs/rules/jsx-no-undef.md): Disallow undeclared variables in JSX
* [react/jsx-one-expression-per-line](docs/rules/jsx-one-expression-per-line.md): Limit to one expression per line in JSX
* [react/jsx-curly-brace-presence](docs/rules/jsx-curly-brace-presence.md): Enforce curly braces or disallow unnecessary curly braces in JSX
* [react/jsx-pascal-case](docs/rules/jsx-pascal-case.md): Enforce PascalCase for user-defined JSX components
* [react/jsx-sort-props](docs/rules/jsx-sort-props.md): Enforce props alphabetical sorting (fixable)
Expand Down
104 changes: 104 additions & 0 deletions docs/rules/jsx-one-expression-per-line.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# One JSX Element Per Line (react/jsx-indent)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong rule name

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol whoops, good catch. i'll fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad!


This option limits every line in JSX to one expression each.

**Fixable:** This rule is automatically fixable using the `--fix` flag on the command line.
Fixer will insert line breaks between any expression that are on the same line.

## Rule Details

The following patterns are considered warnings:

```jsx
<App><Hello /></App>

<App><Hello />
</App>

<App>
<Hello>
</Hello></App>

<App>
</Hello> World
</App>

<App>
</Hello> { 'World' }
</App>

<App>
</Hello> { this.world() }
</App>

<App>
{ 'Hello' }{ ' ' }{ 'World' }
</App>

<App
foo
><Hello />
</App>

<App><Hello
foo
/>
</App>

<App><Hello1 />
<Hello2 />
<Hello3 />
</App>
```

The following patterns are **not** warnings:

```jsx
<App>
<Hello />
</App>

<App>
<Hello>
</Hello>
</App>

<App>
</Hello>
World
</App>

<App>
</Hello>
{ 'World' }
</App>

<App>
</Hello>
{ this.world() }
</App>

<App>
{ 'Hello' }
{ ' ' }
{ 'World' }
</App>

<App
foo
>
<Hello />
</App>

<App>
<Hello
foo
/>
</App>

<App>
<Hello1 />
<Hello2 />
<Hello3 />
</App>
```
4 changes: 2 additions & 2 deletions lib/rules/jsx-one-expression-per-line.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview Limit to one element tag per line in JSX
* @fileoverview Limit to one expression per line in JSX
* @author Mark Ivan Allen <Vydia.com>
*/

Expand All @@ -12,7 +12,7 @@
module.exports = {
meta: {
docs: {
description: 'Limit to one element tag per line in JSX',
description: 'Limit to one expression per line in JSX',
category: 'Stylistic Issues',
recommended: false
},
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/rules/jsx-one-expression-per-line.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @fileoverview Limit to one element tag per line in JSX
* @fileoverview Limit to one expression per line in JSX
* @author Mark Ivan Allen <Vydia.com>
*/

Expand Down