stylelint: Lint CSS and SCSS in CI
stylelint checks stylesheet files against its rules and exits 2 when problems are found, 0 when clean.
stylelint is the standard CSS/SCSS linter. In CI you pass it a glob, choose a formatter, and optionally fail on warnings.
What it does
stylelint takes a file glob, loads the config, runs the rules, and prints problems. It exits 2 when lint errors are found, 1 on a configuration or usage error, and 0 when clean. --max-warnings turns warning-level results into a failure too.
Common usage
npx stylelint "src/**/*.{css,scss}"
# fail if there are any warnings
npx stylelint "src/**/*.css" --max-warnings 0
# CI-friendly formatter
npx stylelint "**/*.css" --formatter githubFlags
| Flag | What it does |
|---|---|
| "<glob>" | Files to lint (quote it so the shell does not expand) |
| --max-warnings <n> | Exit non-zero past this many warnings (0 = strict) |
| --formatter <name> | Output format (string, json, github, compact) |
| --fix | Autofix problems where possible |
| --allow-empty-input | Do not error when the glob matches no files |
| --cache | Only re-lint changed files |
In CI
Quote the glob so stylelint, not the shell, expands it; an unquoted pattern can match nothing or the wrong files. Set --max-warnings 0 to make warnings fail CI, since by default warnings exit 0 and slip through.
Common errors in CI
"No files matching the pattern ... were found" means the glob is wrong or the shell expanded it; quote it or add --allow-empty-input. "No configuration provided" means stylelint found no config file. "Unknown rule X" means a rule from a plugin you have not added to plugins.