Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Oct 16, 2015
0 parents commit 04572a7
Show file tree
Hide file tree
Showing 17 changed files with 2,556 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{*.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules/
17 changes: 17 additions & 0 deletions .vscode/launch.json
@@ -0,0 +1,17 @@
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
"configurations": [
{
"name": "Attach to Language Worker",
"type": "node",
"request": "attach",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5871,
"outDir": "out",
"sourceMaps": true
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,9 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"out": false // set this to true to hide the "out" folder with the compiled JS files
},
"search.exclude": {
"out": true
}
}
30 changes: 30 additions & 0 deletions .vscode/tasks.json
@@ -0,0 +1,30 @@
// Available variables which can be used inside of strings.
// ${workspaceRoot}: the root folder of the team
// ${file}: the current opened file
// ${fileBasename}: the current opened file's basename
// ${fileDirname}: the current opened file's dirname
// ${fileExtname}: the current opened file's extension
// ${cwd}: the current working directory of the spawned process

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile"],

// The tsc compiler is started in watching mode
"isWatching": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
}
7 changes: 7 additions & 0 deletions .vscodeignore
@@ -0,0 +1,7 @@
.vscode/**
typings/**
**/*.ts
**/*.map
.gitignore
tsconfig.json
screenshot.png
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Sam Verschueren <sam.verschueren@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
48 changes: 48 additions & 0 deletions README.md
@@ -0,0 +1,48 @@
# vscode-linter-xo

> Linter for [XO](https://github.com/sindresorhus/xo)

## Install

Press <kbd>F1</kbd> and narrow down the list commands by typing `extension`. Pick `Extensions: Install Extension`.

![](https://github.com/SamVerschueren/vscode-linter-xo/raw/master/screenshot.png)

Simply pick the `linter-xo` extension from the list

## Usage

Enable the linter in the VS Code Settings.

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

You can also pass in extra options via the settings file.

```json
{
"xo.enable": true,
"xo.options": {
"semicolon": false
}
}
```

Settings can also be set in the `package.json` file.

```json
{
"name": "my-pkg",
"xo": {
"semicolon": false
}
}
```

## License

MIT © [Sam Verschueren](http://github.com/SamVerschueren)
78 changes: 78 additions & 0 deletions extension.ts
@@ -0,0 +1,78 @@
'use strict';

import { runSingleFileValidator, SingleFileValidator, InitializeResponse, IValidationRequestor, IDocument, Diagnostic, Severity, Files } from 'vscode-languageworker';

import path = require('path');
import fs = require('fs');
import objectAssign = require('object-assign');

let lintText: any = null;
let lintConfig: Object = null;

function makeDiagnostic(problem: any): Diagnostic {
return {
message: `${problem.message} (${problem.ruleId})`,
severity: problem.severity === 2 ? Severity.Error : Severity.Warning,
start: {
line: problem.line,
character: problem.column
},
end: {
line: problem.line,
character: problem.column
}
};
}

let validator : SingleFileValidator = {
initialize: (rootFolder: string): Thenable<InitializeResponse> => {
return Files.resolveModule(rootFolder, 'xo').then(xo => {
lintText = xo.lintText;
return null;
}, (error) => {
return Promise.reject({
success: false,
message: 'Failed to load xo library. Please install xo in your workspace folder using \'npm install xo\' and then press Retry.',
retry: true
});
});
},
onConfigurationChange(settings: any, requestor: IValidationRequestor): void {
// VSCode settings have changed and the requested settings changes
// have been synced over to the language worker
if (settings.xo) {
lintConfig = settings.xo.options;
}

// Request re-validation of all open documents
requestor.all();
},
validate: (document: IDocument): Diagnostic[] => {
try {
const uri = document.uri;
const fsPath = Files.uriToFilePath(uri);
const contents = document.getText();

const report = lintText(contents, objectAssign({cwd: path.dirname(fsPath)}, lintConfig));

let diagnostics: Diagnostic[] = [];

report.results.forEach(result => {
result.messages.forEach(message => {
diagnostics.push(makeDiagnostic(message));
});
});

return diagnostics;
} catch (err) {
let message: string = null;
if (typeof err.message === 'string' || err.message instanceof String) {
message = <string>err.message;
throw new Error(message);
}
throw err;
}
}
};

runSingleFileValidator(process.stdin, process.stdout, validator);
68 changes: 68 additions & 0 deletions out/extension.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions out/extension.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions package.json
@@ -0,0 +1,60 @@
{
"name": "linter-xo",
"version": "0.1.0",
"publisher": "SamVerschueren",
"engines": {
"vscode": "*"
},
"dependencies": {
"object-assign": "^4.0.1",
"vscode-languageworker": "*",
"xo": "^0.9.0"
},
"devDependencies": {
"typescript": "^1.6.2"
},
"contributes": {
"configuration": {
"type": "object",
"title": "xo configuration",
"properties": {
"xo.enable": {
"type": "boolean",
"default": false,
"description": "Control whether xo is enabled or not."
},
"xo.options": {
"type": "object",
"default": {},
"description": "The xo options object to provide args to the xo command."
}
}
},
"languageWorkers": {
"activate": [
"onLanguage:javascript",
"onLanguage:javascriptreact"
],
"executable": {
"run": {
"nodeModule": "out/extension.js"
},
"debug": {
"nodeModule": "out/extension.js",
"execArgv": [
"--nolazy",
"--debug=5871"
]
}
},
"watchFiles": [
"**/*.js"
],
"settings": "xo"
}
},
"scripts": {
"vscode:prepublish": "tsc",
"compile": "tsc -watch -p ./"
}
}
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.
11 changes: 11 additions & 0 deletions tsconfig.json
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"outDir": "out",
"sourceMap": true
},
"exclude": [
"node_modules"
]
}

0 comments on commit 04572a7

Please sign in to comment.