Skip to content

Commit cfd3959

Browse files
pfhayesljharb
authored andcommitted
[Docs] add jsx-child-element-spacing
1 parent 5e1a64c commit cfd3959

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Enforce or disallow spaces inside of curly braces in JSX attributes and expressions. (react/jsx-curly-spacing)
2+
3+
## Rule Details
4+
5+
Since React removes extraneous new lines between elements when possible,
6+
it is possible to end up with inline elements that are not rendered with spaces between them and adjacent text.
7+
This is often indicative of an error, so this rule attempts to detect
8+
9+
The following patterns are considered warnings:
10+
11+
```jsx
12+
<div>
13+
Here is a
14+
<a>link</a>
15+
</div>
16+
```
17+
18+
```jsx
19+
<div>
20+
<b>This text</b>
21+
is bold
22+
</div>
23+
```
24+
25+
The following patterns are **not** considered warnings:
26+
27+
```jsx
28+
<div>
29+
Spacing is
30+
{' '}
31+
<a>explicit</a>
32+
</div>
33+
```
34+
35+
```jsx
36+
<div>
37+
Lack of spacing is{/*
38+
*/}<a>explicit</a>
39+
</div>
40+
```
41+
42+
## When Not To Use It
43+
44+
You can turn this rule off if you are not concerned with inline elements appearing adjacent to text,
45+
or if you always explicitly include `{' '}` between elements to denote spacing.

lib/rules/jsx-child-element-spacing.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const docsUrl = require('../util/docsUrl');
4+
35
// This list is taken from https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
46
const INLINE_ELEMENTS = new Set([
57
'a',
@@ -40,7 +42,8 @@ module.exports = {
4042
docs: {
4143
description: 'Ensures inline tags are not rendered without spaces between them',
4244
category: 'Stylistic Issues',
43-
recommended: false
45+
recommended: false,
46+
url: docsUrl('jsx-child-element-spacing')
4447
},
4548
fixable: false,
4649
schema: [

0 commit comments

Comments
 (0)