Skip to content

Commit 60b96d3

Browse files
Ensiveljharb
authored andcommitted
[guide] Add a 19.9 bullet in a Whitespace section
- with explanations about preventing two blank lines from appearing consecutively in JavaScript code
1 parent b85baea commit 60b96d3

File tree

1 file changed

+66
-11
lines changed

1 file changed

+66
-11
lines changed

README.md

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2656,8 +2656,63 @@ Other Style Guides
26562656
}
26572657
```
26582658
2659+
<a name="whitespace--no-multiple-blanks"></a>
2660+
- [19.9](#whitespace--no-multiple-blanks) Do not use multiple blank lines to pad your code. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines)
2661+
2662+
<!-- markdownlint-disable MD012 -->
2663+
```javascript
2664+
// bad
2665+
class Person {
2666+
constructor(fullName, email, birthday) {
2667+
this.fullName = fullName;
2668+
2669+
2670+
this.email = email;
2671+
2672+
2673+
this.setAge(birthday);
2674+
}
2675+
2676+
2677+
setAge(birthday) {
2678+
const today = new Date();
2679+
2680+
2681+
const age = this.getAge(today, birthday);
2682+
2683+
2684+
this.age = age;
2685+
}
2686+
2687+
2688+
getAge(today, birthday) {
2689+
// ..
2690+
}
2691+
}
2692+
2693+
// good
2694+
class Person {
2695+
constructor(fullName, email, birthday) {
2696+
this.fullName = fullName;
2697+
this.email = email;
2698+
this.setAge(birthday);
2699+
}
2700+
2701+
2702+
setAge(birthday) {
2703+
const today = new Date();
2704+
const age = getAge(today, birthday);
2705+
this.age = age;
2706+
}
2707+
2708+
getAge(today, birthday) {
2709+
// ..
2710+
}
2711+
}
2712+
```
2713+
26592714
<a name="whitespace--in-parens"></a><a name="18.9"></a>
2660-
- [19.9](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](https://eslint.org/docs/rules/space-in-parens.html)
2715+
- [19.10](#whitespace--in-parens) Do not add spaces inside parentheses. eslint: [`space-in-parens`](https://eslint.org/docs/rules/space-in-parens.html)
26612716
26622717
```javascript
26632718
// bad
@@ -2682,7 +2737,7 @@ Other Style Guides
26822737
```
26832738
26842739
<a name="whitespace--in-brackets"></a><a name="18.10"></a>
2685-
- [19.10](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](https://eslint.org/docs/rules/array-bracket-spacing.html)
2740+
- [19.11](#whitespace--in-brackets) Do not add spaces inside brackets. eslint: [`array-bracket-spacing`](https://eslint.org/docs/rules/array-bracket-spacing.html)
26862741
26872742
```javascript
26882743
// bad
@@ -2695,7 +2750,7 @@ Other Style Guides
26952750
```
26962751
26972752
<a name="whitespace--in-braces"></a><a name="18.11"></a>
2698-
- [19.11](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing.html)
2753+
- [19.12](#whitespace--in-braces) Add spaces inside curly braces. eslint: [`object-curly-spacing`](https://eslint.org/docs/rules/object-curly-spacing.html)
26992754
27002755
```javascript
27012756
// bad
@@ -2706,7 +2761,7 @@ Other Style Guides
27062761
```
27072762
27082763
<a name="whitespace--max-len"></a><a name="18.12"></a>
2709-
- [19.12](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html)
2764+
- [19.13](#whitespace--max-len) Avoid having lines of code that are longer than 100 characters (including whitespace). Note: per [above](#strings--line-length), long strings are exempt from this rule, and should not be broken up. eslint: [`max-len`](https://eslint.org/docs/rules/max-len.html)
27102765
27112766
> Why? This ensures readability and maintainability.
27122767
@@ -2736,7 +2791,7 @@ Other Style Guides
27362791
```
27372792
27382793
<a name="whitespace--block-spacing"></a>
2739-
- [19.13](#whitespace--block-spacing) Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint: [`block-spacing`](https://eslint.org/docs/rules/block-spacing)
2794+
- [19.14](#whitespace--block-spacing) Require consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line. eslint: [`block-spacing`](https://eslint.org/docs/rules/block-spacing)
27402795
27412796
```javascript
27422797
// bad
@@ -2749,7 +2804,7 @@ Other Style Guides
27492804
```
27502805
27512806
<a name="whitespace--comma-spacing"></a>
2752-
- [19.14](#whitespace--comma-spacing) Avoid spaces before commas and require a space after commas. eslint: [`comma-spacing`](https://eslint.org/docs/rules/comma-spacing)
2807+
- [19.15](#whitespace--comma-spacing) Avoid spaces before commas and require a space after commas. eslint: [`comma-spacing`](https://eslint.org/docs/rules/comma-spacing)
27532808
27542809
```javascript
27552810
// bad
@@ -2762,7 +2817,7 @@ Other Style Guides
27622817
```
27632818
27642819
<a name="whitespace--computed-property-spacing"></a>
2765-
- [19.15](#whitespace--computed-property-spacing) Enforce spacing inside of computed property brackets. eslint: [`computed-property-spacing`](https://eslint.org/docs/rules/computed-property-spacing)
2820+
- [19.16](#whitespace--computed-property-spacing) Enforce spacing inside of computed property brackets. eslint: [`computed-property-spacing`](https://eslint.org/docs/rules/computed-property-spacing)
27662821
27672822
```javascript
27682823
// bad
@@ -2779,7 +2834,7 @@ Other Style Guides
27792834
```
27802835
27812836
<a name="whitespace--func-call-spacing"></a>
2782-
- [19.16](#whitespace--func-call-spacing) Avoid spaces between functions and their invocations. eslint: [`func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing)
2837+
- [19.17](#whitespace--func-call-spacing) Avoid spaces between functions and their invocations. eslint: [`func-call-spacing`](https://eslint.org/docs/rules/func-call-spacing)
27832838
27842839
```javascript
27852840
// bad
@@ -2793,7 +2848,7 @@ Other Style Guides
27932848
```
27942849
27952850
<a name="whitespace--key-spacing"></a>
2796-
- [19.17](#whitespace--key-spacing) Enforce spacing between keys and values in object literal properties. eslint: [`key-spacing`](https://eslint.org/docs/rules/key-spacing)
2851+
- [19.18](#whitespace--key-spacing) Enforce spacing between keys and values in object literal properties. eslint: [`key-spacing`](https://eslint.org/docs/rules/key-spacing)
27972852
27982853
```javascript
27992854
// bad
@@ -2805,10 +2860,10 @@ Other Style Guides
28052860
```
28062861
28072862
<a name="whitespace--no-trailing-spaces"></a>
2808-
- [19.18](#whitespace--no-trailing-spaces) Avoid trailing spaces at the end of lines. eslint: [`no-trailing-spaces`](https://eslint.org/docs/rules/no-trailing-spaces)
2863+
- [19.19](#whitespace--no-trailing-spaces) Avoid trailing spaces at the end of lines. eslint: [`no-trailing-spaces`](https://eslint.org/docs/rules/no-trailing-spaces)
28092864
28102865
<a name="whitespace--no-multiple-empty-lines"></a>
2811-
- [19.19](#whitespace--no-multiple-empty-lines) Avoid multiple empty lines and only allow one newline at the end of files. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines)
2866+
- [19.20](#whitespace--no-multiple-empty-lines) Avoid multiple empty lines and only allow one newline at the end of files. eslint: [`no-multiple-empty-lines`](https://eslint.org/docs/rules/no-multiple-empty-lines)
28122867
28132868
<!-- markdownlint-disable MD012 -->
28142869
```javascript

0 commit comments

Comments
 (0)