Socket
Socket
Sign inDemoInstall

stylelint-csstree-validator

Package Overview
Dependencies
228
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    stylelint-csstree-validator

Stylelint plugin to validate CSS syntax


Version published
Weekly downloads
54K
increased by16.37%
Maintainers
1
Install size
2.27 MB
Created
Weekly downloads
 

Changelog

Source

1.9.0 (October 27, 2020)

  • Bumped CSSTree to ^1.0.0 (mdn-data is bumped to 2.0.12)
  • Added properties and types options to extend syntax dictionary
  • Added ignoreValue option (#14)

Readme

Source

NPM version Build Status

stylelint-csstree-validator

CSS syntax validator based on csstree as plugin for stylelint. Currently it's only checking declaration values to match W3C specs and browsers extensions. It would be extended in future to validate other parts of CSS.

Validator is designed to check CSS syntax only. However PostCSS (that used by stylelint as backend) may parse other syntaxes like Less or Sass and can be used for these syntaxes too. In this case validator is limited to check declaration that doesn't contain any CSS extension (e.g. variables).

Install

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

Usage

Setup plugin in your stylelint config:

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

Options

properties

Type: Object or null
Default: null

Overrides or/and extends property definition dictionary. CSS Value Definition Syntax is used to define value's syntax. If definition starts with | it added to existing definition if any. See CSS syntax reference for default definitions.

In the following example we extend width property and defines size:

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

Using property definitions with the syntax <any-value> is an alternative for ignore option.

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

Type: Object or null
Default: null

Overrides or/and extends type definition dictionary. CSS Value Definition Syntax is used to define value's syntax. If definition starts with | it added to existing definition if any. See CSS syntax reference for default definitions.

In the following example we define new functional type my-fn() and extend 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

Type: Array or false
Default: false

Defines a list of property names that should be ignored by the validator.

{
  "plugins": [
    "stylelint-csstree-validator"
  ],
  "rules": {
    "csstree/validator": {
      "ignore": ["composes", "foo", "bar"]
    }
  }
}

In this example, plugin would not test declaration with property name composes, foo or bar. As a result, no warnings for these declarations.

ignoreValue

Type: RegExp
Default: false

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

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

In this example, the plugin will not report warnings for values that match the given pattern. Warnings will still be reported for properties.

License

MIT

Keywords

FAQs

Last updated on 27 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc