All files / src/linters lizard.ts

94.73% Statements 18/19
71.42% Branches 5/7
75% Functions 3/4
94.73% Lines 18/19

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          7x   7x 7x   7x   6x 6x   6x 6x       2x       2x   2x       6x   6x   6x   1x     5x 4x                   1x                          
// Copyright (c) 2017-2022 The VSCode C/C++ Flylint Authors
//
// SPDX-License-Identifier: MIT
 
import { Settings } from '../settings';
import { Linter } from './linter';
import { InternalDiagnostic } from '../server';
import { path as sysPath } from '../utils';
import { DiagnosticSeverity } from 'vscode-languageserver/node';
 
export class Lizard extends Linter {
    constructor(settings: Settings, workspaceRoot: string) {
        super('Lizard', settings, workspaceRoot, false);
        this.cascadeCommonSettings('lizard');
 
        this.setExecutable(settings.lizard.executable);
        this.active = this.enabled = settings.lizard.enable;
    }
 
    protected buildCommandLine(fileName: string, _tmpFileName: string): string[] {
        let args = [this.executable]
            .concat(['--warnings_only'])
            .concat((this.settings.lizard.extraArgs || []).map(a => this.expandVariables(a).result || a));
 
        args.push(sysPath(fileName));
 
        return args;
    }
 
    protected parseLine(line: string): InternalDiagnostic | null {
        let regex = /^([a-zA-Z]?:?[^:]+):(\d+)?:? warning: (.+)$/;
        let regexArray: RegExpExecArray | null;
        let excludeRegex = /^$/;
 
        if (excludeRegex.exec(line) !== null) {
            // skip this line
            return null;
        }
 
        if ((regexArray = regex.exec(line)) !== null) {
            return {
                fileName: regexArray[1],
                line: parseInt(regexArray[2]) - 1,
                column: 0,
                severity: DiagnosticSeverity.Warning,
                code: 'Cyclomatic complexity',
                message: regexArray[3],
                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
            };
        }
    }
}