diff --git a/package.json b/package.json index c4847c4632d1..fdc1391200c2 100644 --- a/package.json +++ b/package.json @@ -1068,6 +1068,83 @@ "Warning" ] }, + "python.linting.pep8CategorySeverity.W": { + "type": "string", + "default": "Warning", + "description": "Severity of Pep8 message type 'W'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, + "python.linting.pep8CategorySeverity.E": { + "type": "string", + "default": "Error", + "description": "Severity of Pep8 message type 'E'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, + "python.linting.flake8CategorySeverity.F": { + "type": "string", + "default": "Error", + "description": "Severity of Flake8 message type 'F'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, + "python.linting.flake8CategorySeverity.E": { + "type": "string", + "default": "Error", + "description": "Severity of Flake8 message type 'E'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, + "python.linting.flake8CategorySeverity.W": { + "type": "string", + "default": "Warning", + "description": "Severity of Flake8 message type 'W'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, + "python.linting.mypyCategorySeverity.error": { + "type": "string", + "default": "Error", + "description": "Severity of Mypy message type 'Error'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, + "python.linting.mypyCategorySeverity.note": { + "type": "string", + "default": "Information", + "description": "Severity of Mypy message type 'Note'.", + "enum": [ + "Hint", + "Error", + "Information", + "Warning" + ] + }, "python.linting.prospectorPath": { "type": "string", "default": "prospector", diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index c2f91de2e1b4..8d8af85e2987 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -49,6 +49,19 @@ export interface IPylintCategorySeverity { error: vscode.DiagnosticSeverity; fatal: vscode.DiagnosticSeverity; } +export interface IPep8CategorySeverity { + W: vscode.DiagnosticSeverity; + E: vscode.DiagnosticSeverity; +} +export interface Flake8CategorySeverity { + F: vscode.DiagnosticSeverity; + E: vscode.DiagnosticSeverity; + W: vscode.DiagnosticSeverity; +} +export interface IMypyCategorySeverity { + error: vscode.DiagnosticSeverity; + note: vscode.DiagnosticSeverity; +} export interface ILintingSettings { enabled: boolean; enabledWithoutWorkspace: boolean; @@ -69,6 +82,9 @@ export interface ILintingSettings { lintOnSave: boolean; maxNumberOfProblems: number; pylintCategorySeverity: IPylintCategorySeverity; + pep8CategorySeverity: IPep8CategorySeverity; + flake8CategorySeverity: Flake8CategorySeverity; + mypyCategorySeverity: IMypyCategorySeverity; prospectorPath: string; pylintPath: string; pep8Path: string; @@ -183,6 +199,19 @@ export class PythonSettings extends EventEmitter implements IPythonSettings { fatal: vscode.DiagnosticSeverity.Error, refactor: vscode.DiagnosticSeverity.Hint, warning: vscode.DiagnosticSeverity.Warning + }, + pep8CategorySeverity: { + E: vscode.DiagnosticSeverity.Error, + W: vscode.DiagnosticSeverity.Warning + }, + flake8CategorySeverity: { + F: vscode.DiagnosticSeverity.Error, + E: vscode.DiagnosticSeverity.Error, + W: vscode.DiagnosticSeverity.Warning + }, + mypyCategorySeverity: { + error: vscode.DiagnosticSeverity.Error, + note: vscode.DiagnosticSeverity.Hint } }; this.linting.pylintPath = getAbsolutePath(systemVariables.resolveAny(this.linting.pylintPath), workspaceRoot); diff --git a/src/client/linters/baseLinter.ts b/src/client/linters/baseLinter.ts index ab4fa1372fc3..818c201e9269 100644 --- a/src/client/linters/baseLinter.ts +++ b/src/client/linters/baseLinter.ts @@ -65,6 +65,29 @@ export abstract class BaseLinter { public abstract isEnabled(): Boolean; public abstract runLinter(document: vscode.TextDocument, cancellation: vscode.CancellationToken): Promise; + protected parseMessagesSeverity(error: string, categorySeverity: any): LintMessageSeverity { + if (categorySeverity[error]) { + let severityName = categorySeverity[error]; + switch (severityName) { + case 'Error': + return LintMessageSeverity.Error; + case 'Hint': + return LintMessageSeverity.Hint; + case 'Information': + return LintMessageSeverity.Information; + case 'Warning': + return LintMessageSeverity.Warning; + default: { + if (LintMessageSeverity[severityName]) { + return LintMessageSeverity[severityName]; + } + } + } + } + + return LintMessageSeverity.Information; + } + protected run(command: string, args: string[], document: vscode.TextDocument, cwd: string, cancellation: vscode.CancellationToken, regEx: string = REGEX): Promise { let outputChannel = this.outputChannel; diff --git a/src/client/linters/flake8.ts b/src/client/linters/flake8.ts index aa41fe706c43..0bf1f0624157 100644 --- a/src/client/linters/flake8.ts +++ b/src/client/linters/flake8.ts @@ -10,20 +10,6 @@ export class Linter extends baseLinter.BaseLinter { super('flake8', Product.flake8, outputChannel, workspaceRootPath); } - private parseMessagesCodeSeverity(error: string): baseLinter.LintMessageSeverity { - - let category_letter = error[0]; - switch (category_letter) { - case 'F': - case 'E': - return baseLinter.LintMessageSeverity.Error; - case 'W': - return baseLinter.LintMessageSeverity.Warning; - default: - return baseLinter.LintMessageSeverity.Information; - } - } - public isEnabled(): Boolean { return this.pythonSettings.linting.flake8Enabled; } @@ -35,9 +21,9 @@ export class Linter extends baseLinter.BaseLinter { let flake8Path = this.pythonSettings.linting.flake8Path; let flake8Args = Array.isArray(this.pythonSettings.linting.flake8Args) ? this.pythonSettings.linting.flake8Args : []; return new Promise((resolve, reject) => { - this.run(flake8Path, flake8Args.concat(['--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => { + this.run(flake8Path, flake8Args.concat(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => { messages.forEach(msg => { - msg.severity = this.parseMessagesCodeSeverity(msg.type); + msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.flake8CategorySeverity); }); resolve(messages); diff --git a/src/client/linters/mypy.ts b/src/client/linters/mypy.ts index de7290c4bd32..3713e3aeb422 100644 --- a/src/client/linters/mypy.ts +++ b/src/client/linters/mypy.ts @@ -11,19 +11,6 @@ export class Linter extends baseLinter.BaseLinter { constructor(outputChannel: OutputChannel, workspaceRootPath?: string) { super('mypy', Product.mypy, outputChannel, workspaceRootPath); } - private parseMessagesSeverity(category: string): baseLinter.LintMessageSeverity { - switch (category) { - case 'error': { - return baseLinter.LintMessageSeverity.Error; - } - case 'note': { - return baseLinter.LintMessageSeverity.Hint; - } - default: { - return baseLinter.LintMessageSeverity.Information; - } - } - } public isEnabled(): Boolean { return this.pythonSettings.linting.mypyEnabled; @@ -38,7 +25,7 @@ export class Linter extends baseLinter.BaseLinter { return new Promise((resolve, reject) => { this.run(mypyPath, mypyArgs.concat([document.uri.fsPath]), document, this.workspaceRootPath, cancellation, REGEX).then(messages => { messages.forEach(msg => { - msg.severity = this.parseMessagesSeverity(msg.type); + msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.mypyCategorySeverity); msg.code = msg.type; }); diff --git a/src/client/linters/pep8Linter.ts b/src/client/linters/pep8Linter.ts index 18592b544d52..d403dd117feb 100644 --- a/src/client/linters/pep8Linter.ts +++ b/src/client/linters/pep8Linter.ts @@ -10,19 +10,6 @@ export class Linter extends baseLinter.BaseLinter { super('pep8', Product.pep8, outputChannel, workspaceRootPath); } - private parseMessagesCodeSeverity(error: string): baseLinter.LintMessageSeverity { - - let category_letter = error[0]; - switch (category_letter) { - case 'E': - return baseLinter.LintMessageSeverity.Error; - case 'W': - return baseLinter.LintMessageSeverity.Warning; - default: - return baseLinter.LintMessageSeverity.Information; - } - } - public isEnabled(): Boolean { return this.pythonSettings.linting.pep8Enabled; } @@ -34,9 +21,9 @@ export class Linter extends baseLinter.BaseLinter { let pep8Path = this.pythonSettings.linting.pep8Path; let pep8Args = Array.isArray(this.pythonSettings.linting.pep8Args) ? this.pythonSettings.linting.pep8Args : []; return new Promise(resolve => { - this.run(pep8Path, pep8Args.concat(['--format=%(row)d,%(col)d,%(code)s,%(code)s:%(text)s', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => { + this.run(pep8Path, pep8Args.concat(['--format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => { messages.forEach(msg => { - msg.severity = this.parseMessagesCodeSeverity(msg.type); + msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.pep8CategorySeverity); }); resolve(messages); diff --git a/src/client/linters/pylint.ts b/src/client/linters/pylint.ts index ac72e7ace1cc..7af9eef7f68e 100644 --- a/src/client/linters/pylint.ts +++ b/src/client/linters/pylint.ts @@ -10,29 +10,6 @@ export class Linter extends baseLinter.BaseLinter { super('pylint', Product.pylint, outputChannel, workspaceRootPath); } - private parseMessagesSeverity(category: string): baseLinter.LintMessageSeverity { - if (this.pythonSettings.linting.pylintCategorySeverity[category]) { - let severityName = this.pythonSettings.linting.pylintCategorySeverity[category]; - switch (severityName) { - case 'Error': - return baseLinter.LintMessageSeverity.Error; - case 'Hint': - return baseLinter.LintMessageSeverity.Hint; - case 'Information': - return baseLinter.LintMessageSeverity.Information; - case 'Warning': - return baseLinter.LintMessageSeverity.Warning; - default: { - if (baseLinter.LintMessageSeverity[severityName]) { - return baseLinter.LintMessageSeverity[severityName]; - } - } - } - } - - return baseLinter.LintMessageSeverity.Information; - } - public isEnabled(): Boolean { return this.pythonSettings.linting.pylintEnabled; } @@ -46,7 +23,7 @@ export class Linter extends baseLinter.BaseLinter { return new Promise((resolve, reject) => { this.run(pylintPath, pylintArgs.concat(['--msg-template=\'{line},{column},{category},{msg_id}:{msg}\'', '--reports=n', '--output-format=text', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => { messages.forEach(msg => { - msg.severity = this.parseMessagesSeverity(msg.type); + msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.pylintCategorySeverity); }); resolve(messages); diff --git a/src/test/pythonFiles/sorting/withconfig/before.py b/src/test/pythonFiles/sorting/withconfig/before.py index 5f180136e025..e1fd315dbf92 100644 --- a/src/test/pythonFiles/sorting/withconfig/before.py +++ b/src/test/pythonFiles/sorting/withconfig/before.py @@ -1,10 +1,3 @@ -from third_party import lib0 -from third_party import lib1 -from third_party import lib2 -from third_party import lib3 -from third_party import lib4 -from third_party import lib5 -from third_party import lib6 -from third_party import lib7 -from third_party import lib8 -from third_party import lib9 +from third_party import (lib1, lib2, lib3, + lib4, lib5, lib6, + lib7, lib8, lib9) \ No newline at end of file