npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lint-todo/stylelint-formatter-todo

v1.1.0

Published

A Stylelint formatter that can report errors as todos.

Downloads

6

Readme

@lint-todo/stylelint-formatter-todo

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

A Stylelint 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 file that should be checked in with other source code. Each error generates a unique entry, 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 stylelint "**/*.css" --format @lint-todo/stylelint-formatter-todo

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

If an error is fixed manually, stylelint will automatically remove the todo when run again.

stylelint "**/*.css" --format @lint-todo/stylelint-formatter-todo

If you want to opt out of this behavior, you can run with the NO_CLEAN_TODO env var set.

# Will not remove the todo automatically
NO_CLEAN_TODO='1' stylelint "**/*.css" --format @lint-todo/stylelint-formatter-todo

To compact the .lint-todo storage file, you can use the COMPACT_TODO environment variable.

COMPACT_TODO=1 stylelint "**/*.css" --format @lint-todo/stylelint-formatter-todo

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.

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

  1. Via package.json configuration

    {
      "lintTodo": {
        "stylelint": {
          "decayDays": {
            "warn": 5,
            "error": 10
          }
        }
      }
    }
  2. Via .lint-todorc.js

    module.exports = {
      stylelint: {
        daysToDecay: {
          warn: 5,
          error: 10,
        },
      },
    };
  3. Via environment variables

    UPDATE_TODO='1' TODO_DAYS_TO_WARN="5" TODO_DAYS_TO_ERROR="10" stylelint "**/*.css" --format @lint-todo/stylelint-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": {
        "stylelint": {
          "decayDays": {
            "warn": 5,
            "error": 10
          }
        }
      }
    }

    ...and you supply the following environment variables:

    UPDATE_TODO='1' TODO_DAYS_TO_WARN= '2' stylelint "**/*.css" --format @lint-todo/stylelint-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.

Configuring Due Dates for Individual Rules

Due dates can be configured on a per-rule basis with the daysToDecayByRule option. See examples below.

  1. Via package.json

    {
      "lintTodo": {
        "stylelint": {
          "daysToDecay": {
            "warn": 5,
            "error": 10
          },
          "daysToDecayByRule": {
            "alpha-value-notation": {
              "warn": 10,
              "error": 20
            }
          }
        }
      }
    }
  2. Via .lint-todorc.js

    module.exports = {
      stylelint: {
        daysToDecay: {
          warn: 5,
          error: 10,
        },
        daysToDecayByRule: {
          'alpha-value-notation': {
            warn: 10,
            error: 20,
          },
        },
      },
    };

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' stylelint "**/*.css" --format @lint-todo/stylelint-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' stylelint "**/*.css" --format @lint-todo/stylelint-formatter-todo

Additional options for formatting output

This package will only format the data in todos with the pretty format.

If you need to preserve the todo functionality while outputting in a different format for your CI system, you can set an additional environment variable, FORMAT_TODO_AS, which references a node module that is installed in your project.

:warning: Note that additional functionality of this formatter is not supported (i.e., UPDATE_TODO, etc) when using the FORMAT_TODO_AS flag; this flag is strictly for modifying the command line output.

FORMAT_TODO_AS=stylelint-sarif-formatter stylelint "**/*.css" --format @lint-todo/stylelint-formatter-todo