Skip to content

Commit

Permalink
Adding support for explicit rubocop configfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Preston committed Jun 7, 2017
1 parent 3715b81 commit 19025c9
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.6.3 (2017-06-06)
- Allow `rubocop.configFile` workspace parameter (@stuartpreston)

## 0.6.2 (2016-11-04)
- Use Cookstyle in place of Rubocop by default (@smith)

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2015 Pendrica
Copyright 2015-2017 Pendrica

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The Chef Extension for Visual Studio Code offers rich language support for Chef
* Entire repo will be linted when files are saved.
* If you have the [ChefDK](http://downloads.chef.io/chef-dk) installed, linting should "just work" on Windows, Mac OS X and Linux (Ubuntu.) [Cookstyle](https://github.com/chef/cookstyle) will be used by default.
* If you do not have the ChefDK but do have Rubocop installed, you can set the executable path by setting ```{ "rubocop.path": "c:\\path\\to\\rubocop.bat"}``` in user/workspace settings).
* To override the config file used by Rubocop/Cookstyle, use the ```{ "rubocop.configFile": "path/to/config.yml" }``` in user/workspace settings.

#### Foodcritic analysis (experimental):
* Disabled by default (enable by adding ```{ "foodcritic.enable": true }``` in user/workspace settings)
Expand Down Expand Up @@ -110,9 +111,9 @@ Contributions are welcomed, please file issues and pull requests via the [projec

## Author

This extension was written by Stuart Preston [stuart@pendrica.com](stuart@pendrica.com)
This extension was written by Stuart Preston [stuart@chef.io](stuart@chef.io)

## License
This extension is licensed under an [Apache 2](LICENSE.md) license.

(c) 2015-2016 Pendrica
(c) 2015-2017 Pendrica
20 changes: 17 additions & 3 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let diagnosticCollectionRubocop: vscode.DiagnosticCollection;
let diagnosticCollectionFoodcritic: vscode.DiagnosticCollection;
let config: vscode.WorkspaceConfiguration;
let rubocopPath: string;
let rubocopConfigFile: string;
let foodcriticPath: string;
let cookbookPaths: Array<string> = [];

Expand All @@ -25,8 +26,16 @@ export function activate(context: vscode.ExtensionContext): void {
}
} else {
rubocopPath = vscode.workspace.getConfiguration("rubocop").path;
console.log("Using custom Rubocop path:" + rubocopPath);
console.log("Using custom Rubocop path: " + rubocopPath);
}

if (vscode.workspace.getConfiguration("rubocop").configFile === "") {
console.log("No explicit config file set for Rubocop.");
} else {
rubocopConfigFile = vscode.workspace.getConfiguration("rubocop").configFile;
console.log("Using custom Rubocop config from: " + rubocopConfigFile);
}

if (vscode.workspace.getConfiguration("rubocop").enable) {
validateWorkspace();
context.subscriptions.push(startLintingOnSaveWatcher());
Expand All @@ -41,7 +50,7 @@ export function activate(context: vscode.ExtensionContext): void {
}
} else {
foodcriticPath = vscode.workspace.getConfiguration("foodcritic").path;
console.log("Using custom Foodcritic path:" + foodcriticPath);
console.log("Using custom Foodcritic path: " + foodcriticPath);
}

if (vscode.workspace.getConfiguration("foodcritic").enable) {
Expand Down Expand Up @@ -86,7 +95,12 @@ function convertSeverity(severity: string): vscode.DiagnosticSeverity {
function validateWorkspace(): void {
try {
let spawn = require("child_process").spawnSync;
let rubocop = spawn(rubocopPath, ["-f", "j", vscode.workspace.rootPath], { cwd: vscode.workspace.rootPath });
let rubocop: any;
if (rubocopConfigFile) {
rubocop = spawn(rubocopPath, ["--config", rubocopConfigFile, "-f", "j", vscode.workspace.rootPath], { cwd: vscode.workspace.rootPath });
} else {
rubocop = spawn(rubocopPath, ["-f", "j", vscode.workspace.rootPath], { cwd: vscode.workspace.rootPath });
}
let rubocopOutput = JSON.parse(rubocop.stdout);
if (rubocop.status < 2) {
let arr = [];
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Chef",
"description": "Chef language support and snippets for Visual Studio Code",
"version": "0.6.2",
"version": "0.6.3",
"publisher": "Pendrica",
"icon": "images/chef-logo.svg",
"displayName": "Chef Extension for Visual Studio Code",
Expand Down Expand Up @@ -80,6 +80,11 @@
"default": "",
"description": "Full path to Rubocop, only change this if you have the ChefDK installed in a non-standard location."
},
"rubocop.configFile": {
"type": "string",
"default": "",
"description": "Path to a Rubocop config file (e.g. .rubocop_shared.yml) - relative paths resolve inside the workspace."
},
"foodcritic.enable": {
"type": "boolean",
"default": false,
Expand All @@ -94,8 +99,8 @@
}
},
"scripts": {
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
}
}
14 changes: 6 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
"target": "ES5",
"target": "ES6",
"outDir": "out",
"sourceMap": true,
"typeRoots": [
"node_modules/@types"
"node_modules/@types",
"typings/"
],
"types": [
"node"
"lib": [
"es6"
]
},
"exclude": [
"node_modules"
]
}
}
1 change: 0 additions & 1 deletion typings/node.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion typings/vscode-typings.d.ts

This file was deleted.

0 comments on commit 19025c9

Please sign in to comment.