Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

stylelint-value-no-unknown-custom-properties

csstools666.2kCC0-1.06.0.1

A stylelint rule to disallow usage of unknown custom properties

stylelint, stylelint-plugin, css, custom, properties, property, variables, variable, vars, var, csswg, w3c, unknown

readme

Stylelint Value No Unknown Custom Properties stylelint

NPM Version test Discord

Stylelint Value No Unknown Custom Properties is a stylelint rule to disallow usage of unknown custom properties.

Usage

Add stylelint and Stylelint Value No Unknown Custom Properties to your project.

npm install stylelint stylelint-value-no-unknown-custom-properties --save-dev

Add Stylelint Value No Unknown Custom Properties to your stylelint configuration.

{
  "plugins": [
    "stylelint-value-no-unknown-custom-properties"
  ],
  "rules": {
    "csstools/value-no-unknown-custom-properties": true || null
  }
}

Options

true

If the first option is true, then Stylelint Value No Unknown Custom Properties requires all custom properties to be known, and the following patterns are not considered violations:

:root {
  --brand-blue: #33f;
}

.example {
  color: var(--brand-blue);
}
.example {
  color: var(--brand-blue);
}

.some-other-class {
  --brand-blue: #33f;
}
:root {
  --brand-blue: #33f;
  --brand-color: var(--brand-blue);
}

While the following patterns are considered violations:

.example {
  color: var(--brand-blue);
}
:root {
  --brand-color: var(--brand-blue);
}

Custom Properties can be imported using the second option.

null

If the first option is null, then Stylelint Value No Unknown Custom Properties does nothing.


importFrom

When the first option is true, then the second option can specify sources where Custom Properties should be imported from by using an importFrom key. These imports might be CSS, JS, and JSON files, functions, and directly passed objects.

// .stylelintrc
{
  "plugins": [
    "stylelint-value-no-unknown-custom-properties"
  ],
  "rules": {
    "csstools/value-no-unknown-custom-properties": [true, {
      "importFrom": [
        "path/to/file.css", // => :root { --brand-blue: #33f; }
        "path/to/file.json" // => { "custom-properties": { "--brand-blue": "#33f" } }
      ]
    }]
  }
}

resolver

Use this option to configure how the rule solve paths of @import rules.

// .stylelintrc
{
  "plugins": [
    "stylelint-value-no-unknown-custom-properties"
  ],
  "rules": {
    "csstools/value-no-unknown-custom-properties": [true, {
      "resolver": {
        "extensions": [".css"], // => default to [".css"]
        "paths": ["./assets/css", "./static/css"] // => paths to look for files, default to []
        "moduleDirectories": ["node_modules"] // => modules folder to look for files, default to ["node_modules"]
      }
    }]
  }
}

changelog

Changes to Stylelint Value No Unknown Custom Properties

Unreleased

  • Fix @import prelude parsing

6.0.0 (Dec 28, 2023)

  • Updated: peer stylelint to >=16 (breaking)
  • Removed false option, use null instead

5.0.0 (November 6, 2023)

  • Ensure this can work with Stylelint 15 too. (thanks @alex-e-leon!)
  • Updated dependencies to latest versions.
  • Breaking: Dropping support for old Node versions.

4.0.0 (March 26, 2022)

  • Updated to use postcss-value-parser.
  • Updating to use common plugin layout. (thanks @jameschensmith!)
  • Updating: peer stylelint to 14 (major). (thanks @oscarvz and @ronilaukkarinen!)
  • Updated: Engines to match PostCSS support
  • Added resolver to resolve absolute path in @import (thanks @heroandtn3!)

3.0.0 (May 12, 2020)

  • Updated: postcss-values-parser to 3.0.4 (major)
  • Updated: peer stylelint to 10 - 13 (major)
  • Updated: Node 10+ compatibility (major)

2.0.0 (September 26, 2018)

  • Fixed: Options are now configured

1.0.0 (September 25, 2018)

  • Initial version