66import sys
77from pathlib import Path
88
9- from .diagnostics import Severity
9+ from .diagnostics import Diagnostic , Severity
1010from .sarif import build_sarif_run
1111from .validator import PineScriptValidator
1212
@@ -25,6 +25,30 @@ def build_parser() -> argparse.ArgumentParser:
2525 action = "store_true" ,
2626 help = "Print SARIF output for CI, code scanning, and machine-readable review tooling." ,
2727 )
28+ parser .add_argument (
29+ "--errors" ,
30+ action = argparse .BooleanOptionalAction ,
31+ default = True ,
32+ help = "Include or exclude error diagnostics." ,
33+ )
34+ parser .add_argument (
35+ "--warnings" ,
36+ action = argparse .BooleanOptionalAction ,
37+ default = True ,
38+ help = "Include or exclude warning diagnostics." ,
39+ )
40+ parser .add_argument (
41+ "--information" ,
42+ action = argparse .BooleanOptionalAction ,
43+ default = True ,
44+ help = "Include or exclude information diagnostics." ,
45+ )
46+ parser .add_argument (
47+ "--hints" ,
48+ action = argparse .BooleanOptionalAction ,
49+ default = True ,
50+ help = "Include or exclude hint diagnostics." ,
51+ )
2852 return parser
2953
3054
@@ -64,6 +88,33 @@ def _validate_file_targets(validator: PineScriptValidator, paths: list[Path]) ->
6488 return results
6589
6690
91+ def _selected_severities (args : argparse .Namespace ) -> set [Severity ]:
92+ selected : set [Severity ] = set ()
93+ if args .errors :
94+ selected .add (Severity .ERROR )
95+ if args .warnings :
96+ selected .add (Severity .WARNING )
97+ if args .information :
98+ selected .add (Severity .INFORMATION )
99+ if args .hints :
100+ selected .add (Severity .HINT )
101+ return selected
102+
103+
104+ def _filter_results (results : list [dict [str , object ]], selected : set [Severity ]) -> list [dict [str , object ]]:
105+ filtered : list [dict [str , object ]] = []
106+ for item in results :
107+ diagnostics = [diagnostic for diagnostic in item ["diagnostics" ] if diagnostic .severity in selected ]
108+ filtered .append (
109+ {
110+ "path" : item ["path" ],
111+ "text" : item ["text" ],
112+ "diagnostics" : diagnostics ,
113+ }
114+ )
115+ return filtered
116+
117+
67118def _summary (results : list [dict [str , object ]]) -> dict [str , int ]:
68119 diagnostics = [diagnostic for item in results for diagnostic in item ["diagnostics" ]]
69120 return {
@@ -81,6 +132,9 @@ def main(argv: list[str] | None = None) -> int:
81132 validator = PineScriptValidator ()
82133 if sum (1 for flag in (args .json , args .agent_json , args .sarif ) if flag ) > 1 :
83134 raise SystemExit ("Choose only one of --json, --agent-json, or --sarif." )
135+ selected_severities = _selected_severities (args )
136+ if not selected_severities :
137+ raise SystemExit ("At least one diagnostic severity must remain enabled." )
84138
85139 if "-" in args .paths :
86140 if len (args .paths ) != 1 :
@@ -94,9 +148,10 @@ def main(argv: list[str] | None = None) -> int:
94148 if not file_paths :
95149 raise SystemExit ("No .pine files matched the provided targets." )
96150 results = _validate_file_targets (validator , file_paths )
97- file_path = results [0 ]["path" ] if len (results ) == 1 else None
98- text = results [0 ]["text" ] if len (results ) == 1 else ""
99- diagnostics = results [0 ]["diagnostics" ] if len (results ) == 1 else []
151+ results = _filter_results (results , selected_severities )
152+ file_path = results [0 ]["path" ] if len (results ) == 1 else None
153+ text = results [0 ]["text" ] if len (results ) == 1 else ""
154+ diagnostics = results [0 ]["diagnostics" ] if len (results ) == 1 else []
100155
101156 if args .sarif :
102157 print (json .dumps (build_sarif_run (results ), ensure_ascii = False , indent = 2 ))
0 commit comments