@garvae/eslint-plugin-comments
v1.0.7
Published
Various rules for ESLint to work with comments
Downloads
51
Maintainers
Readme
eslint-plugin-comments by @Garvae
Various rules for ESLint to work with comments
🛠 Installation
1. Install ESLint if you haven't already
npm i eslint --save-dev
2. Install package
npm:
npm -i --save-dev @garvae/eslint-plugin-comments
yarn:
yarn add -D @garvae/eslint-plugin-comments
3. Add the plugin and the rule to the ESLint config
{
"plugins": ["@garvae/comments"],
"rules": {
"@garvae/comments/no-line-comments": "error"
}
}
📦 Rules
🧾 no-line-comments
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.
💪 Benefits
✔️ Automatically fixable by the --fix
CLI option
✔️ Flexible settings
⚙ Options
| 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
}
]
}
⚡ Examples
⚙ Default options
{
"@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
*/
⚙ singleLineToSingleLineBlock
option
{
"@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
*/
⚙ ignore
option + startsWith
{
"@garvae/comments/no-line-comments": [
"error",
{
"ignore": { "startsWith": ["keyword", "key-phrase"] }
}
]
}
Examples of 👎 incorrect code for these options:
// single line comment
Examples of 👍 correct code for these options:
// keyword single-line comment (will be ignored)
// key-phrase single-line comment (will be ignored)
⚙ ignore
option + includes
{
"@garvae/comments/no-line-comments": [
"error",
{
"ignore": { "includes": ["keyword", "key-phrase"] }
}
]
}
Examples of 👎 incorrect code for these options:
// single-line comment
Examples of 👍 correct code for these options:
// single-line comment with keyword (will be ignored)
// single-line comment with key-phrase (will be ignored)
💎 Recommendations
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
🤝 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 me
🌐 Contact page
🔳 QR code
🔗 Links
🚀 Mentoring
If you want to grow 🚀 fast in front-end development - contact me! 🙋♂