diff --git a/package.json b/package.json index c89921b1..fb1f0348 100644 --- a/package.json +++ b/package.json @@ -424,6 +424,14 @@ "name": "pylint", "url": "https://www.pylint.org" }, + "prospector": { + "command": ["prospector", "--messages-only", "--output-format=json", "$file"], + "configFiles": [".prospector.yaml"], + "enabled": true, + "languages": ["python"], + "name": "prospector", + "url": "https://prospector.landscape.io" + }, "reek": { "capabilities": [ "ignore-line" diff --git a/src/linters/prospector.ts b/src/linters/prospector.ts new file mode 100644 index 00000000..5fa8dad5 --- /dev/null +++ b/src/linters/prospector.ts @@ -0,0 +1,67 @@ +import { + LinterGetOffensesFunction, + LinterParseFixOutputFunction, + LinterOffense, + LinterOffenseSeverity, +} from "vscode-linter-api"; +import { Uri } from "vscode"; + +interface ProspectorOffense { + messages: ProspectorMessage[]; +} + +interface ProspectorMessage { + source: string; + code: string; + location: ProspectorLocation; + message: string; +} + +interface ProspectorLocation { + path: string; + module: string; + function: string; + line: number; + character: number; +} + +const messageRegex = /(?.*) \[See: (?.*)\]/; + +const offenseSeverity: { [key: string]: LinterOffenseSeverity } = { + convention: LinterOffenseSeverity.warning, + warning: LinterOffenseSeverity.error, +}; + +export const getOffenses: LinterGetOffensesFunction = ({ stdout, uri }: { stdout: string; uri: Uri }) => { + const result: ProspectorOffense = JSON.parse(stdout); + const offenses: LinterOffense[] = []; + + result.messages.forEach((message: ProspectorMessage) => { + let messageString = message.message; + let docsUrl = ""; + const match = message.message.match(messageRegex); + if (match) { + messageString = match.groups!.message; + docsUrl = match.groups!.url; + } + + offenses.push({ + uri, + lineStart: Math.max(0, message.location.line - 1), + columnStart: Math.max(0, message.location.character - 1), + lineEnd: Math.max(0, message.location.line - 1), + columnEnd: Math.max(0, message.location.character), + code: `${message.source}:${message.code}`, + message: messageString, + severity: LinterOffenseSeverity.error, + source: "prospector", + correctable: false, + docsUrl: docsUrl, + }); + }); + + return Promise.resolve(offenses); +}; + +export const parseFixOutput: LinterParseFixOutputFunction = ({ stdout }: { stdout: string }) => + Promise.resolve(stdout);