Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/client/linters/baseLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface ILintMessage {
code: string;
message: string;
type: string;
possibleWord?: string;
severity?: LintMessageSeverity;
provider: string;
}
Expand Down Expand Up @@ -53,6 +52,7 @@ export abstract class BaseLinter {
private installer: Installer;
protected pythonSettings: settings.IPythonSettings;
private _workspaceRootPath: string;
protected _columnOffset = 0;
protected get workspaceRootPath(): string {
return typeof this._workspaceRootPath === 'string' ? this._workspaceRootPath : vscode.workspace.rootPath;
}
Expand Down Expand Up @@ -84,24 +84,11 @@ export abstract class BaseLinter {
match.line = Number(<any>match.line);
match.column = Number(<any>match.column);

let possibleWord: string;
if (!isNaN(match.column)) {
let sourceLine = document.lineAt(match.line - 1).text;
let sourceStart = sourceLine.substring(match.column - 1);

// try to get the first word from the startig position
let possibleProblemWords = sourceStart.match(/\w+/g);
if (possibleProblemWords != null && possibleProblemWords.length > 0 && sourceStart.startsWith(possibleProblemWords[0])) {
possibleWord = possibleProblemWords[0];
}
}

diagnostics.push({
code: match.code,
message: match.message,
column: isNaN(match.column) || match.column === 0 ? 0 : match.column - 1,
column: isNaN(match.column) || match.column === 0 ? 0 : match.column - this._columnOffset,
line: match.line,
possibleWord: possibleWord,
type: match.type,
provider: this.Id
});
Expand Down
2 changes: 2 additions & 0 deletions src/client/linters/flake8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Product } from '../common/installer';
import { TextDocument, CancellationToken } from 'vscode';

export class Linter extends baseLinter.BaseLinter {
_columnOffset = 1;

constructor(outputChannel: OutputChannel, workspaceRootPath?: string) {
super('flake8', Product.flake8, outputChannel, workspaceRootPath);
}
Expand Down
2 changes: 2 additions & 0 deletions src/client/linters/pep8Linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Product } from '../common/installer';
import { TextDocument, CancellationToken } from 'vscode';

export class Linter extends baseLinter.BaseLinter {
_columnOffset = 1;

constructor(outputChannel: OutputChannel, workspaceRootPath?: string) {
super('pep8', Product.pep8, outputChannel, workspaceRootPath);
}
Expand Down
10 changes: 0 additions & 10 deletions src/client/linters/prospector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,12 @@ export class Linter extends baseLinter.BaseLinter {
parsedData.messages.filter((value, index) => index <= this.pythonSettings.linting.maxNumberOfProblems).forEach(msg => {

let lineNumber = msg.location.line === null || isNaN(msg.location.line) ? 1 : msg.location.line;
let sourceLine = document.lineAt(lineNumber - 1).text;
let sourceStart = sourceLine.substring(msg.location.character);

// try to get the first word from the starting position
let possibleProblemWords = sourceStart.match(/\w+/g);
let possibleWord: string;
if (possibleProblemWords != null && possibleProblemWords.length > 0 && sourceStart.startsWith(possibleProblemWords[0])) {
possibleWord = possibleProblemWords[0];
}

diagnostics.push({
code: msg.code,
message: msg.message,
column: msg.location.character,
line: lineNumber,
possibleWord: possibleWord,
type: msg.code,
provider: `${this.Id} - ${msg.source}`
});
Expand Down
2 changes: 2 additions & 0 deletions src/client/linters/pylama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { TextDocument, CancellationToken } from 'vscode';
const REGEX = '(?<file>.py):(?<line>\\d+):(?<column>\\d+): \\[(?<type>\\w+)\\] (?<code>\\w\\d+):? (?<message>.*)\\r?(\\n|$)';

export class Linter extends baseLinter.BaseLinter {
_columnOffset = 1;

constructor(outputChannel: OutputChannel, workspaceRootPath?: string) {
super('pylama', Product.pylama, outputChannel, workspaceRootPath);
}
Expand Down
10 changes: 2 additions & 8 deletions src/client/providers/lintProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ lintSeverityToVSSeverity.set(linter.LintMessageSeverity.Information, vscode.Diag
lintSeverityToVSSeverity.set(linter.LintMessageSeverity.Warning, vscode.DiagnosticSeverity.Warning);

function createDiagnostics(message: linter.ILintMessage, document: vscode.TextDocument): vscode.Diagnostic {
let endCol = document.lineAt(message.line - 1).text.length;

// try to get the first word from the startig position
if (message.possibleWord === 'string' && message.possibleWord.length > 0) {
endCol = message.column + message.possibleWord.length;
}

let range = new vscode.Range(new vscode.Position(message.line - 1, message.column), new vscode.Position(message.line - 1, endCol));
let position = new vscode.Position(message.line - 1, message.column);
let range = new vscode.Range(position, position);

let severity = lintSeverityToVSSeverity.get(message.severity);
let diagnostic = new vscode.Diagnostic(range, message.code + ':' + message.message, severity);
Expand Down
Loading