@carlosjeurissen/stylelint-csstree-validator

中文文档
3.3.1发布于 2026/03/10MITESM + CJS近 30 天下载 1.8万

Stylelint plugin to validate CSS syntax

原始使用文档
文档目录5 节
  1. Install
  2. Usage
  3. Options
  4. RegExp patterns
  5. License

NPM version Build Status Coverage Status

⚠️ DEPRECATED: @carlosjeurissen/stylelint-csstree-validator

Note > This fork has been deprecated in favor of the original-package. Please update your dependencies back to the original package to receive future updates and bug fixes.

A stylelint plugin based on csstree to examinate CSS syntax. It examinates at-rules and declaration values to match W3C specs and browsers extensions. It might be extended in future to validate other parts of CSS.

⚠️ Warning ⚠️: The plugin is designed to validate CSS syntax only. However stylelint may be configured to use for other syntaxes like Less or Sass. In this case, the plugin avoids examination of expressions containing non-standard syntax, but you need specify which preprocessor is used with the syntaxExtensions option.

Install

$ npm install --save-dev stylelint-csstree-validator

Usage

Setup plugin in stylelint config:

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": true
  }
}

Options

syntaxExtensions

Type: Array<'sass' | 'less'> or false
Default: false

Since the plugin focuses on CSS syntax validation it warns on a syntax which is introducing by preprocessors like Less or Sass. The syntaxExtensions option allows to specify that some preprocessor's syntaxes are used for styles so the plugin may avoid warnings when met such a syntax.

By default the plugin exams styles as pure CSS. To specify that a preprocessor's syntax is used, you must specify an array with the names of these extensions. Currently supported:

  • sass – declaration values with Sass syntax will be ignored as well as custom at-rules introduced by Saas (e.g. @if, @else, @mixin etc). For now Sass at-rules are allowed with any prelude, but it might be replaced for real syntax definitions in future releases
  • less – declaration values with Sass syntax will be ignored as well as @plugin at-rule introduced by Less

Using both syntax extensions is also possible:

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "syntaxExtensions": ["sass", "less"]
    }
  }
}

atrules

Type: Object, false or null
Default: null

Using false value for the option disables at-rule validation.

Otherwise the option is using for extending or altering at-rules syntax dictionary. An atrule definition consists of prelude and descriptors, both are optional. A prelude is a single expression that comes after at-rule name. A descriptors is a dictionary like properties option but for a specific at-rule. CSS Value Definition Syntax is used to define value's syntax. If a definition starts with | it is adding to existing definition value if any. See CSS syntax reference for default definitions.

The following example defines new atrule @example with a prelude and two descriptors (a descriptor is the same as a declaration but with no !important allowed):

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "atrules": {
        "example": {
          "prelude": "<custom-ident>",
          "descriptors": {
            "foo": "<number>",
            "bar": "<color>"
          }
        }
      }
    }
  }
}

properties

Type: Object or null
Default: null

An option for extending or altering properties syntax dictionary. CSS Value Definition Syntax is used to define value's syntax. If a definition starts with | it is adding to existing definition value if any. See CSS syntax reference for default definitions.

The following example extends width and defines size properties:

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "properties": {
        "width": "| new-keyword | custom-function(<length>, <percentage>)",
        "size": "<length-percentage>"
      }
    }
  }
}

Using <any-value> for a property definition is an alternative for ignoreProperties option.

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "properties": {
        "my-custom-property": "<any-value>"
      }
    }
  }
}

types

Type: Object or null
Default: null

An option for extending or altering types syntax dictionary. Types are something like a preset which allow reuse a definition across other definitions. CSS Value Definition Syntax is used to define value's syntax. If a definition starts with | it is adding to existing definition value if any. See CSS syntax reference for default definitions.

The following example defines a new functional type my-fn() and extends color type:

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "properties": {
        "some-property": "<my-fn()>"
      },
      "types": {
        "color": "| darken(<color>, [ <percentage> | <number [0, 1]> ])",
        "my-fn()": "my-fn( <length-percentage> )"
      }
    }
  }
}

ignore

Works the same as ignoreProperties but deprecated, use ignoreProperties instead.

ignoreAtrules

Type: Array<string|RegExp> or false
Default: false

Defines a list of at-rules names that should be ignored by the plugin. Ignorance for an at-rule means no validation for its name, prelude or descriptors. The names provided are used for full case-insensitive matching, i.e. a vendor prefix is mandatory and prefixed names should be provided as well if you need to ignore them. You can use RegExp patterns in the list as well.

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "ignoreAtrules": ["custom-at-rule", "-webkit-keyframes"]
    }
  }
}

ignoreProperties

Type: Array<string|RegExp> or false
Default: false

Defines a list of property names that should be ignored by the plugin. The names provided are used for full case-insensitive matching, i.e. a vendor prefix is mandatory and prefixed names should be provided as well if you need to ignore them.

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "ignoreProperties": ["composes", "mask", "-webkit-mask"]
    }
  }
}

In this example, plugin will not test declarations with a property name composes, mask or -webkit-mask, i.e. no warnings for these declarations would be raised. You can use RegExp patterns in the list as well.

ignoreValue

Type: RegExp or false
Default: false

Defines a pattern for values that should be ignored by the validator.

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "ignoreValue": "^pattern$"
    }
  }
}

For this example, the plugin will not report warnings for values which is matched the given pattern. However, warnings will still be reported for unknown properties.

RegExp patterns

In some cases a more general match patterns are needed instead of exact name matching. In such cases a RegExp pattern can be used.

Since CSS names are an indentifiers which can't contain a special characters used for RegExp's, a distinguishing between a CSS name and RegExp is a trivial problem. When the plugin encounters a string in a ignore pattern list containing any character other than a-z, A-Z, 0-9 or -, it produces a RegExp using the construction new RegExp('^(' + pattern + ')$', 'i'). In other words, the pattern should be fully matched case-insensitive.

To have a full control over a RegExp pattern, a regular RegExp instance or its stringified version (i.e. "/pattern/flags?") can be used.

  • "foo|bar" transforms into /^(foo|bar)$/i
  • "/foo|bar/i" transforms into /foo|bar/i (note: it's not the same as previous RegExp, since not requires a full match with a name)
  • /foo|bar/ used as is (note: with no i flag a matching will be case-sensitive which makes no sense in CSS)

License

MIT

版本与发布记录

@carlosjeurissen/stylelint-csstree-validator 共发布 5 个版本,首次发布于 2024/02/09;过去 12 个月发布了 2 个版本。

版本发布日期距今
3.3.1latest2026/03/108 个月前
3.3.02026/01/169 个月前
3.2.12025/03/061.7 年前
3.2.02025/03/061.7 年前
3.1.02024/02/092 年前

关于 @carlosjeurissen/stylelint-csstree-validator 的常见问题

@carlosjeurissen/stylelint-csstree-validator 是什么?

Stylelint plugin to validate CSS syntax

如何安装 @carlosjeurissen/stylelint-csstree-validator?

在项目目录运行 npm install @carlosjeurissen/stylelint-csstree-validator,或使用 pnpm add / yarn add / bun add。

@carlosjeurissen/stylelint-csstree-validator 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/carlosjeurissen__stylelint-csstree-validator 是否存在。

@carlosjeurissen/stylelint-csstree-validator 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@carlosjeurissen/stylelint-csstree-validator 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^14.13.0 || >=15.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@carlosjeurissen/stylelint-csstree-validator 可以商用吗?

@carlosjeurissen/stylelint-csstree-validator 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@carlosjeurissen/stylelint-csstree-validator 的下载量有多少?

根据 npm 官方下载统计,@carlosjeurissen/stylelint-csstree-validator 在 2026/10/09 – 2026/11/07 这 30 天内被下载 17,682 次,日均约 589 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@carlosjeurissen/stylelint-csstree-validator 还在维护吗?

最新版本 3.3.1 发布于 2026/03/10(8 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 2 个;首次发布于 2024/02/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。