Skip to content

buschtoens/eslint-formatter-todo

 
 

Repository files navigation

@scalvert/eslint-formatter-todo

CI Build npm version License Dependabot Volta Managed TypeScript Code Style: prettier

An ESLint formatter that can report errors as todos, which can be deferred and fixed at a later time.

Linting is a fundamental tool to help ensure the quality of a codebase. Ensuring there are as few linting errors as possible (ideally 0), is a useful measure of a baseline of code hygiene.

It's common to leverage linting not just for syntax adherence, but also to direct developers to employ standardized patterns. As such, it's a fairly routine activity to introduce new lint rules into a codebase. This introduction, while necessary, can cause unintended friction, such as:

  • new lint errors being introduced where they previously didn't exist
  • causing unintended delays to shipping new fixes and features
  • an "all or nothing" approach, where new rules require fixing before rollout

Having the ability to identify violations as todos allows for this incremental roll out, while providing tools that allow maintainers to view the full list of todo violations.

This formatter allows you to introduce new rules immediately, without blocking commits, by taking a snapshot of errors and transforming them to todos. Errors not found in this snapshot will continue to reported as errors.

Usage

Todos are stored in a .lint-todo directory that should be checked in with other source code. Each error generates a unique file, allowing for multiple errors within a single file to be resolved individually with minimal conflicts.

To convert errors to todos, you can use the UPDATE_TODO environment variable. This will convert all active errors to todos, hiding them from the linting output.

UPDATE_TODO=1 eslint --format @scalvert/eslint-formatter-todo

If you want to see todos as part of eslint's output, you can include them

If an error is fixed manually, eslint will let you know that there's an outstanding todo file. You can remove this file by running --fix

eslint . --format @scalvert/eslint-formatter-todo --fix

Configuring Due Dates

Todos can be created with optional due dates. These due dates allow for todos to, over a period of time, 'decay' the severity to a warning and/or error after a certain date. This helps ensure that todos are created but not forgotten, and can allow for better managing incremental roll-outs of large-scale or slow-to-fix rules.

Due dates can be configured in one of two ways, but both specify integers for warn and error to signify the number of days from the todo created date to decay the severity.

💡 Both warn and error are optional. The value for warn should be greater than the value of error.

  1. Via package.json configuration
{
  "lintTodo": {
    "decayDays": {
      "warn": 5,
      "error": 10
    }
  }
}
  1. Via environment variables
UPDATE_TODO='1' TODO_DAYS_TO_WARN="5" TODO_DAYS_TO_ERROR="10" eslint . --format @scalvert/eslint-formatter-todo

In order of precedence, environment variables override package.json configuration values.

For example, if you've specified the following values in the package.json configuration...

{
  "lintTodo": {
    "decayDays": {
      "warn": 5,
      "error": 10
    }
  }
}

...and you supply the following environment variables:

UPDATE_TODO='1' TODO_DAYS_TO_WARN= '2' eslint . --format @scalvert/eslint-formatter-todo

...the todos will be created with a warn date 2 days from the created date, and an error date 10 days from the created date.

Due Date Workflows

Converting errors to todos with warn and error dates that transition the todo to warn after 10 days and error after 20 days:

UPDATE_TODO='1' TODO_DAYS_TO_WARN= '10' TODO_DAYS_TO_ERROR='20' eslint . --format @scalvert/eslint-formatter-todo

Converting errors to todos with warn and error dates that transition the todo error after 20 days, but doesn't include a warn date:

UPDATE_TODO='1' TODO_DAYS_TO_WARN= '' TODO_DAYS_TO_ERROR='20' eslint . --format @scalvert/eslint-formatter-todo

About

eslint formatter to provide todo functionality

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.4%
  • JavaScript 1.6%