Options
Options shared by the:
You can use some of these options in the configuration object.
allowEmptyInput
Section titled “allowEmptyInput”CLI flag: --allow-empty-input
Stylelint does not throw an error when glob pattern matches no files.
configFile
Section titled “configFile”CLI flag: --config, -c
Path to a JSON, YAML, or JS file that contains your configuration object.
Use this option if you don’t want Stylelint to search for a configuration file.
The path should be either absolute or relative to the directory that your process is running from (process.cwd()).
configBasedir
Section titled “configBasedir”CLI flag: --config-basedir
Absolute path to the directory that relative paths defining extends, plugins, and customSyntax are relative to. Only necessary if these values are relative paths.
CLI flag: --fix
Automatically fix, where possible, problems reported by rules.
The rules run in passes over the fixed code, up to 10 times, until a pass leaves the code unchanged. The PostCSS plugin runs one pass.
Options are:
"strict"(default) - uses PostCSS Parser and only fixes problems when there are no syntax errors"lax"- uses postcss-safe-parser to fix as much as possible, even when there are syntax errors
When using the Node.js API, the autofixed code is available as the value of the code property in the returned object.
computeEditInfo
Section titled “computeEditInfo”CLI flag: --compute-edit-info
Compute edit information for autofixable rules.
The edit information will not be computed when:
- the
fixoption is enabled - a rule’s fix is disabled:
- in the configuration object, e.g.
"rule-name": [true, { disableFix: true }] - using configuration comments, e.g.
/* stylelint-disable rule-name */
- in the configuration object, e.g.
- another edit has already been computed for the same code region
See Node.js API Warning details.
customSyntax
Section titled “customSyntax”CLI flag: --custom-syntax
Specify a custom syntax to use on your code.
There are many styling languages, ranging from CSS language extensions like SCSS to entirely different notations, e.g. CSS-in-JS objects.
These styling languages can be embedded within other languages too. For example:
- HTML
<style>tags - markdown fences
- JavaScript template literals
This option allows Stylelint to transform these into something that resembles CSS, which is the language that:
- underpins all the other styling languages
- is best understood by rules built into Stylelint
This option should be a string that resolves to a JS module that exports a PostCSS-compatible syntax. The string can be a module name (like my-module) or a path to a JS file (like path/to/my-module.js).
If you want to lint two or more different languages, you can combine customSyntax with the overrides configuration property.
Using the Node.js API, the customSyntax option can also accept a Syntax object. Stylelint treats the parse property as a required value. Also, Stylelint supports syntax modules written in ESM.
formatter
Section titled “formatter”CLI flags: --formatter, -f | --custom-formatter
Specify the formatter to format your results.
Options are:
compact- generates output similar to ESLint’s compact formattergithub- generates messages via workflow commands for GitHub Actions (DEPRECATED)json(default for Node API) - generates JSON that can be consumed by another toolstring(default for CLI) - generates human-readable stringstap- generates Test Anything Protocol outputunix- generates messages like a C compiler, so that tools like Emacs’ Compilation mode can hyperlink themverbose- extendsstringto include a list of checked files and a tally for each rule
The formatter Node.js API option can also accept a function or a Promise function, whereas the --custom-formatter CLI flag accepts a path (either a filesystem path or a dependency) to a JS file exporting one. The function in both cases must fit the signature described in the Developer Guide.
CLI flags: --color, --no-color
Force enabling/disabling of color in the formatted results.
When not set, the built-in formatters use color if node:util.styleText detects that the terminal supports it. node:util.styleText honors the FORCE_COLOR, NO_COLOR and NODE_DISABLE_COLORS environment variables.
CLI flag: --cache
Store the results of processed files so that Stylelint only operates on the changed ones. By default, the cache is stored in ./.stylelintcache in process.cwd().
The following values are used as cache keys:
- Stylelint version
- Options
Enabling this option can dramatically improve Stylelint’s speed because only changed files are linted.
If you run Stylelint with cache and then run Stylelint without cache, Stylelint deletes the .stylelintcache because we have to assume that the second command invalidated .stylelintcache.
cacheLocation
Section titled “cacheLocation”CLI flag: --cache-location
Path to a file or directory for the cache location.
If a directory is specified, Stylelint creates a cache file inside the specified folder. The name of the file is based on the hash of process.cwd() (e.g. .cache_hashOfCWD) so that Stylelint can reuse a single location for a variety of caches from different projects.
If the directory of cacheLocation does not exist, make sure you add a trailing / on *nix systems or \ on Windows. Otherwise, Stylelint assumes the path to be a file.
cacheStrategy
Section titled “cacheStrategy”CLI flag: --cache-strategy
Strategy for the cache to use for detecting changed files. Can be either “metadata” or “content”.
The “content” strategy can be useful in cases where the modification time of your files changes even if their contents have not. For example, this can happen during git operations like “git clone” because git does not track file modification time.
maxWarnings
Section titled “maxWarnings”CLI flag: --max-warnings
Set a limit to the number of warnings accepted.
It is useful when setting defaultSeverity to "warning" and expecting the process to fail on warnings (e.g. CI build).
If the number of warnings exceeds this value, the:
- CLI process exits with code
2 - Node.js API adds a
maxWarningsExceededproperty to the returned data
disableDefaultIgnores
Section titled “disableDefaultIgnores”CLI flag: --disable-default-ignores
Disable the default ignores. Stylelint will not automatically ignore the contents of node_modules.
globbyOptions
Section titled “globbyOptions”CLI flag: --globby-options
Options for matching the files globs, a subset of globby’s options. More info.
ignorePath
Section titled “ignorePath”CLI flag: --ignore-path, -i
Path to a file containing patterns that describe files to ignore. The path can be absolute or relative to process.cwd(). You can repeat the option to provide multiple paths. By default, Stylelint looks for .stylelintignore in process.cwd().
ignoreDisables
Section titled “ignoreDisables”CLI flag: --ignore-disables
Ignore stylelint-disable (e.g. /* stylelint-disable block-no-empty */) comments.
You can use this option to see what your linting results would be like without those exceptions.
reportDescriptionlessDisables
Section titled “reportDescriptionlessDisables”CLI flag: --report-descriptionless-disables
Report configuration comments without a description.
The following patterns are reported:
/* stylelint-disable */a {}/* stylelint-disable-next-line block-no-empty */a {}But, the following patterns (stylelint-disable -- <description>) are not reported:
/* stylelint-disable -- This problem is ignorable. */a {}/* stylelint-disable-next-line block-no-empty -- This problem is ignorable. */a {}reportInvalidScopeDisables
Section titled “reportInvalidScopeDisables”CLI flag: --report-invalid-scope-disables
Report configuration comments that don’t match rules that are specified in the configuration object.
For example, with this configuration:
{ "rules": { "block-no-empty": true }}The following pattern is reported:
/* stylelint-disable comment-no-empty */The following pattern is not reported:
/* stylelint-disable block-no-empty */reportNeedlessDisables
Section titled “reportNeedlessDisables”CLI flag: --report-needless-disables
Report configuration comments that don’t actually match any lints that need to be disabled.
For example, with this configuration:
{ "rules": { "block-no-empty": true }}The following pattern is reported:
/* stylelint-disable block-no-empty */a { color: red; }The following pattern is not reported:
/* stylelint-disable block-no-empty */a {}reportUnscopedDisables
Section titled “reportUnscopedDisables”CLI flag: --report-unscoped-disables
Report configuration comments that aren’t scoped to one or more rules.
The following pattern is reported:
/* stylelint-disable */The following pattern is not reported:
/* stylelint-disable block-no-empty */validate
Section titled “validate”CLI flags: --validate, --no-validate
Force enable/disable the validation of the rules’ options. Default: true.
For example, your CI might be faster by skipping the validation if rules didn’t change.
e.g.
export default { // … validate: process.env["CI"] !== "true"};codeFilename
Section titled “codeFilename”CLI flag: --stdin-filename
A filename to assign the input.
If using code or stdin to pass a source string directly, you can use codeFilename to associate that code with a particular filename.
CLI flag: --quiet
Only register problems for rules with an “error”-level severity (ignore “warning”-level).
quietDeprecationWarnings
Section titled “quietDeprecationWarnings”CLI flag: --quiet-deprecation-warnings
Ignore deprecation warnings.