Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | 7x 7x 7x 7x 7x 7x 7x 9x 9x 9x 9x 9x 9x 2x 2x 1x 1x 1x 7x 2x 2x 44x 44x 44x 10x 34x 51x 9x 3x 3x 3x 6x 6x 6x 9x 24x 24x 24x 24x 24x 1x 33x 33x 1x 33x 33x 33x | // Copyright (c) 2017-2022 The VSCode C/C++ Flylint Authors
//
// SPDX-License-Identifier: MIT
import * as path from 'path';
import * as _ from 'lodash';
import { PclintPlusSeverityMaps, Settings, VS_DiagnosticSeverity } from '../settings';
import { headerExts, Linter } from './linter';
import { InternalDiagnostic } from '../server';
import { path as sysPath } from '../utils';
import { DiagnosticSeverity } from 'vscode-languageserver/node';
type ParseData = {
fileName: string,
line: string,
column: string,
};
export class PclintPlus extends Linter {
private lastParse: ParseData = <ParseData>{};
constructor(settings: Settings, workspaceRoot: string) {
super('PclintPlus', settings, workspaceRoot, true);
this.cascadeCommonSettings('pclintplus');
this.setExecutable(settings.pclintplus.executable);
this.setConfigFile(settings.pclintplus.configFile);
this.active = this.enabled = settings.pclintplus.enable;
}
protected buildCommandLine(fileName: string, _tmpFileName: string): string[] {
let args = [
this.executable,
this.configFile,
'-v', // turn off verbosity
'-b', // suppress banner output
'-format=%f %l %c %t %n: %m', // format of diagnostic
'-h1', // height of diagnostics message
'-width(0,0)', // width of a line, and continuation indent
'-zero(400)', // exit zero if no warnings at level >= 400
];
if (headerExts.indexOf(path.extname(fileName)) !== -1) {
let hArgs = this.settings.pclintplus.headerArgs;
Iif (typeof hArgs === 'string') {
args.push(hArgs);
} else {
hArgs.forEach(element => {
args.push(element);
});
}
}
args.push(sysPath(fileName));
return args;
}
protected parseLine(line: string): InternalDiagnostic | null {
let regex = /^(([^ ]+)?\s\s([0-9]+)\s([0-9]+\s)?\s([iI]nfo|[wW]arning|[eE]rror|[nN]ote|[sS]upplemental)\s([0-9]+):\s(.*)|(.+?):([0-9]+):([0-9]+:)?\s([iI]nfo|[wW]arning|[eE]rror|[nN]ote|[sS]upplemental)\s([0-9]+):\s(.*))$/;
let regexArray: RegExpExecArray | null;
let excludeRegex = /^(\s+file '.*'|PC-lint.*|licensed.*|LICENSED.*|.*evaluation license.*|[^ \t]+|)$/;
if (excludeRegex.exec(line) !== null) {
// skip this line
return null;
}
if ((regexArray = regex.exec(line)) !== null) {
if (_.every([regexArray[3], regexArray[4], regexArray[5]], el => el !== undefined)) {
if (_.isUndefined(regexArray[2])) {
regexArray[2] = this.lastParse.fileName;
regexArray[3] = this.lastParse.line;
regexArray[4] = this.lastParse.column;
} else {
this.lastParse.fileName = regexArray[2];
this.lastParse.line = regexArray[3];
this.lastParse.column = regexArray[4];
}
return {
fileName: regexArray[2],
line: parseInt(regexArray[3]) - 1,
column: 0,
severity: this.getSeverityCode(regexArray[5].toLowerCase()),
code: regexArray[6],
message: regexArray[7],
source: this.name,
};
} else {
Iif (_.isUndefined(regexArray[8])) {
regexArray[8] = this.lastParse.fileName;
regexArray[9] = this.lastParse.line;
regexArray[10] = this.lastParse.column;
} else {
this.lastParse.fileName = regexArray[8];
this.lastParse.line = regexArray[9];
this.lastParse.column = regexArray[10];
}
return {
fileName: regexArray[8],
line: parseInt(regexArray[9]) - 1,
column: 0,
severity: this.getSeverityCode(regexArray[11].toLowerCase()),
code: regexArray[12],
message: regexArray[13],
source: this.name,
};
}
} else {
return {
parseError: 'Line could not be parsed: ' + line,
fileName: '',
line: 0,
column: 0,
severity: DiagnosticSeverity.Error,
code: 0,
message: '',
source: this.name
};
}
}
protected transformParse(currentParsed: InternalDiagnostic | null, parsed: InternalDiagnostic | null) {
if (parsed) {
// Skip over successful completion messages...
if (parsed['code'] === '900') {
parsed = null;
}
}
return { currentParsed: currentParsed, parsed: parsed };
}
private getSeverityCode(severity: string): DiagnosticSeverity {
let output = this.settings.pclintplus.severityLevels[severity as keyof PclintPlusSeverityMaps];
return VS_DiagnosticSeverity.from(output);
}
}
|