Skip to content

Latest commit

 

History

History
140 lines (103 loc) · 3.05 KB

File metadata and controls

140 lines (103 loc) · 3.05 KB

Require a ticket reference in the TODO comment (todo-plz/ticket-ref)

Adding a TODO comment that will be addressed in the future should have a corresponding ticket (AKA issue) in the project backlog, so the team doesn't lose track of pending work.

Options

pattern

Type: RegExp | string

This option is required, and controls what the ticket pattern is to match against. Expects a regex string.

For example, let's say you're using Jira and your ticket IDs are prefixed with PROJ followed by a number (e.g PROJ-123), you would configure this rule like:

{
  "rules": {
    "todo-plz/ticket-ref": ["error", { "pattern": "PROJ-[0-9]+" }]
  }
}

Examples of incorrect code for this rule when using the above options:

// TODO: Connect to the API
// TODO (ABC-123): Connect to the API
// TODO (ABC): Connect to the API

Examples of correct code for this rule when using the above options:

// TODO (PROJ-123): Connect to the API

terms

Type: Array<string>

Optional. Change what terms to require the ticket reference on. Defaults to: ["TODO"]

{
  "rules": {
    "todo-plz/ticket-ref": [
      "error",
      { "pattern": "PROJ-[0-9]+", "terms": ["FIXME", "TODO"] }
    ]
  }
}

Examples of incorrect code for this rule when using the above options:

// TODO: Connect to the API
// FIXME: Connect to the API

Examples of correct code for this rule when using the above options:

// TODO (PROJ-123): Connect to the API
// FIXME (PROJ-123): Connect to the API
// HELLO: This isn't a term targeted by the lint rule

Advanced options

commentPattern

Type: RegExp | string

Optional. Override the overall comment pattern that matches both term and ticket. When used, term and pattern options are ignored. Expects a regex, or a string that can be passed to new RegExp.

For example, let's say you expect a different comment pattern such as TODO: [PROJ-123], you would configure this rule like this:

export default [
  {
    rules: {
      "todo-plz/ticket-ref": [
        "error",
        { commentPattern: /TODO:\s\[(PROJ-[0-9]+[,\s]*)+\]/ },
      ],
    },
  },
];

If you use a legacy JSON config, you would configure it like this:

{
  "rules": {
    "todo-plz/ticket-ref": [
      "error",
      { "commentPattern": /TODO:\s\[(PROJ-[0-9]+[,\s]*)+\]/ }
    ]
  }
}

Examples of incorrect code for this rule when using the above options:

// TODO (PROJ-456): Connect to the API
// TODO [PROJ-456]: Connect to the API

Examples of correct code for this rule when using the above options:

// TODO: [PROJ-456] Connect to the API

description

Type: string

Optional. Override the error message portion that provides guidance on the expected ticket pattern. Defaults to: Ticket pattern: <pattern>

{
  "rules": {
    "todo-plz/ticket-ref": [
      "error",
      {
        "pattern": "PROJ-[0-9]+",
        "description": "For example: `TODO (PROJ-123):`"
      }
    ]
  }
}