]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/line-comment-position.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / line-comment-position.md
CommitLineData
eb39fafa
DC
1# enforce position of line comments (line-comment-position)
2
3Line comments can be positioned above or beside code. This rule helps teams maintain a consistent style.
4
5```js
6// above comment
7var foo = "bar"; // beside comment
8```
9
10## Rule Details
11
12This rule enforces consistent position of line comments. Block comments are not affected by this rule. By default, this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, `falls through`.
13
eb39fafa
DC
14## Options
15
16This rule takes one argument, which can be a string or an object. The string settings are the same as those of the `position` property (explained below). The object option has the following properties:
17
18### position
19
20The `position` option has two settings:
21
22* `above` (default) enforces line comments only above code, in its own line.
23* `beside` enforces line comments only at the end of code lines.
24
25#### position: above
26
27Examples of **correct** code for the `{ "position": "above" }` option:
28
29```js
30/*eslint line-comment-position: ["error", { "position": "above" }]*/
31// valid comment
321 + 1;
33```
34
eb39fafa
DC
35Examples of **incorrect** code for the `{ "position": "above" }` option:
36
37```js
38/*eslint line-comment-position: ["error", { "position": "above" }]*/
391 + 1; // invalid comment
40```
41
42#### position: beside
43
44Examples of **correct** code for the `{ "position": "beside" }` option:
45
46```js
47/*eslint line-comment-position: ["error", { "position": "beside" }]*/
481 + 1; // valid comment
49```
50
eb39fafa
DC
51Examples of **incorrect** code for the `{ "position": "beside" }` option:
52
53```js
54/*eslint line-comment-position: ["error", { "position": "beside" }]*/
55// invalid comment
561 + 1;
57```
58
59### ignorePattern
60
61By default this rule ignores comments starting with the following words: `eslint`, `jshint`, `jslint`, `istanbul`, `global`, `exported`, `jscs`, `falls through`. An alternative regular expression can be provided.
62
63Examples of **correct** code for the `ignorePattern` option:
64
65```js
66/*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/
671 + 1; // pragma valid comment
68```
69
70Examples of **incorrect** code for the `ignorePattern` option:
71
72```js
73/*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/
741 + 1; // invalid comment
75```
76
77### applyDefaultIgnorePatterns
78
79Default ignore patterns are applied even when `ignorePattern` is provided. If you want to omit default patterns, set this option to `false`.
80
81Examples of **correct** code for the `{ "applyDefaultIgnorePatterns": false }` option:
82
83```js
84/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
851 + 1; // pragma valid comment
86```
87
88Examples of **incorrect** code for the `{ "applyDefaultIgnorePatterns": false }` option:
89
90```js
91/*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
921 + 1; // falls through
93```
94
95**Deprecated:** the object property `applyDefaultPatterns` is deprecated. Please use the property `applyDefaultIgnorePatterns` instead.
96
97## When Not To Use It
98
99If you aren't concerned about having different line comment styles, then you can turn off this rule.
100
101## Compatibility
102
103**JSCS**: [validateCommentPosition](https://jscs-dev.github.io/rule/validateCommentPosition)