Command Line Interface (CLI)
You can use Stylelint on the command line. For example:
stylelint "**/*.css"You should include quotation marks around file globs.
If you are using npm scripts, you’ll need to escape the quotes:
{ "scripts": { "lint": "stylelint \"**/*.css\"" }}Use stylelint --help to print the CLI documentation.
Options
Section titled “Options”The CLI accepts:
--allow-empty-input
Section titled “--allow-empty-input”The process exits without throwing an error when glob pattern matches no files. More info.
--cache-location
Section titled “--cache-location”Path to a file or directory for the cache location. More info.
--cache-strategy
Section titled “--cache-strategy”Strategy for the cache to use for detecting changed files. Can be either “metadata” or “content”. More info.
--cache
Section titled “--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(). More info.
--color, --no-color
Section titled “--color, --no-color”Force enabling/disabling of color. More info.
--config-basedir
Section titled “--config-basedir”Absolute path to the directory that relative paths defining extends, plugins, and customSyntax are relative to. More info.
--config
Section titled “--config”Path to a JSON, YAML, or JS file that contains your configuration object. More info.
--custom-syntax
Section titled “--custom-syntax”Specify a custom syntax to use on your code. More info.
--disable-default-ignores
Section titled “--disable-default-ignores”Disable the default ignores. Stylelint will not automatically ignore the contents of node_modules. More info.
Automatically fix, where possible, problems reported by rules. More info.
--compute-edit-info
Section titled “--compute-edit-info”Compute edit information for fixable problems. More info.
--formatter | --custom-formatter
Section titled “--formatter | --custom-formatter”Specify the formatter to format your results. More info.
--globby-options
Section titled “--globby-options”Options in JSON format for matching the input globs, e.g. '{"dot":true}'. More info.
--ignore-disables
Section titled “--ignore-disables”Ignore stylelint-disable (e.g. /* stylelint-disable block-no-empty */) comments. More info.
--ignore-path
Section titled “--ignore-path”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(). More info.
--ignore-pattern
Section titled “--ignore-pattern”Pattern of files to ignore (in addition to those in .stylelintignore).
--max-warnings
Section titled “--max-warnings”Set a limit to the number of warnings accepted. More info.
--output-file
Section titled “--output-file”Path of file to write a report. Stylelint outputs the report to the specified filename in addition to process.stderr.
--print-config
Section titled “--print-config”Print the configuration for the given input path. Globs are unsupported.
--quiet
Section titled “--quiet”Only register problems for rules with an “error”-level severity (ignore “warning”-level). More info.
--quiet-deprecation-warnings
Section titled “--quiet-deprecation-warnings”Ignore deprecation warnings. More info.
--report-descriptionless-disables
Section titled “--report-descriptionless-disables”Produce a report of the stylelint-disable comments without a description. More info.
--report-invalid-scope-disables
Section titled “--report-invalid-scope-disables”Produce a report of the stylelint-disable comments that used for rules that don’t exist within the configuration object. More info.
--report-needless-disables
Section titled “--report-needless-disables”Produce a report to clean up your codebase, keeping only the stylelint-disable comments that serve a purpose. More info.
--report-unscoped-disables
Section titled “--report-unscoped-disables”Produce a report of the configuration comments that are not scoped to one or more rules. More info.
--stdin-filename
Section titled “--stdin-filename”A filename to assign the input. More info.
--stdin
Section titled “--stdin”Accept stdin input even if it is empty.
--suppress
Section titled “--suppress”Suppress problems that have the severity of error and record them in a file. More info.
--suppress-location
Section titled “--suppress-location”Path to a file or directory for the suppressions location. More info.
--validate, --no-validate
Section titled “--validate, --no-validate”Force enable/disable the validation of the rules’ options. More info.
--version
Section titled “--version”Show the currently installed version of Stylelint.
Profile Rule Performance
Section titled “Profile Rule Performance”The TIMING environment variable allows you to profile the performance of individual rules.
When TIMING is set to all or a positive integer (n >= 1), it displays the execution time of the longest-running rules upon linting completion. This includes both rule creation and execution time, as well as each rule’s relative impact as a percentage of the total rule processing time.
$ TIMING=10 stylelint "**/*.css"| # | Rule | Time (ms) | Relative ||---:|:---------------------------------------------------|----------:|---------:|| 1 | no-descending-specificity | 1.154 | 19.3% || 2 | no-duplicate-selectors | 0.357 | 6.0% || 3 | length-zero-no-unit | 0.300 | 5.0% || 4 | selector-type-no-unknown | 0.265 | 4.4% || 5 | alpha-value-notation | 0.251 | 4.2% || 6 | declaration-block-no-redundant-longhand-properties | 0.217 | 3.6% || 7 | selector-class-pattern | 0.187 | 3.1% || 8 | value-keyword-case | 0.151 | 2.5% || 9 | declaration-block-no-duplicate-custom-properties | 0.146 | 2.4% || 10 | declaration-empty-line-before | 0.140 | 2.3% |You can adjust the number of results by setting a different value for TIMING.
For example:
TIMING=30will show the top 30 rules.TIMING=allwill display all rules.
Usage examples
Section titled “Usage examples”The CLI expects input as either a file glob or process.stdin. It outputs formatted results into process.stderr.
You should include quotation marks around file globs.
Example A - recursive
Section titled “Example A - recursive”Recursively linting all .css files in the foo directory:
stylelint "foo/**/*.css"Example B - multiple file extensions
Section titled “Example B - multiple file extensions”Linting all .css, .scss, and .sass files:
stylelint "**/*.{css,scss,sass}"Example C - stdin
Section titled “Example C - stdin”Linting stdin:
echo "a { color: pink; }" | stylelintExample D - negation
Section titled “Example D - negation”Linting all .css files except those within docker subfolders, using negation in the input glob:
stylelint "**/*.css" "!**/docker/**"Example E - caching
Section titled “Example E - caching”Caching processed .scss files foo directory:
stylelint "foo/**/*.scss" --cache --cache-location "/Users/user/.stylelintcache/"Example F - writing a report
Section titled “Example F - writing a report”Linting all .css files in the foo directory, then writing the output to myTestReport.txt:
stylelint "foo/*.css" --output-file myTestReport.txtExample G - specifying a config
Section titled “Example G - specifying a config”Using bar/mySpecialConfig.json as config to lint all .css files in the foo directory and any of its subdirectories:
stylelint "foo/**/*.css" --config bar/mySpecialConfig.jsonExample H - using a custom syntax
Section titled “Example H - using a custom syntax”Recursively linting all .css files in the foo directory using a custom syntax:
stylelint "foo/**/*.css" --custom-syntax path/to/my-custom-syntax.jsExample I - print on success
Section titled “Example I - print on success”Ensure output on successful runs:
stylelint -f verbose "foo/**/*.css"Example J - print a config
Section titled “Example J - print a config”Print a configuration used for the given input file:
stylelint test.css --print-configExample K - piping a report to another command
Section titled “Example K - piping a report to another command”Use a report as input for another command through piping:
stylelint -f json "*.css" 2>&1 | jq '[.[] | .warnings | length] | add'Exit codes
Section titled “Exit codes”The CLI can exit the process with the following exit codes:
1- fatal error2- lint problem64- invalid CLI usage78- invalid configuration file