7.0.0-6 • Published 5 years ago

stylelint-vscode v7.0.0-6

Weekly downloads
6
License
ISC
Repository
github
Last release
5 years ago

stylelint-vscode

npm version Build Status Coverage Status

stylelint wrapper to easily integrate with Visual Studio Code language server

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

const code = `
p {
  line-height: .8;
  color: red;
}`;

(async () => {
  await stylelintVSCode({
    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(options)

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

It works like stylelint.lint, except for:

  • It will be resolved with an Array of VS Code's 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.
  • code option is required and files option is not supported.
    • Because extensions can derive file contents via TextDocument#getText() and there is no need to read physical files again.
const stylelintVSCode = require('stylelint-vscode');

(async () => {
  await stylelintVSCode({
    code: '{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({
      code: '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"'
      ]
    */
  }
})();

License

ISC License © 2018 Shinnosuke Watanabe

7.0.0-21

5 years ago

7.0.0-20

5 years ago

7.0.0-19

6 years ago

7.0.0-18

6 years ago

7.0.0-17

6 years ago

7.0.0-16

6 years ago

7.0.0-15

6 years ago

7.0.0-14

6 years ago

7.0.0-13

6 years ago

7.0.0-12

6 years ago

7.0.0-11

6 years ago

7.0.0-10

6 years ago

7.0.0-9

6 years ago

7.0.0-8

6 years ago

7.0.0-7

6 years ago

7.0.0-6

6 years ago

7.0.0-5

6 years ago

7.0.0-4

6 years ago

7.0.0-3

6 years ago

7.0.0-2

6 years ago

7.0.0-1

6 years ago

7.0.0-0

6 years ago

6.1.1

6 years ago

6.1.0

6 years ago

6.0.0

7 years ago

5.2.3

7 years ago

5.2.2

7 years ago

5.2.1

7 years ago

5.2.0

7 years ago

5.1.0

8 years ago

5.0.1

8 years ago

5.0.0

8 years ago

4.1.1

8 years ago

4.1.0

8 years ago

4.0.0

8 years ago

3.1.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.0.0

8 years ago

1.0.0

8 years ago