Skip to content

Latest commit

 

History

History
195 lines (112 loc) · 6.79 KB

options.md

File metadata and controls

195 lines (112 loc) · 6.79 KB

Options

Options shared by the:

configFile

CLI flag: --config

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

CLI flag: --config-basedir

Absolute path to the directory that relative paths defining "extends" and "plugins" are relative to. Only necessary if these values are relative paths.

fix

CLI flag: --fix

Automatically fix, where possible, violations reported by rules.

For CSS with standard syntax, stylelint uses postcss-safe-parser to fix syntax errors.

If a source contains a:

  • scoped disable comment, e.g. /* stylelint-disable indentation */, any violations reported by the scoped rules will not be automatically fixed anywhere in the source
  • unscoped disable comment, i.e. /* stylelint-disable */, the entirety of source will not be automatically fixed

This limitation in being tracked in issue #2643.

formatter

CLI flags: --formatter, -f | --custom-formatter

Specify the formatter to format your results.

Options are:

  • compact - generates output similar to ESLint's compact formatter
  • json (default for Node API) - generates JSON that can be consumed by another tool
  • string (default for CLI) - generates human-readable strings
  • tap - generates Test Anything Protocol output
  • unix - generates messages like a C compiler, so that tools like Emacs' Compilation mode can hyperlink them
  • verbose - extends string to include a list of checked files and a tally for each rule

The formatter Node.js API option can also accept a function, whereas the --custom-formatter CLI flag accepts a path to a JS file exporting one. The function in both cases must fit the signature described in the Developer Guide.

cache

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().

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 that second command invalidated .stylelintcache.

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.

maxWarnings

CLI flags: --max-warnings, --mw

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 maxWarningsExceeded property to the returned data

customSyntax

CLI flag: --custom-syntax

Specify a custom syntax to use on your code.

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).

Using the Node.js API, the customSyntax option can also accept a Syntax object. Stylelint treats the parse property as a required value.

Note that stylelint can provide no guarantee that core rules work with syntaxes.

disableDefaultIgnores

CLI flags: --disable-default-ignores, --di

Disable the default ignores. stylelint will not automatically ignore the contents of node_modules.

ignorePath

CLI flags: --ignore-path, -i

A path to a file containing patterns describing files to ignore. The path can be absolute or relative to process.cwd(). By default, stylelint looks for .stylelintignore in process.cwd().

ignoreDisables

CLI flags: --ignore-disables, --id

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.

reportNeedlessDisables

CLI flags: --report-needless-disables, --rd

Produce a report to clean up your codebase, keeping only the stylelint-disable comments that serve a purpose.

If needless disables are found, the:

  • CLI process exits with code 2
  • Node.js API adds errors to the returned data

reportInvalidScopeDisables

CLI flags: --report-invalid-scope-disables, --risd

Produce a report of the stylelint-disable comments that used for rules that don't exist within the configuration object.

If invalid scope disables are found, the:

  • CLI process exits with code 2
  • Node.js API adds errors to the returned data

reportDescriptionlessDisables

CLI flags: --report-descriptionless-disables, --rdd

Produce a report of the stylelint-disable comments without a description.

For example, when the configuration { block-no-empty: true } is given, 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 violation is ignorable. */
a {}
/* stylelint-disable-next-line block-no-empty -- This violation is ignorable. */
a {}

If descriptionless disables are found, the:

  • CLI process exits with code 2
  • Node.js API adds errors to the returned data

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.

quiet

CLI flag: --quiet

Only register violations for rules with an "error"-level severity (ignore "warning"-level).