Skip to content

Commit e797bc7

Browse files
committed
set current directory for pylint, pep8 and flask commands #117
1 parent bf514e9 commit e797bc7

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/client/linters/baseLinter.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,17 @@ export abstract class BaseLinter {
6262
return Promise.resolve([]);
6363
}
6464

65-
protected run(commandLine: string, filePath: string, txtDocumentLines: string[], regEx: string = REGEX): Promise<ILintMessage[]> {
65+
protected run(commandLine: string, filePath: string, txtDocumentLines: string[], cwd: string, regEx: string = REGEX): Promise<ILintMessage[]> {
6666
var outputChannel = this.outputChannel;
6767
var linterId = this.Id;
6868

6969
return new Promise<ILintMessage[]>((resolve, reject) => {
70-
var fileDir = path.dirname(filePath);
71-
sendCommand(commandLine, fileDir, true).then(data => {
70+
sendCommand(commandLine, cwd, true).then(data => {
7271
outputChannel.clear();
73-
outputChannel.append(data);
72+
outputChannel.append(data);
7473
var outputLines = data.split(/\r?\n/g);
7574
var diagnostics: ILintMessage[] = [];
76-
outputLines.filter((value, index) => index <= this.pythonSettings.linting.maxNumberOfProblems).forEach(line=> {
75+
outputLines.filter((value, index) => index <= this.pythonSettings.linting.maxNumberOfProblems).forEach(line => {
7776
var match = matchNamedRegEx(line, regEx);
7877
if (match == null) {
7978
return;
@@ -86,7 +85,7 @@ export abstract class BaseLinter {
8685
var sourceLine = txtDocumentLines[match.line - 1];
8786
var sourceStart = sourceLine.substring(match.column - 1);
8887
var endCol = txtDocumentLines[match.line - 1].length;
89-
88+
9089
//try to get the first word from the startig position
9190
var possibleProblemWords = sourceStart.match(/\w+/g);
9291
var possibleWord: string;
@@ -111,7 +110,7 @@ export abstract class BaseLinter {
111110
});
112111

113112
resolve(diagnostics);
114-
}, error=> {
113+
}, error => {
115114
outputChannel.appendLine(`Linting with ${linterId} failed. If not installed please turn if off in settings.\n ${error}`);
116115
window.showInformationMessage(`Linting with ${linterId} failed. If not installed please turn if off in settings. View Python output for details.`);
117116
});

src/client/linters/flake8.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from 'path';
44
import * as baseLinter from './baseLinter';
55
import * as settings from './../common/configSettings';
6-
import {OutputChannel} from 'vscode';
6+
import {OutputChannel, workspace} from 'vscode';
77

88
const FLAKE8_COMMANDLINE = " --format='%(row)d,%(col)d,%(code)s,%(code)s:%(text)s'";
99

@@ -20,7 +20,7 @@ export class Linter extends baseLinter.BaseLinter {
2020
var flake8Path = this.pythonSettings.linting.flake8Path;
2121
var cmdLine = `${flake8Path} ${FLAKE8_COMMANDLINE} "${filePath}"`;
2222
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
23-
this.run(cmdLine, filePath, txtDocumentLines).then(messages=> {
23+
this.run(cmdLine, filePath, txtDocumentLines, workspace.rootPath).then(messages=> {
2424
//All messages in pep8 are treated as warnings for now
2525
messages.forEach(msg=> {
2626
msg.severity = baseLinter.LintMessageSeverity.Information;

src/client/linters/pep8Linter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from 'path';
44
import * as baseLinter from './baseLinter';
55
import * as settings from './../common/configSettings';
6-
import {OutputChannel} from 'vscode';
6+
import {OutputChannel, workspace} from 'vscode';
77

88
const PEP_COMMANDLINE = " --format='%(row)d,%(col)d,%(code)s,%(code)s:%(text)s'";
99

@@ -20,7 +20,7 @@ export class Linter extends baseLinter.BaseLinter {
2020
var pep8Path = this.pythonSettings.linting.pep8Path;
2121
var cmdLine = `${pep8Path} ${PEP_COMMANDLINE} "${filePath}"`;
2222
return new Promise<baseLinter.ILintMessage[]>(resolve => {
23-
this.run(cmdLine, filePath, txtDocumentLines).then(messages=> {
23+
this.run(cmdLine, filePath, txtDocumentLines, workspace.rootPath).then(messages=> {
2424
//All messages in pep8 are treated as warnings for now
2525
messages.forEach(msg=> {
2626
msg.severity = baseLinter.LintMessageSeverity.Information;

src/client/linters/pylint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as path from 'path';
44
import * as baseLinter from './baseLinter';
55
import * as settings from './../common/configSettings';
6-
import {OutputChannel} from 'vscode';
6+
import {OutputChannel, workspace} from 'vscode';
77

88
const PYLINT_COMMANDLINE = " --msg-template='{line},{column},{category},{msg_id}:{msg}' --reports=n --output-format=text";
99

@@ -32,7 +32,7 @@ export class Linter extends baseLinter.BaseLinter {
3232
var pylintPath = this.pythonSettings.linting.pylintPath;
3333
var cmdLine = `${pylintPath} ${PYLINT_COMMANDLINE} "${filePath}"`;
3434
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
35-
this.run(cmdLine, filePath, txtDocumentLines).then(messages=> {
35+
this.run(cmdLine, filePath, txtDocumentLines, workspace.rootPath).then(messages=> {
3636
messages.forEach(msg=> {
3737
msg.severity = this.parseMessagesSeverity(msg.type);
3838
});

0 commit comments

Comments
 (0)