eslint-plugin-comments by @Garvae
Various rules for ESLint to work with comments
1. Install ESLint if you haven't already
npm i eslint --save-devnpm:
npm -i --save-dev @garvae/eslint-plugin-commentsyarn:
yarn add -D @garvae/eslint-plugin-comments{
"plugins": ["@garvae/comments"],
"rules": {
"@garvae/comments/no-line-comments": "error"
}
}The no-line-comments rule of the @garvae/eslint-plugin-comments plugin can help you to enforce
special style for Line (double slash) type comments.
This rule returns an error for all comments of type Line (double slash) unless the special options of this rule (ingore*) are specified.
The format of this rule can be applied if both --fix option of ESLint and fixable = true option of this rule are specified.
βοΈ Automatically fixable by the --fix CLI option
βοΈ Flexible settings
| option | description |
type | default |
|---|---|---|---|
fixable |
Enables auto-fix by the --fix ESLint CLI option. Disabled by default because you may want to check all comments first |
boolean |
false |
ignore |
Defines the conditions under which a comment will be ignored by the rule | Object |
undefined |
ignore.startsWith |
A comment will be ignored by the rule if it starts with one of the strings defined in the array of strings passed to this rule parameter. | Array<string> |
undefined |
ignore.includes |
A comment will be ignored by the rule if it includes one of the strings defined in the array of strings passed to this rule parameter. | Array<string> |
undefined |
singleLineToSingleLineBlock |
If this option is false (default), a 'Line' type (not 'Block' type / starred) comment will be formatted into a multi-line 'Block' type (starred) comment, otherwise the comment will be formatted into a valid single-line 'Block' type (starred) comment |
boolean |
false |
Example (all options):
{
"@garvae/comments/no-line-comments": [
"error",
{
"fixable": true,
"ignore": {
"startsWith": ["keyword", "key-phrase"],
"includes": ["keyword", "key-phrase"]
},
"singleLineToSingleLineBlock": true
}
]
}{
"@garvae/comments/no-line-comments": "error"
}Examples of π incorrect code for these options:
// single-line comment// single-line comment
// single-line comment/**
* multiline comment
* line with wrong offset - Expected all lines to be aligned with the start of the comment
*//**
* multiline comment
line without a '*' symbol - Expected a '*' symbol at the start of each line of the starred-block comment
*/Examples of π correct code for these options:
/**
* single-line comment
*//**
* single-line comment
* single-line comment
*//**
* multiline comment
* line with valid offset
*//**
* multiline comment
* line with a '*' symbol
*/{
"@garvae/comments/no-line-comments": [
"error",
{
"singleLineToSingleLineBlock": true
}
]
}Examples of π incorrect code for these options:
// single-line comment/* "Block" comment without ending spacing*//*"Block" comment without leading spacing */Examples of π correct code for these options:
/* single-line comment *//**
* single-line comment
*/{
"@garvae/comments/no-line-comments": [
"error",
{
"ignore": { "startsWith": ["keyword", "key-phrase"] }
}
]
}Examples of π incorrect code for these options:
// single line commentExamples of π correct code for these options:
// keyword single-line comment (will be ignored)// key-phrase single-line comment (will be ignored){
"@garvae/comments/no-line-comments": [
"error",
{
"ignore": { "includes": ["keyword", "key-phrase"] }
}
]
}Examples of π incorrect code for these options:
// single-line commentExamples of π correct code for these options:
// single-line comment with keyword (will be ignored)// single-line comment with key-phrase (will be ignored)Read about "multiline-comment-style" rule by Teddy Katz.
no-line-comments by @Garvae and multiline-comment-style by Teddy Katz can complement each other
π€ Contributions, issues and feature requests are welcome!
Feel free to check issues page and pull request page.
β€οΈ Give a β if you like this project!
π Contact page
If you want to grow π fast in front-end development - contact me! πββ
