Skip to content

Commit

Permalink
Merge branch 'bojand-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxsan committed Sep 8, 2017
2 parents 8ea2b8e + d1d88d8 commit aaf55f5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
37 changes: 35 additions & 2 deletions eslint-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {

import Uri from 'vscode-uri';
import path = require('path');
import fs = require('fs');
const deglob = require('deglob');
namespace Is {
const toString = Object.prototype.toString;
Expand Down Expand Up @@ -133,6 +134,7 @@ interface Settings {
semistandard?: boolean;
validate?: (string | ValidateItem)[];
workingDirectories?: (string | DirectoryItem)[];
usePackageJson?: boolean;
}
[key: string]: any;
}
Expand Down Expand Up @@ -343,7 +345,38 @@ documents.onDidOpen((event) => {
if (!supportedLanguages[event.document.languageId]) {
return;
}
const style = settings.standard.semistandard ? 'semistandard' : 'standard';
const usePackageJson = settings.standard.usePackageJson;
let pkgStyle
let pkgOptions
if (usePackageJson) {
const pkgPath = path.join(workspaceRoot, 'package.json');
const pkgExists = fs.existsSync(pkgPath);
if (pkgExists) {
const pkgStr = fs.readFileSync(pkgPath, 'utf8');
const pkg = JSON.parse(pkgStr);
if (pkg && pkg.devDependencies && pkg.devDependencies.standard) {
pkgStyle = 'standard';
} else if (pkg && pkg.devDependencies && pkg.devDependencies.semistandard) {
pkgStyle = 'semistandard';
}

if (pkgStyle) {
pkgOptions = pkg[pkgStyle];
} else {
connection.console.info('no standard in package.json');
return;
}
}
}

let style = settings.standard.semistandard ? 'semistandard' : 'standard';
if (pkgStyle) {
style = pkgStyle;
}
if (pkgOptions) {
options = pkgOptions;
}

if (!document2Library[event.document.uri]) {
let uri = Uri.parse(event.document.uri);
let promise: Thenable<string>
Expand Down Expand Up @@ -1145,4 +1178,4 @@ connection.onExecuteCommand((params) => {
connection.console.error(`Failed to apply command: ${params.command}`);
});
})
connection.listen();
connection.listen();
5 changes: 5 additions & 0 deletions eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
"javascriptreact"
],
"description": "An array of language ids which should be validated by JavaScript Standard Style"
},
"standard.usePackageJson": {
"type": "boolean",
"default": false,
"description": "Activate only if present in package.json and use settings specified there."
}
}
},
Expand Down

0 comments on commit aaf55f5

Please sign in to comment.