Skip to content

Commit 587f480

Browse files
committed
linter issues (if errors, promise wasn't resolved)
1 parent 89fc7fe commit 587f480

File tree

7 files changed

+184
-192
lines changed

7 files changed

+184
-192
lines changed

src/client/linters/baseLinter.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ import {execPythonFile} from './../common/utils';
66
import * as settings from './../common/configSettings';
77
import {OutputChannel, window} from 'vscode';
88

9-
var NamedRegexp = null;
9+
let NamedRegexp = null;
1010
const REGEX = '(?<line>\\d+),(?<column>\\d+),(?<type>\\w+),(?<code>\\w\\d+):(?<message>.*)\\r?(\\n|$)';
1111

1212
export interface IRegexGroup {
13-
line: number
14-
column: number
15-
code: string
16-
message: string
17-
type: string
13+
line: number;
14+
column: number;
15+
code: string;
16+
message: string;
17+
type: string;
1818
}
1919

2020
export interface ILintMessage {
21-
line: number
22-
column: number
23-
code: string
24-
message: string
25-
type: string
26-
possibleWord?: string
27-
severity?: LintMessageSeverity
28-
provider: string
21+
line: number;
22+
column: number;
23+
code: string;
24+
message: string;
25+
type: string;
26+
possibleWord?: string;
27+
severity?: LintMessageSeverity;
28+
provider: string;
2929
}
3030
export enum LintMessageSeverity {
3131
Hint,
@@ -39,10 +39,10 @@ export function matchNamedRegEx(data, regex): IRegexGroup {
3939
NamedRegexp = require('named-js-regexp');
4040
}
4141

42-
var compiledRegexp = NamedRegexp(regex, 'g');
43-
var rawMatch = compiledRegexp.exec(data);
42+
let compiledRegexp = NamedRegexp(regex, 'g');
43+
let rawMatch = compiledRegexp.exec(data);
4444
if (rawMatch !== null) {
45-
return <IRegexGroup>rawMatch.groups()
45+
return <IRegexGroup>rawMatch.groups();
4646
}
4747

4848
return null;
@@ -59,17 +59,17 @@ export abstract class BaseLinter {
5959
public abstract runLinter(filePath: string, txtDocumentLines: string[]): Promise<ILintMessage[]>;
6060

6161
protected run(command: string, args: string[], filePath: string, txtDocumentLines: string[], cwd: string, regEx: string = REGEX): Promise<ILintMessage[]> {
62-
var outputChannel = this.outputChannel;
63-
var linterId = this.Id;
62+
let outputChannel = this.outputChannel;
63+
let linterId = this.Id;
6464

6565
return new Promise<ILintMessage[]>((resolve, reject) => {
6666
execPythonFile(command, args, cwd, true).then(data => {
6767
outputChannel.append('#'.repeat(10) + 'Linting Output - ' + this.Id + '#'.repeat(10) + '\n');
6868
outputChannel.append(data);
69-
var outputLines = data.split(/\r?\n/g);
70-
var diagnostics: ILintMessage[] = [];
69+
let outputLines = data.split(/\r?\n/g);
70+
let diagnostics: ILintMessage[] = [];
7171
outputLines.filter((value, index) => index <= this.pythonSettings.linting.maxNumberOfProblems).forEach(line => {
72-
var match = matchNamedRegEx(line, regEx);
72+
let match = matchNamedRegEx(line, regEx);
7373
if (match == null) {
7474
return;
7575
}
@@ -78,13 +78,13 @@ export abstract class BaseLinter {
7878
match.line = Number(<any>match.line);
7979
match.column = Number(<any>match.column);
8080

81-
var sourceLine = txtDocumentLines[match.line - 1];
82-
var sourceStart = sourceLine.substring(match.column - 1);
83-
var endCol = txtDocumentLines[match.line - 1].length;
81+
let sourceLine = txtDocumentLines[match.line - 1];
82+
let sourceStart = sourceLine.substring(match.column - 1);
83+
let endCol = txtDocumentLines[match.line - 1].length;
8484

85-
//try to get the first word from the startig position
86-
var possibleProblemWords = sourceStart.match(/\w+/g);
87-
var possibleWord: string;
85+
// try to get the first word from the startig position
86+
let possibleProblemWords = sourceStart.match(/\w+/g);
87+
let possibleWord: string;
8888
if (possibleProblemWords != null && possibleProblemWords.length > 0 && sourceStart.startsWith(possibleProblemWords[0])) {
8989
possibleWord = possibleProblemWords[0];
9090
}
@@ -100,16 +100,16 @@ export abstract class BaseLinter {
100100
});
101101
}
102102
catch (ex) {
103-
//Hmm, need to handle this later
104-
//TODO:
105-
var y = '';
103+
// Hmm, need to handle this later
104+
// TODO:
105+
let y = '';
106106
}
107107
});
108108

109109
resolve(diagnostics);
110110
}).catch(error => {
111111
this.handleError(this.Id, command, error);
112-
return [];
112+
resolve([]);
113113
});
114114
});
115115
}

src/client/linters/flake8.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as baseLinter from './baseLinter';
55
import {OutputChannel, workspace} from 'vscode';
66
export class Linter extends baseLinter.BaseLinter {
77
constructor(outputChannel: OutputChannel, workspaceRootPath: string) {
8-
super("flake8", outputChannel, workspaceRootPath);
8+
super('flake8', outputChannel, workspaceRootPath);
99
}
1010

1111
public isEnabled(): Boolean {
@@ -16,11 +16,11 @@ export class Linter extends baseLinter.BaseLinter {
1616
return Promise.resolve([]);
1717
}
1818

19-
var flake8Path = this.pythonSettings.linting.flake8Path;
19+
let flake8Path = this.pythonSettings.linting.flake8Path;
2020
let flake8Args = Array.isArray(this.pythonSettings.linting.flake8Args) ? this.pythonSettings.linting.flake8Args : [];
2121
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
22-
this.run(flake8Path, flake8Args.concat(["--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s", filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
23-
//All messages in pep8 are treated as warnings for now
22+
this.run(flake8Path, flake8Args.concat(['--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s', filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
23+
// All messages in pep8 are treated as warnings for now
2424
messages.forEach(msg => {
2525
msg.severity = baseLinter.LintMessageSeverity.Information;
2626
});

src/client/linters/pep8Linter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {OutputChannel, workspace} from 'vscode';
66

77
export class Linter extends baseLinter.BaseLinter {
88
constructor(outputChannel: OutputChannel, workspaceRootPath: string) {
9-
super("pep8", outputChannel, workspaceRootPath);
9+
super('pep8', outputChannel, workspaceRootPath);
1010
}
1111

1212
public isEnabled(): Boolean {
@@ -17,11 +17,11 @@ export class Linter extends baseLinter.BaseLinter {
1717
return Promise.resolve([]);
1818
}
1919

20-
var pep8Path = this.pythonSettings.linting.pep8Path;
20+
let pep8Path = this.pythonSettings.linting.pep8Path;
2121
let pep8Args = Array.isArray(this.pythonSettings.linting.pep8Args) ? this.pythonSettings.linting.pep8Args : [];
2222
return new Promise<baseLinter.ILintMessage[]>(resolve => {
23-
this.run(pep8Path, pep8Args.concat(["--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s", filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
24-
//All messages in pep8 are treated as warnings for now
23+
this.run(pep8Path, pep8Args.concat(['--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s', filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
24+
// All messages in pep8 are treated as warnings for now
2525
messages.forEach(msg => {
2626
msg.severity = baseLinter.LintMessageSeverity.Information;
2727
});

src/client/linters/prospector.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ interface IProspectorResponse {
99
messages: IProspectorMessage[];
1010
}
1111
interface IProspectorMessage {
12-
source: "string";
13-
message: "string";
14-
code: "string";
12+
source: string;
13+
message: string;
14+
code: string;
1515
location: IProspectorLocation;
1616
}
1717
interface IProspectorLocation {
@@ -78,7 +78,7 @@ export class Linter extends baseLinter.BaseLinter {
7878
resolve(diagnostics);
7979
}).catch(error => {
8080
this.handleError(this.Id, prospectorPath, error);
81-
return [];
81+
resolve([]);
8282
});
8383
});
8484
}

src/client/linters/pydocstyle.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export class Linter extends baseLinter.BaseLinter {
2020
return Promise.resolve([]);
2121
}
2222

23-
var pydocStylePath = this.pythonSettings.linting.pydocStylePath;
23+
let pydocStylePath = this.pythonSettings.linting.pydocStylePath;
2424
let pydocstyleArgs = Array.isArray(this.pythonSettings.linting.pydocstleArgs) ? this.pythonSettings.linting.pydocstleArgs : [];
2525
return new Promise<baseLinter.ILintMessage[]>(resolve => {
2626
this.run(pydocStylePath, pydocstyleArgs.concat([filePath]), filePath, txtDocumentLines).then(messages => {
27-
//All messages in pep8 are treated as warnings for now
27+
// All messages in pep8 are treated as warnings for now
2828
messages.forEach(msg => {
2929
msg.severity = baseLinter.LintMessageSeverity.Information;
3030
});
@@ -35,21 +35,21 @@ export class Linter extends baseLinter.BaseLinter {
3535
}
3636

3737
protected run(commandLine: string, args: string[], filePath: string, txtDocumentLines: string[]): Promise<ILintMessage[]> {
38-
var outputChannel = this.outputChannel;
39-
var linterId = this.Id;
38+
let outputChannel = this.outputChannel;
39+
let linterId = this.Id;
4040

4141
return new Promise<ILintMessage[]>((resolve, reject) => {
42-
var fileDir = path.dirname(filePath);
42+
let fileDir = path.dirname(filePath);
4343
execPythonFile(commandLine, args, this.workspaceRootPath, true).then(data => {
4444
outputChannel.append('#'.repeat(10) + 'Linting Output - ' + this.Id + '#'.repeat(10) + '\n');
4545
outputChannel.append(data);
46-
var outputLines = data.split(/\r?\n/g);
47-
var diagnostics: ILintMessage[] = [];
48-
var baseFileName = path.basename(filePath);
46+
let outputLines = data.split(/\r?\n/g);
47+
let diagnostics: ILintMessage[] = [];
48+
let baseFileName = path.basename(filePath);
4949

5050
// Remember, the first line of the response contains the file name and line number, the next line contains the error message
5151
// So we have two lines per message, hence we need to take lines in pairs
52-
var maxLines = this.pythonSettings.linting.maxNumberOfProblems * 2;
52+
let maxLines = this.pythonSettings.linting.maxNumberOfProblems * 2;
5353
// First line is almost always empty
5454
let oldOutputLines = outputLines.filter(line => line.length > 0);
5555
outputLines = [];
@@ -85,14 +85,14 @@ export class Linter extends baseLinter.BaseLinter {
8585
});
8686
}
8787
catch (ex) {
88-
//Hmm, need to handle this later
89-
var y = '';
88+
// Hmm, need to handle this later
89+
let y = '';
9090
}
9191
});
9292
resolve(diagnostics);
9393
}, error => {
9494
this.handleError(this.Id, commandLine, error);
95-
return [];
95+
resolve([]);
9696
});
9797
});
9898
}

src/client/linters/pylint.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ import {OutputChannel, workspace} from 'vscode';
66

77
export class Linter extends baseLinter.BaseLinter {
88
constructor(outputChannel: OutputChannel, workspaceRootPath: string) {
9-
super("pylint", outputChannel, workspaceRootPath);
9+
super('pylint', outputChannel, workspaceRootPath);
1010
}
1111

1212
private parseMessagesSeverity(category: string): baseLinter.LintMessageSeverity {
1313
if (this.pythonSettings.linting.pylintCategorySeverity[category]) {
1414
let severityName = this.pythonSettings.linting.pylintCategorySeverity[category];
1515
switch (severityName) {
16-
case "Error":
16+
case 'Error':
1717
return baseLinter.LintMessageSeverity.Error;
18-
case "Hint":
18+
case 'Hint':
1919
return baseLinter.LintMessageSeverity.Hint;
20-
case "Information":
20+
case 'Information':
2121
return baseLinter.LintMessageSeverity.Information;
22-
case "Warning":
22+
case 'Warning':
2323
return baseLinter.LintMessageSeverity.Warning;
2424
default: {
2525
if (baseLinter.LintMessageSeverity[severityName]) {
@@ -43,7 +43,7 @@ export class Linter extends baseLinter.BaseLinter {
4343
let pylintPath = this.pythonSettings.linting.pylintPath;
4444
let pylintArgs = Array.isArray(this.pythonSettings.linting.pylintArgs) ? this.pythonSettings.linting.pylintArgs : [];
4545
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
46-
this.run(pylintPath, pylintArgs.concat(["--msg-template='{line},{column},{category},{msg_id}:{msg}'", "--reports=n", "--output-format=text", filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
46+
this.run(pylintPath, pylintArgs.concat(['--msg-template=\'{line},{column},{category},{msg_id}:{msg}\'', '--reports=n', '--output-format=text', filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
4747
messages.forEach(msg => {
4848
msg.severity = this.parseMessagesSeverity(msg.type);
4949
});

0 commit comments

Comments
 (0)