1.0.7 โ€ข Published 7 months ago

@garvae/eslint-plugin-comments v1.0.7

Weekly downloads
-
License
SEE LICENSE IN TH...
Repository
github
Last release
7 months ago

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

optiondescriptiontypedefault
fixableEnables auto-fix by the --fix ESLint CLI option. Disabled by default because you may want to check all comments firstbooleanfalse
ignoreDefines the conditions under which a comment will be ignored by the ruleObjectundefined
ignore.startsWithA 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.includesA 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
singleLineToSingleLineBlockIf 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) commentbooleanfalse

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! ๐Ÿ™‹โ€โ™‚

๐Ÿ“„ License

See license in the "LICENCE" file

1.0.7

7 months ago

1.0.5

12 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago