2.1.1 • Published 4 months ago

eslint-plugin-todo-with-label v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

eslint-plugin-todo-with-label

node version npm version downloads count size license github-ci

🔨 ESLint plugin supports TODO comments with a label in parentheses

Give a ⭐️ if this project helped you!

Motivation

npm.io

When working with code, many times there will be a situation of creating a TODO in the code to indicate that you need to perform some action here, such as writing an error handler. In such situations, the creation of a TODO is understandable. On the other hand, it often happens that such a comment in the code is for a long time. Then people reading such code, who would like to solve the TODO comment, lack information about the author, so that they can turn to him for more details.

If we use this plugin, we will force everyone creating a TODO comment to define the author in parentheses. This way, we will always have a point of contact for the person we can ask for help.

Features

  • ✅ Validate format of TODOs in comments (default valid format is TODO(label): any text here)
  • ✅ Supports passing a custom pattern and types
  • ✅ Supports 8 comment types (by default): TODO, NOTE, COMMENT, FIXME, BUG, HACK, INFO, XXX
  • ✅ Autofix with --fix [#2]

Usage

Installation:

npm install -D eslint eslint-plugin-todo-with-label

Add todo-with-label to the plugins section of your .eslintrc.js configuration file:

module.exports = {
  // ...
  plugins: ["todo-with-label"],
  rules: {
    "todo-with-label/has-valid-pattern": "error",
  },
  // ...
};

Options

The optional configuration for rule todo-with-label/has-valid-pattern:

Option: types

Default value: ["TODO", "NOTE", "COMMENT", "FIXME", "BUG", "HACK", "INFO", "XXX"]

  • valid: TODO(label): any text here
  • valid: NOTE(label): any text here
  • valid: COMMENT(label): any text here
  • etc.

Example values:

  • ["TODO"]
    • valid: TODO(label): any text here
    • invalid: NOTE(label): any text here
  • ["FOO", "BAR", "BAZ"]
    • valid: FOO(label): any text here
    • valid: BAR(label): any text here
    • valid: BAZ(label): any text here
    • invalid: TODO(label): any text here
    • invalid: NOTE(label): any text here

Option: pattern

Default value: ^TODO\\((\\w+)\\)\\: (.*)$

  • valid: TODO(label): any text here
  • invalid: TODO: any text here
  • invalid: TODO - any text here

Example values:

  • ^TODO: (.*)$
    • valid: TODO: any text here
  • ^TODO\\((\\w+)\\)$
    • valid: TODO(label)
  • ^TODO\\((author:@\\w+)\\)\\: (.*)$
    • valid: TODO(author:@login): any text here

⚠️ WARNING: When you pass a pattern, it should be a string with escaped backslashes.

⚠️ WARNING 2: When you pass a pattern, you cannot use --fix option.

Examples

module.exports = {
  // ...
  plugins: ["todo-with-label"],
  rules: {
    "todo-with-label/has-valid-pattern": [
      "error",
      {
        types: ["TODO"],
        pattern: "^TODO\\((author:@\\w+)\\)\\: (.*)$",
      },
    ],
  },
};

Related

License

The MIT License @ 2023

2.1.1

4 months ago

2.1.0

4 months ago

2.0.8

5 months ago

2.0.7

8 months ago

2.0.5

8 months ago

2.0.4

8 months ago

2.0.6

8 months ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.1

8 months ago

2.0.0

1 year ago

1.0.0

2 years ago