forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake8.ts
More file actions
38 lines (30 loc) · 1.66 KB
/
Copy pathflake8.ts
File metadata and controls
38 lines (30 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'use strict';
import * as baseLinter from './baseLinter';
import { OutputChannel } from 'vscode';
import { Product, ProductExecutableAndArgs } from '../common/installer';
import { TextDocument, CancellationToken } from 'vscode';
export class Linter extends baseLinter.BaseLinter {
_columnOffset = 1;
constructor(outputChannel: OutputChannel) {
super('flake8', Product.flake8, outputChannel);
}
protected runLinter(document: TextDocument, cancellation: CancellationToken): Promise<baseLinter.ILintMessage[]> {
if (!this.pythonSettings.linting.flake8Enabled) {
return Promise.resolve([]);
}
let flake8Path = this.pythonSettings.linting.flake8Path;
let flake8Args = Array.isArray(this.pythonSettings.linting.flake8Args) ? this.pythonSettings.linting.flake8Args : [];
if (flake8Args.length === 0 && ProductExecutableAndArgs.has(Product.flake8) && flake8Path.toLocaleLowerCase() === 'flake8') {
flake8Path = ProductExecutableAndArgs.get(Product.flake8).executable;
flake8Args = ProductExecutableAndArgs.get(Product.flake8).args;
}
return new Promise<baseLinter.ILintMessage[]>((resolve, reject) => {
this.run(flake8Path, flake8Args.concat(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath]), document, this.getWorkspaceRootPath(document), cancellation).then(messages => {
messages.forEach(msg => {
msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.flake8CategorySeverity);
});
resolve(messages);
}, reject);
});
}
}