Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions src/format/RuboCop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ export class AutoCorrect {
}

// What's the exe name for rubocop?
get exe(): string {
const opts = this.opts;
get exe(): string[] {
const opts:any = this.opts;
if (opts.exe) {
return opts.exe;
return [opts.exe];
}

const ext: string = process.platform === 'win32' ? '.bat' : '';
if (vscode.workspace.getConfiguration('ruby').useBundler) {
return [`bundle${ext}`, 'exec', 'rubocop'];
}
const ext = process.platform === 'win32' ? '.bat' : '';
return `rubocop${ext}`;

return [`rubocop${ext}`];
}

// Arguments for running rubocop.
Expand Down Expand Up @@ -81,9 +86,20 @@ export class AutoCorrect {
// here to make it easier for users to debug config issues.
//

private spawn = (args: string[], options?: cp.SpawnOptions): cp.ChildProcess => {
const exe: string[] = this.exe;
const spawnOpt: cp.SpawnOptions = options ? options : {}

if (!spawnOpt.cwd) { spawnOpt.cwd = vscode.workspace.rootPath }

return cp.spawn(exe.shift(), exe.concat(args), spawnOpt);
};

public test(): Promise<any> {
return new Promise((resolve, reject) => {
const rubo = cp.spawn(this.exe, ['-v']);

const rubo = this.spawn(['-v']);

rubo.on('error', err => {
if (err.message.includes('ENOENT')) {
vscode.window.showErrorMessage(`couldn't find ${this.exe} for formatting (ENOENT)`);
Expand All @@ -98,6 +114,11 @@ export class AutoCorrect {
console.log(`rubocop stderr ${data}`);
});

rubo.stdout.on('data', data => {
// for debugging
console.log(`rubocop stdout ${data}`);
});

rubo.on('exit', code => {
if (code) {
vscode.window.showErrorMessage(`rubocop failed with code=${code}`);
Expand Down Expand Up @@ -133,7 +154,7 @@ export class AutoCorrect {
console.log(`${this.exe} ${args.join(' ')}`);

const startTm = new Date().getTime();
const rubo = cp.spawn(this.exe, args, {
const rubo = this.spawn(args, {
cwd: root || process.cwd(),
env: process.env,
});
Expand Down