Skip to content

torchbox/stylelint-config-torchbox

Repository files navigation

Shareable stylelint config for CSS and SCSS, following Torchbox’s code style.

Usage

Install stylelint, and the config:

npm install --save-dev stylelint stylelint-config-torchbox

Then configure stylelint to use this config. As a stylelint.config.js or stylelint.config.mjs in the root of your project:

/** @type {import('stylelint').Config} */
export default {
  // See https://github.com/torchbox/stylelint-config-torchbox for rules.
  extends: 'stylelint-config-torchbox',
};

Tips

Linting setup for ongoing projects

Review our CHANGELOG for guidance on how to upgrade a project’s linting to a specific version.

More generally, when retrofitting stricter linting onto an existing project, consider a gradual approach to linting strictness, so you can start using linting without having to change significant portions of the project’s code. Here is an example, disabling commonly hard-to-retrofit rules:

// Rules which we ideally would want to enforce but are reporting too many issues currently.
const legacyRules = {
  'max-nesting-depth': null,
  'selector-max-specificity': null,
};

/** @type {import('stylelint').Config} */
export default {
  // See https://github.com/torchbox/stylelint-config-torchbox for rules.
  extends: 'stylelint-config-torchbox',
  rules: {
    ...legacyRules,
  },
};

Agent skills

This is new - please share feedback about agent skills if you use this on projects!

This project ships an upgrading-stylelint agent skill for AI coding agents. It is meant for auditing or carrying out a Stylelint upgrade, including checking the upgrade path, reviewing migration guides, updating dependencies or config, running QA, and reporting follow-up work.

Install the project skills with Vercel Lab’s Agent Skills:

npx skills add torchbox/stylelint-config-torchbox

Example prompt:

Use the upgrading-stylelint skill to upgrade this project from Stylelint 16 to 17, including updating to the compatible stylelint-config-torchbox version. Update dependencies and config as needed, update as much of the styles as you can if safe.

Common CLI flags

We recommend the following run script to add to your package.json:

"lint:css": "stylelint --report-needless-disables --report-unscoped-disables 'src/sass' 'src/vue'"
  • Use --report-needless-disables to ensure you do not use more stylelint-disable comments than needed.
  • Use --report-unscoped-disables to prevent fully disabling linting.
  • Target specific folders so Stylelint doesn’t attempt to lint other file types, say JS or HTML files.

.stylelintignore

Stylelint supports ignore patterns in a .stylelintignore file, however we tend not to use this since we lint all files within a given folder.

Prettier

This config is Prettier-compatible, there isn’t anything extra needed.

Tailwind

This config should work with Tailwind with no adjustments needed. Please submit an issue if that’s not the case.

prek for pre-commit hooks

We recommend prek, an implementation of the pre-commit framework to manage hooks. Our sample setup uses a standard .pre-commit-config.yaml, so the same configuration also works with pre-commit if needed:

default_language_version:
  node: system
repos:
  - repo: https://github.com/thibaudcolas/pre-commit-stylelint
    rev: v17.4.0
    hooks:
      - id: stylelint
        files: \.(scss|vue)$
        additional_dependencies:
          - stylelint@17.4.0
          - stylelint-config-torchbox@5.0.0

Vue

Stylelint supports Vue, and our configuration is usable in .vue single-file components with no changes. Do make sure linting is configured to check .vue files:

  • Wherever stylelint is manually invoked, make sure to point it both at stylesheets, and Vue components: stylelint --report-needless-disables --report-unscoped-disables './src/sass' './src/vue_components'.
  • With stylelint-webpack-plugin, use extensions: ['scss', 'vue'],.
  • With prek or pre-commit, use files: \.(scss|vue)$.

Related tools

To get the most out of this config, it is assumed that projects have the following tools set up:

What’s included

See config.js for the config definition. This package includes configuration from:

Rules

For the full list of enabled, disabled, and unused rules, view src/rules.md.

Custom rules

Inherited rules

Contributing

See the contribution guidelines for guidance and setup instructions.

About

Shareable stylelint config for CSS and SCSS, following Torchbox’s code style.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors