Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #232 from wingrunr21/workspaceroot_support
Browse files Browse the repository at this point in the history
Add workspaceRoot and bundler support
  • Loading branch information
rebornix authored Jan 25, 2018
2 parents c65e82d + 2e42d02 commit 1614e2f
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/lint/lib/linter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

import {workspace} from 'vscode';

const fs = require('./fsPromise'),
path = require('path'),
os = require('os'),
Expand Down Expand Up @@ -56,10 +58,39 @@ class Linter {
}
return fs.link(sourceFile, opName).then(() => opName);
}
_detectBundledLinter(name, cwd) {
try {
cp.execSync(`bundle show ${name}`, { cwd });
return true;
} catch (e) {
return false;
}
}
_getLinterPath(svc) {
const workspaceRoot = workspace.rootPath;
let svcPath = svc.path || "";
svcPath = svcPath.replace('${workspaceRoot}', workspaceRoot);
return svcPath;
}
_getLinterCmd(svc, cmdOpts) {
const args = svc.args.map(arg => arg.replace("{path}", cmdOpts.file || ""));
let svcPath = this._getLinterPath(svc);

// Try bundler for the linter
// otherwise fallback to the path + the exe name
if (svcPath.length === 0 && this._detectBundledLinter(svc.exe, cmdOpts.dir)) {
svcPath = 'bundle';
args.unshift('exec', svc.exe);
} else {
svcPath = path.join(svcPath, svc.exe + svc.ext);
}

return [svcPath, args];
}
_exeLinter(svc, cmdOpts) {
return new Promise((resolve, reject) => {
const args = svc.args.map(arg => arg.replace("{path}", cmdOpts.file || ""));
const spawned = cp.spawn(path.join(svc.path || "", svc.exe + svc.ext), args, {
const [svcPath, args] = this._getLinterCmd(svc, cmdOpts);
const spawned = cp.spawn(svcPath, args, {
cwd: cmdOpts.dir,
env: process.env
});
Expand Down Expand Up @@ -135,7 +166,7 @@ class Linter {
return prom.then(final);
});
const noTmpFileSvc = () => toRun.filter(svc => !svc.tmp).map(svc => this._exeLinter(svc, {
dir: this.rootPath || sourceDir,
dir: sourceDir || this.rootPath,
data: doc.getText(),
file: doc.fileName
}).then(final));
Expand Down

0 comments on commit 1614e2f

Please sign in to comment.