1 # enforce position of line comments (line-comment-position)
3 Line comments can be positioned above or beside code. This rule helps teams maintain a consistent style.
7 var foo = "bar"; // beside comment
12 This 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`.
16 This 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:
20 The `position` option has two settings:
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.
27 Examples of **correct** code for the `{ "position": "above" }` option:
30 /*eslint line-comment-position: ["error", { "position": "above" }]*/
35 Examples of **incorrect** code for the `{ "position": "above" }` option:
38 /*eslint line-comment-position: ["error", { "position": "above" }]*/
39 1 + 1; // invalid comment
44 Examples of **correct** code for the `{ "position": "beside" }` option:
47 /*eslint line-comment-position: ["error", { "position": "beside" }]*/
48 1 + 1; // valid comment
51 Examples of **incorrect** code for the `{ "position": "beside" }` option:
54 /*eslint line-comment-position: ["error", { "position": "beside" }]*/
61 By 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.
63 Examples of **correct** code for the `ignorePattern` option:
66 /*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/
67 1 + 1; // pragma valid comment
70 Examples of **incorrect** code for the `ignorePattern` option:
73 /*eslint line-comment-position: ["error", { "ignorePattern": "pragma" }]*/
74 1 + 1; // invalid comment
77 ### applyDefaultIgnorePatterns
79 Default ignore patterns are applied even when `ignorePattern` is provided. If you want to omit default patterns, set this option to `false`.
81 Examples of **correct** code for the `{ "applyDefaultIgnorePatterns": false }` option:
84 /*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
85 1 + 1; // pragma valid comment
88 Examples of **incorrect** code for the `{ "applyDefaultIgnorePatterns": false }` option:
91 /*eslint line-comment-position: ["error", { "ignorePattern": "pragma", "applyDefaultIgnorePatterns": false }]*/
92 1 + 1; // falls through
95 **Deprecated:** the object property `applyDefaultPatterns` is deprecated. Please use the property `applyDefaultIgnorePatterns` instead.
99 If you aren't concerned about having different line comment styles, then you can turn off this rule.
103 **JSCS**: [validateCommentPosition](https://jscs-dev.github.io/rule/validateCommentPosition)