Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Nov 24, 2015
0 parents commit 7d9a9db
Show file tree
Hide file tree
Showing 13 changed files with 651 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"${workspaceRoot}/fixture.css"
],
"stopOnEntry": false
},
{
"name": "Launch Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceRoot}",
"--extensionTestsPath=${workspaceRoot}/test"
],
"stopOnEntry": false
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"javascript.validate.syntaxValidation": false
}
8 changes: 8 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.editorconfig
.gitignore
.vscode/**
*.css
*.png
*.scss
media/*.ai
test
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# vscode-stylelint

[![Dependency Status](https://david-dm.org/shinnn/vscode-stylelint.svg)](https://david-dm.org/shinnn/vscode-stylelint)
[![devDependency Status](https://david-dm.org/shinnn/vscode-stylelint/dev-status.svg)](https://david-dm.org/shinnn/vscode-stylelint#info=devDependencies)

A [Visual Studio Code](https://code.visualstudio.com/) extension to lint [CSS](https://www.w3.org/Style/CSS/)/[SCSS](http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax) with [stylelint](http://stylelint.io/)

![screenshot](screenshot.png)

## Installation

1. Run [`Install Extension`](https://code.visualstudio.com/docs/editor/extension-gallery#_install-an-extension) command from [Command Palette](https://code.visualstudio.com/Docs/editor/codebasics#_command-palette).
2. Search and choose `stylelint`.

See the [extension installation guide](https://code.visualstudio.com/docs/editor/extension-gallery) for details.

## Usage

Enable the linter in the VS Code [settings](https://code.visualstudio.com/docs/customization/userandworkspace).

```json
{
"stylelint.enable": true
}
```

### Configurations

*In addition to the VS Code settings mentioned below, you can set the config by adding [`.stylelintrc`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/configuration.md#configuration) file to the workspace directory or its ancestor ones.*

#### stylelint.enable

Type: `Boolean`
Default: `false`

Control whether [stylelint](https://github.com/stylelint/stylelint/) is enabled for CSS/SCSS files or not.

#### stylelint.config

Type: `Object`
Default: `null`

Will be directly passed to [`config`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/node-api.md#config) option.

#### stylelint.configOverrides

Type: `Object`
Default: `null`

Will be directly passed to [`configOverrides`](https://github.com/stylelint/stylelint/blob/master/docs/user-guide/node-api.md#configoverrides) option.

## License

Copyright (c) 2015 [Shinnosuke Watanabe](https://github.com/shinnn)

Licensed under [the MIT License](./LICENSE).
32 changes: 32 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const path = require('path');

const langClient = require('vscode-languageclient');
const LanguageClient = langClient.LanguageClient;
const SettingMonitor = langClient.SettingMonitor;
const vscode = require('vscode');

exports.activate = function activateStylelint(context) {
const serverModule = path.join(__dirname, 'server.js');

const client = new LanguageClient('stylelint', {
run: {
module: serverModule
},
debug: {
module: serverModule,
options: {
execArgv: ['--nolazy', '--debug=6004']
}
}
}, {
documentSelector: ['css', 'sass'],
synchronize: {
configurationSection: 'stylelint',
fileEvents: vscode.workspace.createFileSystemWatcher('**/.stylelintrc')
}
});

context.subscriptions.push(new SettingMonitor(client, 'stylelint.enable').start());
};
Empty file added fixture.css
Empty file.
291 changes: 291 additions & 0 deletions media/icon.ai

Large diffs are not rendered by default.

97 changes: 97 additions & 0 deletions media/icon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "stylelint",
"version": "0.1.0",
"displayName": "stylelint",
"description": "Modern CSS/SCSS linter",
"publisher": "shinnn",
"repository": "https://github.com/shinnn/vscode-stylelint",
"homepage": "https://github.com/shinnn/vscode-stylelint#readme",
"bugs": "https://github.com/shinnn/vscode-stylelint/issues",
"license": "MIT",
"icon": "media/icon.svg",
"galleryBanner": {
"color": "#32CD32",
"theme": "light"
},
"engines": {
"vscode": "^0.10.1"
},
"categories": [
"Linters"
],
"activationEvents": [
"onLanguage:css",
"onLanguage:sass"
],
"main": "extension.js",
"contributes": {
"configuration": {
"type": "object",
"title": "stylelint configuration options",
"properties": {
"stylelint.enable": {
"type": "boolean",
"default": false,
"description": "Control whether stylelint is enabled for CSS/SCSS files or not."
},
"stylelint.config": {
"type": "object",
"default": null,
"description": "A stylelint configuration object."
},
"stylelint.configOverrides": {
"type": "object",
"default": null,
"description": "A partial stylelint config whose properties override the existing ones."
}
}
}
},
"scripts": {
"test": "eslint --config @shinnn/node --fix extension.js server.js"
},
"dependencies": {
"stylelint-vscode": "^1.0.0",
"vscode-languageclient": "0.10.7",
"vscode-languageserver": "0.10.6"
},
"devDependencies": {
"@shinnn/eslint-config-node": "^1.0.1",
"eslint": "^1.10.1",
"vscode": "^0.10.6"
}
}
Binary file added screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

const path = require('path');

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

let configBasedir;
let config;
let configOverrides;

const connection = langServer.createConnection(process.stdin, process.stdout);
const documents = new langServer.TextDocuments();

function validate(document) {
return stylelintVSCode({
code: document.getText(),
config,
configOverrides,
configBasedir,
syntax: path.extname(String(document.uri)).toLowerCase() === '.scss' ? 'scss' : null
}).then(diagnostics => {
connection.sendDiagnostics({uri: document.uri, diagnostics});
}).catch(err => {
if (err.reasons) {
err.reasons.forEach(reason => connection.window.showErrorMessage('stylelint: ' + reason));
return;
}

connection.window.showErrorMessage('stylelint: ' + err.message);
});
}

function validateAll() {
return Promise.all(documents.all().map(document => validate(document)));
}

connection.onInitialize(params => {
configBasedir = params.rootPath;

validateAll();

return {
capabilities: {
textDocumentSync: documents.syncKind
}
};
});
connection.onDidChangeConfiguration(params => {
const settings = params.settings;
config = settings.stylelint.config || {};
configOverrides = settings.stylelint.configOverrides || {};

validateAll();
});
connection.onDidChangeWatchedFiles(() => validateAll());

documents.onDidChangeContent(event => validate(event.document));
documents.listen(connection);

connection.listen();

0 comments on commit 7d9a9db

Please sign in to comment.