Skip to content

garvae/eslint-plugin-comments

Repository files navigation

eslint-plugin-comments by @Garvae


Various rules for ESLint to work with comments



eslint-plugin-comments cover


πŸ›  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

contact me

πŸ”— Links


πŸš€ Mentoring

If you want to grow πŸš€ fast in front-end development - contact me! πŸ™‹β€β™‚


πŸ“„ License

See license in the "LICENCE" file

About

Various rules for ESLint to work with comments

Resources

License

Stars

Watchers

Forks

Packages

No packages published