Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docs: Distinguish examples in rules under Stylistic Issues part 6 (#6567
- Loading branch information
1 parent
5ec54be
commit f6b8452
Showing
5 changed files
with
79 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,47 @@ | ||
# Disallow trailing spaces at the end of lines (no-trailing-spaces) | ||
# disallow trailing whitespace at the end of lines (no-trailing-spaces) | ||
|
||
(fixable) The `--fix` option on the [command line](../user-guide/command-line-interface#fix) automatically fixes problems reported by this rule. | ||
|
||
Sometimes in the course of editing files, you can end up with extra whitespace at the end of lines. These whitespace differences can be picked up by source control systems and flagged as diffs, causing frustration for developers. While this extra whitespace causes no functional issues, many code conventions require that trailing spaces be removed before checkin. | ||
Sometimes in the course of editing files, you can end up with extra whitespace at the end of lines. These whitespace differences can be picked up by source control systems and flagged as diffs, causing frustration for developers. While this extra whitespace causes no functional issues, many code conventions require that trailing spaces be removed before check-in. | ||
|
||
## Rule Details | ||
|
||
The following patterns are considered problems: | ||
This rule disallows trailing whitespace (spaces, tabs, and other Unicode whitespace characters) at the end of lines. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
/*eslint no-trailing-spaces: "error"*/ | ||
|
||
// spaces, tabs and unicode whitespaces | ||
// are not allowed at the end of lines | ||
var foo = 0;//••••• | ||
var baz = 5;//•• | ||
//••••• | ||
``` | ||
|
||
The following patterns are not considered problems: | ||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
/*eslint no-trailing-spaces: "error"*/ | ||
|
||
var foo = 0; | ||
|
||
var baz = 5; | ||
``` | ||
|
||
## Options | ||
|
||
There is one option for this rule, `skipBlankLines`. When set to true, the rule will not flag any lines that are made up purely of whitespace. In short, if a line is zero-length after being trimmed of whitespace, then the rule will not flag that line when `skipBlankLines` is enabled. | ||
This rule has an object option: | ||
|
||
You can enable this option in your config like this: | ||
* `"skipBlankLines": false` (default) disallows trailing whitespace on empty lines | ||
* `"skipBlankLines": true` allows trailing whitespace on empty lines | ||
|
||
```json | ||
{ | ||
"no-trailing-spaces": ["error", { "skipBlankLines": true }] | ||
} | ||
``` | ||
### skipBlankLines | ||
|
||
With this option enabled, The following patterns are not considered problems: | ||
Examples of **correct** code for this rule with the `{ "skipBlankLines": true }` option: | ||
|
||
```js | ||
/*eslint no-trailing-spaces: ["error", { "skipBlankLines": true }]*/ | ||
|
||
var foo = 0; | ||
//•••• | ||
var baz = 5; | ||
//••••• | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.