Skip to content

stylelint

GitHub stars autofix GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

stylelint documentation

stylelint - GitHub

Configuration in MegaLinter

Variable Description Default value
CSS_STYLELINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
CSS_STYLELINT_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
CSS_STYLELINT_FILTER_REGEX_INCLUDE Custom regex including filter
Ex: (src\|lib)
Include every file
CSS_STYLELINT_FILTER_REGEX_EXCLUDE Custom regex excluding filter
Ex: (test\|examples)
Exclude no file
CSS_STYLELINT_CLI_LINT_MODE Override default CLI lint mode
- file: Calls the linter for each file
- list_of_files: Call the linter with the list of files as argument
- project: Call the linter from the root of the project
list_of_files
CSS_STYLELINT_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".css", ".scss", ".saas"]
CSS_STYLELINT_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
Include every file
CSS_STYLELINT_PRE_COMMANDS List of bash commands to run before the linter None
CSS_STYLELINT_POST_COMMANDS List of bash commands to run after the linter None
CSS_STYLELINT_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling CSS_STYLELINT and its pre/post commands None
CSS_STYLELINT_CONFIG_FILE stylelint configuration file nameUse LINTER_DEFAULT to let the linter find it .stylelintrc.json
CSS_STYLELINT_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
CSS_STYLELINT_DISABLE_ERRORS Run linter but consider errors as warnings false
CSS_STYLELINT_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
CSS_STYLELINT_CLI_EXECUTABLE Override CLI executable ['stylelint']

IDE Integration

Use stylelint in your favorite IDE to catch errors before MegaLinter !

IDE Extension Name Install
Atom linter-stylelint Visit Web Site
Emacs flycheck Visit Web Site
Sublime Text SublimeLinter-stylelint Visit Web Site
Sublime Text SublimeLinter-contrib-stylelint_d Visit Web Site
vim ale Visit Web Site
Visual Studio Code vscode-stylelint Install in VSCode

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 125 Docker Image Size (tag) Docker Pulls
c_cpp Optimized for pure C/C++ projects 56 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 84 Docker Image Size (tag) Docker Pulls
documentation MegaLinter for documentation projects 51 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 63 Docker Image Size (tag) Docker Pulls
dotnetweb Optimized for C, C++, C# or VB based projects with JS/TS 72 Docker Image Size (tag) Docker Pulls
go Optimized for GO based projects 53 Docker Image Size (tag) Docker Pulls
java Optimized for JAVA based projects 54 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 61 Docker Image Size (tag) Docker Pulls
php Optimized for PHP based projects 56 Docker Image Size (tag) Docker Pulls
python Optimized for PYTHON based projects 64 Docker Image Size (tag) Docker Pulls
ruby Optimized for RUBY based projects 52 Docker Image Size (tag) Docker Pulls
rust Optimized for RUST based projects 52 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 56 Docker Image Size (tag) Docker Pulls
swift Optimized for SWIFT based projects 52 Docker Image Size (tag) Docker Pulls
terraform Optimized for TERRAFORM based projects 56 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • File extensions: .css, .scss, .saas

How the linting is performed

  • stylelint is called once with the list of files as arguments (list_of_files CLI lint mode)

Example calls

stylelint myfile.css
stylelint --config .stylelintrc.json myfile.css myfile2.css myfile3.css
stylelint --fix --config .stylelintrc.json myfile.css myfile2.css myfile3.css

Help content


  A mighty CSS linter that helps you avoid errors and enforce conventions.

  Usage: stylelint [input] [options]

  Input: Files(s), glob(s), or nothing to use stdin.

    If an input argument is wrapped in quotation marks, it will be passed to
    globby for cross-platform glob support. "node_modules" are always ignored.
    You can also pass no input and use stdin, instead.

  Options:

    --config, -c <path_or_module>

      A path to a specific configuration file (JSON, YAML, CommonJS, or ES module),
      or a module name in "node_modules" that points to one. If no argument is
      provided, Stylelint will search for configuration files in the following
      places, in this order:

        - a "stylelint" property in "package.json"
        - a ".stylelintrc" file
        - a ".stylelintrc.{cjs,mjs,js,json,yaml,yml}" file
        - a "stylelint.config.{cjs,mjs,js}" file

      The search will begin in the working directory and move up the directory
      tree until a configuration file is found.

    --config-basedir <path>

      An absolute path to the directory that relative paths defining "extends",
      "plugins", and "customSyntax" are *relative to*. Only necessary if these
      values are relative paths.

    --print-config

      Print the configuration for the given input file path. Globs are unsupported.

    --ignore-path, -i <path>

      A 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()". Multiple can be set.

    --ignore-pattern, --ip <pattern>

      A pattern of files to ignore (in addition to those in ".stylelintignore").
      Multiple can be set.

    --fix

      Automatically fix problems of certain rules.

    --custom-syntax <name_or_path>

      A module name or path to a JS file exporting a PostCSS-compatible syntax.

    --stdin

      Accept stdin input even if it is empty.

    --stdin-filename <name>

      A filename to assign stdin input.

    --ignore-disables, --id

      Ignore "stylelint-disable" comments.

    --disable-default-ignores, --di

      Allow linting of "node_modules".

    --[no-]cache

      Store the info about processed files in order to only operate on the
      changed ones the next time you run Stylelint. By default, the cache is
      stored in "./.stylelintcache". To adjust this, use "--cache-location".
      Cache is disabled by default.

    --cache-location <path>

      A path to a file or directory to be used for the cache location. If a
      directory is specified, a cache file will be created inside the specified
      folder, with a name derived from a hash of the current working directory.

      If the directory for the cache does not exist, make sure you add a trailing "/"
      on *nix systems or "\" on Windows. Otherwise the path will be assumed to
      be a file.

    --cache-strategy <strategy>

      A strategy for the cache to use for detecting changed files. Either one of:

        metadata     by metadata of a file (default)
        content      by content of a file

      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.

    --formatter, -f <formatter>

      An output formatter. The variants are as follows:

        string       human-readable strings (default)
        compact      similar to ESLint's compact formatter
        github       workflow commands for GitHub Actions
        json         JSON format
        tap          TAP format
        unix         C compiler-like format
        verbose      extend "string" to include a file list and a tally

    --custom-formatter <path_or_module>

      A path to a JS file or module name exporting a custom formatting function.

    --quiet, -q

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

    --quiet-deprecation-warnings

      Ignore deprecations warnings.

    --[no-]color

      Force enabling/disabling of color.

    --report-needless-disables, --rd

      Also report errors for "stylelint-disable" comments that are not blocking
      a lint warning. The process will exit with code 2 if needless disables are found.

    --report-invalid-scope-disables, --risd

      Report "stylelint-disable" comments that used for rules that don't exist
      within the configuration object. The process will exit with code 2 if invalid
      scope disables are found.

    --report-descriptionless-disables, --rdd

      Report "stylelint-disable" comments without a description. The process will
      exit with code 2 if descriptionless disables are found.

    --max-warnings, --mw <number>

      The number of warnings above which the process will exit with code 2.
      Useful when setting "defaultSeverity" to "warning" and expecting the process
      to fail on warnings (e.g. CI build).

    --output-file, -o <path>

      A file path to write a report.

    --allow-empty-input, --aei

      When a glob pattern matches no files, the process will exit without throwing an error.

    --globby-options, --go <json>

      Options in JSON format passed to globby.

    --version, -v

      Show the version.

    --help, -h

      Show the help.

Installation on mega-linter Docker image