This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlinter.ts
100 lines (90 loc) · 3.58 KB
/
linter.ts
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
// Copyright 2022
// Carlos Alberto Ruiz Naranjo [[email protected]]
// Ismael Perez Rojo [[email protected] ]
//
// This file is part of colibri2
//
// Colibri is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Colibri is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with colibri2. If not, see <https://www.gnu.org/licenses/>.
import { Ghdl } from "./ghdl";
import { Icarus } from "./icarus";
import { Verilator } from "./verilator";
import { Vivado } from "./vivado";
import { Modelsim } from "./modelsim";
import { Verible } from "./verible";
import * as common from "./common";
import * as cfg from "../config/config_declaration";
import { t_file } from "../project_manager/common";
/** Linter */
export class Linter {
private get_linter(linter_name: common.t_linter_name) {
if (linter_name === cfg.e_linter_general_linter_vhdl.ghdl) {
return new Ghdl();
}
else if (linter_name === cfg.e_linter_general_linter_vhdl.vivado) {
return new Vivado();
}
else if (linter_name === cfg.e_linter_general_linter_vhdl.modelsim) {
return new Modelsim();
}
else if (linter_name === cfg.e_linter_general_linter_verilog.icarus) {
return new Icarus();
}
else if (linter_name === cfg.e_linter_general_linter_verilog.modelsim) {
return new Modelsim();
}
else if (linter_name === cfg.e_linter_general_linter_verilog.verilator) {
return new Verilator();
}
else if (linter_name === cfg.e_linter_general_linter_verilog.vivado) {
return new Vivado();
}
else if (linter_name === cfg.e_linter_general_lstyle_verilog.verible) {
return new Verible();
}
else {
return new Ghdl();
}
}
parse_output(linter_name: common.t_linter_name, output: string, file: string) {
const linter = this.get_linter(linter_name);
const errors = linter.parse_output(output, file);
return errors;
}
/**
* Lint a file from path
* @param {string} file File path to lint
* @param {common.l_options} options Linter options
*/
async lint_from_file(linter_name: common.t_linter_name, file: string, options: common.l_options) {
const linter = this.get_linter(linter_name);
const errors = await linter.lint_from_file(file, options);
return errors;
}
/**
* Lint a file from the code
* @param {string} code Code to lint
* @param {common.l_options} options Linter options
*/
async lint_from_code(linter_name: common.t_linter_name, code: string, options: common.l_options) {
const linter = this.get_linter(linter_name);
const errors = await linter.lint_from_code(code, options);
return errors;
}
async lint_from_project(file_path: string, prj_file_list: t_file[],
linter_name: common.t_linter_name, options: common.l_options): Promise<common.l_error[]> {
const linter = this.get_linter(linter_name);
const errors = await linter.lint_from_project(file_path, prj_file_list, options);
return errors;
}
}