Skip to content

Commit c9cc9df

Browse files
authored
Merge pull request #495 from tdamsma/pylama
Pylama
2 parents b6ab823 + 49ec7ad commit c9cc9df

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/client/common/configSettings.ts

Lines changed: 5 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;
@@ -137,6 +140,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
137140
lintOnSave: false, lintOnTextChange: false, maxNumberOfProblems: 100,
138141
mypyArgs: [], mypyEnabled: false, mypyPath: 'mypy',
139142
outputWindow: 'python', pep8Args: [], pep8Enabled: false, pep8Path: 'pep8',
143+
pylamaArgs: [], pylamaEnabled: false, pylamaPath: 'pylama',
140144
prospectorArgs: [], prospectorEnabled: false, prospectorPath: 'prospector',
141145
pydocstyleArgs: [], pydocstyleEnabled: false, pydocstylePath: 'pydocstyle',
142146
pylintArgs: [], pylintEnabled: false, pylintPath: 'pylint',
@@ -151,6 +155,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
151155
this.linting.pylintPath = getAbsolutePath(this.linting.pylintPath, workspaceRoot);
152156
this.linting.flake8Path = getAbsolutePath(this.linting.flake8Path, workspaceRoot);
153157
this.linting.pep8Path = getAbsolutePath(this.linting.pep8Path, workspaceRoot);
158+
this.linting.pylamaPath = getAbsolutePath(this.linting.pylamaPath, workspaceRoot);
154159
this.linting.prospectorPath = getAbsolutePath(this.linting.prospectorPath, workspaceRoot);
155160
this.linting.pydocstylePath = getAbsolutePath(this.linting.pydocstylePath, workspaceRoot);
156161

src/client/common/installer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum Product {
99
pylint,
1010
flake8,
1111
pep8,
12+
pylama,
1213
prospector,
1314
pydocstyle,
1415
yapf,
@@ -23,14 +24,15 @@ ProductInstallScripts.set(Product.flake8, ['pip', 'install', 'flake8']);
2324
ProductInstallScripts.set(Product.mypy, ['pip', 'install', 'mypy-lang']);
2425
ProductInstallScripts.set(Product.nosetest, ['pip', 'install', 'nose']);
2526
ProductInstallScripts.set(Product.pep8, ['pip', 'install', 'pep8']);
27+
ProductInstallScripts.set(Product.pylama, ['pip', 'install', 'pylama']);
2628
ProductInstallScripts.set(Product.prospector, ['pip', 'install', 'prospector']);
2729
ProductInstallScripts.set(Product.pydocstyle, ['pip', 'install', 'pydocstyle']);
2830
ProductInstallScripts.set(Product.pylint, ['pip', 'install', 'pylint']);
2931
ProductInstallScripts.set(Product.pytest, ['pip', 'install', '-U', 'pytest']);
3032
ProductInstallScripts.set(Product.yapf, ['pip', 'install', 'yapf']);
3133

3234

33-
const Linters: Product[] = [Product.flake8, Product.pep8, Product.prospector, Product.pylint, Product.mypy, Product.pydocstyle];
35+
const Linters: Product[] = [Product.flake8, Product.pep8, Product.pylama, Product.prospector, Product.pylint, Product.mypy, Product.pydocstyle];
3436
const Formatters: Product[] = [Product.autopep8, Product.yapf];
3537
const TestFrameworks: Product[] = [Product.pytest, Product.nosetest, Product.unittest];
3638

@@ -40,6 +42,7 @@ ProductNames.set(Product.flake8, 'flake8');
4042
ProductNames.set(Product.mypy, 'mypy');
4143
ProductNames.set(Product.nosetest, 'nosetest');
4244
ProductNames.set(Product.pep8, 'pep8');
45+
ProductNames.set(Product.pylama, 'pylama');
4346
ProductNames.set(Product.prospector, 'prospector');
4447
ProductNames.set(Product.pydocstyle, 'pydocstyle');
4548
ProductNames.set(Product.pylint, 'pylint');
@@ -52,6 +55,7 @@ SettingToDisableProduct.set(Product.flake8, 'linting.flake8Enabled');
5255
SettingToDisableProduct.set(Product.mypy, 'linting.mypyEnabled');
5356
SettingToDisableProduct.set(Product.nosetest, 'unitTest.nosetestsEnabled');
5457
SettingToDisableProduct.set(Product.pep8, 'linting.pep8Enabled');
58+
SettingToDisableProduct.set(Product.pylama, 'linting.pylamaEnabled');
5559
SettingToDisableProduct.set(Product.prospector, 'linting.prospectorEnabled');
5660
SettingToDisableProduct.set(Product.pydocstyle, 'linting.pydocstyleEnabled');
5761
SettingToDisableProduct.set(Product.pylint, 'linting.pylintEnabled');

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)