This package has been deprecated

Author message:

This package is deprecated, see https://github.com/stylelint/vscode-stylelint/issues/110 for upcoming new release

stylelint-vscode

7.0.0-6 • Public • Published

stylelint-vscode

npm version Build Status Build status Coverage Status

stylelint wrapper to easily integrate with Visual Studio Code language server

const stylelintVSCode = require('stylelint-vscode');
const {TextDocument} = require('vscode-languageserver-types');
 
(async () => {
  await stylelintVSCode(TextDocument.create('file:///Users/me/0.css', 'css', 1, `
p {
  line-height: .8;
  color: red;
}`), {
    code,
    config: {
      rules: {
        'number-leading-zero': 'always',
        'color-named': ['never', {severity: 'warning'}]
      }
    }
  }); /* => [{
    range: {
      start: {line: 2, character: 14},
      end: {line: 2, character: 14}
    },
    message: 'Expected a leading zero (number-leading-zero)',
    severity: 1,
    code: 'number-leading-zero',
    source: 'stylelint'
  }, {
    range: {
      start: {line: 3, character: 9},
      end: {line: 3, character: 9}
    },
    message: 'Unexpected named color "red" (color-no-named)',
    severity: 2,
    code: 'color-no-named',
    source: 'stylelint'
  }] */
})();

Installation

Use npm.

npm install stylelint-vscode

API

const stylelintVSCode = require('stylelint-vscode');

stylelintVSCode(textDocument [, options])

textDocument: TextDocument
options: Object (directly passed to stylelint.lint)
Return: Promise<Array<Object>>

It works like stylelint.lint, except for:

  • code and codeFilename option values are derived from a TextDocument passed to the first argument.
  • It will be resolved with an Array of VS Code Diagnostic instances.
  • It will be rejected (not resolved) when it takes invalid configs.
    • In this case, it joins config errors into a single error object by using array-to-error.
  • It suppresses No configuration found error.
    • Doing nothing when there is no configuration is a common behavior of editor plugins.
  • files option is not supported.
const stylelintVSCode = require('stylelint-vscode');
 
(async () => {
  await stylelintVSCode(TextDocument.create('file:///Users/me/1.css', 'css', 1, '{foo}')); /*=> [{
    range: {
      start: {line: 0, character: 1},
      end: {line: 0, character: 1}
    },
    message: 'Unknown word (CssSyntaxError)',
    severity: 1,
    code: 'CssSyntaxError',
    source: 'stylelint'
  }] */
});
(async () => {
  try {
    await stylelintVSCode(TextDocument.create('file:///Users/me/2.css', 'css', 1, 'a {}'), {
      config: {
        rules: {
          indentation: 2,
          'function-comma-space-before': 'foo'
        }
      }
    });
  } catch (err) {
    err.name;
    //=> 'SyntaxError'
 
    err.message;
    //=> 'Expected option value for rule "indentation"\nInvalid option value "foo" for rule "function-comma-space-before"'
 
    err.reasons;
    /* =>
      [
        'Expected option value for rule "indentation"',
        'Invalid option value "foo" for rule "function-comma-space-before"'
      ]
    */
  }
})();

Related project

License

ISC License © 2018 Shinnosuke Watanabe

Package Sidebar

Install

npm i stylelint-vscode

Weekly Downloads

46

Version

7.0.0-6

License

ISC

Unpacked Size

9.49 kB

Total Files

4

Last publish

Collaborators

  • ntwb