New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

csstree-validator

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csstree-validator

CSS validator built on csstree

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
14K
increased by11.54%
Maintainers
1
Weekly downloads
 
Created
Source

NPM version Build Status

CSS Tree Validator

CSS validator built on CSSTree

How to use:

NPM package

> npm install csstree-validator

Manualy validate CSS string or CSSTree's AST:

const { validate } = require('./lib');

console.log(validate('.class { pading: 10px; border: 1px super red }', 'demo/example.css'));
// [
//   SyntaxError [SyntaxReferenceError]: Unknown property `pading` {
//     reference: 'pading',
//     property: 'pading',
//     offset: 9,
//     line: 1,
//     column: 10
//   },
//  SyntaxError [SyntaxMatchError]: Mismatch {
//    message: 'Invalid value for `border` property',
//    rawMessage: 'Mismatch',
//    syntax: '<line-width> || <line-style> || <color>',
//    css: '1px super red',
//    mismatchOffset: 4,
//    mismatchLength: 5,
//    offset: 35,
//    line: 1,
//    column: 36,
//    loc: { source: 'demo/example.css', start: [Object], end: [Object] },
//    property: 'border',
//    details: 'Mismatch\n' +
//      '  syntax: <line-width> || <line-style> || <color>\n' +
//      '   value: 1px super red\n' +
//      '  ------------^'
//  }
// ]

Another option is to use helpers to validate a file or directory and buildin reporters:

const { validateFile } = require('csstree-validator');
const reporter = require('csstree-validator').reporters.checkstyle;

console.log(reporter(validateFile('/path/to/style.css')));
API

Validate methods:

  • validateAtrule(node)
  • validateAtrulePrelude(atrule, prelude, preludeLoc)
  • validateAtruleDescriptor(atrule, descriptor, value, descriptorLoc)
  • validateDeclaration(property, value, valueLoc)
  • validateRule(node)
  • validate(css, filename)

Helpers:

  • validateDictionary(dictionary)
  • validateString(css, filename)
  • validateFile(filename)
  • validateFileList(list)
  • validatePath(searchPath, filter)
  • validatePathList(pathList, filter)

Reporters:

  • json
  • console
  • checkstyle
  • gnu

Library in a browser

<script src="csstree-validator/dist/csstree-validator.js"></script>
<script>
    const errors = csstreeValidator.validate('.some { css: source }');
</script>

NOTE: Helpers and reporters are not available for browser version at the moment.

CLI (terminal command)

> npm install -g csstree-validator
> csstree-validator /path/to/style.css
> csstree-validator -h
Usage:

  csstree-validate [fileOrDir] [options]

Options:

  -h, --help               Output usage information
  -r, --reporter <name>    Format of output: console (default), checkstyle, json, gnu
  -v, --version            Output version

Ready to use

Plugins that are using csstree-validator:

License

MIT

Keywords

FAQs

Package last updated on 31 Mar 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc