Skip to content

Commit 4ca11c4

Browse files
author
Thijs Damsma
committed
implement pylama like pep8
1 parent fd24aaf commit 4ca11c4

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/client/common/configSettings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export interface ILintingSettings {
4848
pylintArgs: string[];
4949
pep8Enabled: boolean;
5050
pep8Args: string[];
51+
pylamaEnabled: boolean;
52+
pylamaArgs: string[];
5153
flake8Enabled: boolean;
5254
flake8Args: string[];
5355
pydocstyleEnabled: boolean;
@@ -59,6 +61,7 @@ export interface ILintingSettings {
5961
prospectorPath: string;
6062
pylintPath: string;
6163
pep8Path: string;
64+
pylamaPath: string;
6265
flake8Path: string;
6366
pydocstylePath: string;
6467
outputWindow: string;
@@ -151,6 +154,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
151154
this.linting.pylintPath = getAbsolutePath(this.linting.pylintPath, workspaceRoot);
152155
this.linting.flake8Path = getAbsolutePath(this.linting.flake8Path, workspaceRoot);
153156
this.linting.pep8Path = getAbsolutePath(this.linting.pep8Path, workspaceRoot);
157+
this.linting.pylamaPath = getAbsolutePath(this.linting.pylamaPath, workspaceRoot);
154158
this.linting.prospectorPath = getAbsolutePath(this.linting.prospectorPath, workspaceRoot);
155159
this.linting.pydocstylePath = getAbsolutePath(this.linting.pydocstylePath, workspaceRoot);
156160

src/client/linters/pylama.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
import * as baseLinter from './baseLinter';
4+
import {OutputChannel} from 'vscode';
5+
import { Product } from '../common/installer';
6+
7+
export class Linter extends baseLinter.BaseLinter {
8+
constructor(outputChannel: OutputChannel, workspaceRootPath: string) {
9+
super('pylama', Product.pylama, outputChannel, workspaceRootPath);
10+
}
11+
12+
public isEnabled(): Boolean {
13+
return this.pythonSettings.linting.pylamaEnabled;
14+
}
15+
public runLinter(filePath: string, txtDocumentLines: string[]): Promise<baseLinter.ILintMessage[]> {
16+
if (!this.pythonSettings.linting.pylamaEnabled) {
17+
return Promise.resolve([]);
18+
}
19+
20+
let pylamaPath = this.pythonSettings.linting.pylamaPath;
21+
let pylamaArgs = Array.isArray(this.pythonSettings.linting.pylamaArgs) ? this.pythonSettings.linting.pylamaArgs : [];
22+
return new Promise<baseLinter.ILintMessage[]>(resolve => {
23+
this.run(pylamaPath, pylamaArgs.concat(['--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s', filePath]), filePath, txtDocumentLines, this.workspaceRootPath).then(messages => {
24+
// All messages in pylama are treated as warnings for now
25+
messages.forEach(msg => {
26+
msg.severity = baseLinter.LintMessageSeverity.Information;
27+
});
28+
29+
resolve(messages);
30+
});
31+
});
32+
}
33+
}

src/client/providers/lintProvider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as linter from '../linters/baseLinter';
66
import * as prospector from './../linters/prospector';
77
import * as pylint from './../linters/pylint';
88
import * as pep8 from './../linters/pep8Linter';
9+
import * as pylama from './../linters/pylama';
910
import * as flake8 from './../linters/flake8';
1011
import * as pydocstyle from './../linters/pydocstyle';
1112
import * as mypy from './../linters/mypy';
@@ -71,6 +72,7 @@ export class LintProvider extends vscode.Disposable {
7172
this.linters.push(new prospector.Linter(this.outputChannel, this.workspaceRootPath));
7273
this.linters.push(new pylint.Linter(this.outputChannel, this.workspaceRootPath));
7374
this.linters.push(new pep8.Linter(this.outputChannel, this.workspaceRootPath));
75+
this.linters.push(new pylama.Linter(this.outputChannel, this.workspaceRootPath));
7476
this.linters.push(new flake8.Linter(this.outputChannel, this.workspaceRootPath));
7577
this.linters.push(new pydocstyle.Linter(this.outputChannel, this.workspaceRootPath));
7678
this.linters.push(new mypy.Linter(this.outputChannel, this.workspaceRootPath));

0 commit comments

Comments
 (0)