# stylelint-vscode

> stylelint wrapper to easily integrate with Visual Studio Code

Latest version **7.0.0-6** (published 2018-06-14) · ISC license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install stylelint-vscode
pnpm add stylelint-vscode
yarn add stylelint-vscode
bun add stylelint-vscode
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 7.0.0-6 |
| Published | 2018-06-14 |
| First published | 2015-11-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 9.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Shinnosuke Watanabe |
| Maintainers | shinnn |
| Keywords | stylelint, style, lint, linter, check, checker, css, stylesheet, validate, validation, vsc, vscode, diagnostic, diagnostics, promise, promises, then, async, asynchronous, asynchronously |

## Links

- npm: https://www.npmjs.com/package/stylelint-vscode
- Repository: https://github.com/shinnn/stylelint-vscode
- Homepage: https://github.com/shinnn/stylelint-vscode#readme
- Issues: https://github.com/shinnn/stylelint-vscode/issues
- npm.io page: https://npm.io/package/stylelint-vscode

## Dependencies (8)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [stylelint](https://npm.io/package/stylelint.md) github:stylelint/stylelint#f2fa2ddb0b1d642e41645f3623f57f62cbecb7e2
- [postcss-jsx](https://npm.io/package/postcss-jsx.md) ^0.25.0
- [array-to-error](https://npm.io/package/array-to-error.md) ^1.1.1
- [array-to-sentence](https://npm.io/package/array-to-sentence.md) ^2.0.0
- [inspect-with-kind](https://npm.io/package/inspect-with-kind.md) ^1.0.4
- [vscode-languageserver](https://npm.io/package/vscode-languageserver.md) ^4.2.1
- [stylelint-warning-to-vscode-diagnostic](https://npm.io/package/stylelint-warning-to-vscode-diagnostic.md) ^1.0.1

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 7.0.0-6 (latest) — 2018-06-14
- 7.0.0-21 (next) — 2019-04-19
- 7.0.0-20 — 2019-01-26
- 7.0.0-19 — 2018-10-29
- 7.0.0-18 — 2018-10-13
- 7.0.0-17 — 2018-09-07
- 7.0.0-16 — 2018-08-22
- 7.0.0-15 — 2018-08-21
- 7.0.0-14 — 2018-08-20
- 7.0.0-13 — 2018-08-16
- 7.0.0-12 — 2018-08-16
- 7.0.0-11 — 2018-07-26
- 7.0.0-10 — 2018-06-19
- 7.0.0-9 — 2018-06-19
- 7.0.0-8 — 2018-06-18
- … 25 more at https://npm.io/package/stylelint-vscode/versions

## README

# stylelint-vscode

[![npm version](https://img.shields.io/npm/v/stylelint-vscode.svg)](https://www.npmjs.com/package/stylelint-vscode)
[![Build Status](https://travis-ci.org/shinnn/stylelint-vscode.svg?branch=master)](https://travis-ci.org/shinnn/stylelint-vscode)
[![Build status](https://ci.appveyor.com/api/projects/status/ncmsp5lp5gke8mci/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/stylelint-vscode/branch/master)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/stylelint-vscode.svg)](https://coveralls.io/github/shinnn/stylelint-vscode)

[stylelint](https://github.com/stylelint/stylelint) wrapper to easily integrate with [Visual Studio Code](https://code.visualstudio.com/) [language server](https://github.com/Microsoft/vscode-languageserver-node)

```javascript
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](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm).

```
npm install stylelint-vscode
```

## API

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

### stylelintVSCode(*textDocument* [, *options*])

*textDocument*: [`TextDocument`](https://code.visualstudio.com/docs/extensionAPI/vscode-api#TextDocument)  
*options*: `Object` (directly passed to [`stylelint.lint`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/node-api.md#the-stylelint-node-api))  
Return: `Promise<Array<Object>>`

It works like [`stylelint.lint`](https://github.com/stylelint/stylelint/blob/9.2.1/lib/index.js#L30), except for:

* [`code`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/node-api.md#code) and [`codeFilename`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/node-api.md#codefilename) option values are derived from a `TextDocument` passed to the first argument.
* It will be resolved with an `Array` of [VS Code `Diagnostic`](https://github.com/Microsoft/vscode-languageserver-node/blob/release/4.0.0/types/src/main.ts#L181-L208) 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](https://github.com/shinnn/array-to-error).
* It suppresses `No configuration found` error.
  * Doing nothing when there is no configuration is a common behavior of editor plugins.
* [`files`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/node-api.md#files) option is not supported.

```javascript
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'
  }] */
});
```

```javascript
(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

* [vscode-stylelint](https://github.com/shinnn/vscode-stylelint) — A VS Code extension powered by this module

## License

[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe

---
_Source: https://npm.io/package/stylelint-vscode · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
