@@ -52,20 +52,39 @@ def main(self):
52
52
lint_parser .add_argument ("--exclude" , nargs = "+" , type = str ,
53
53
help = "Comma-separated list of detector names to exclude" )
54
54
list_detectors = subparsers .add_parser ("detectors" , help = "List detectors" )
55
-
55
+ lint_parser .add_argument ("-A" , nargs = "+" , type = int ,
56
+ help = "Print A lines of trailing context after findings." )
57
+ lint_parser .add_argument ("-B" , nargs = "+" , type = int ,
58
+ help = "Print B lines of leading context before findings." )
59
+ lint_parser .add_argument ("-C" , nargs = "+" , type = int ,
60
+ help = "Print C lines of leading and trailing context after and before findings. Takes precedence over -A and -B" )
56
61
user_args = arg_parser .parse_args ()
57
62
if user_args .command == "lint" :
63
+
64
+ tc = 0
65
+ lc = 0
66
+
67
+ if user_args .A is not None :
68
+ tc = user_args .A [0 ]
69
+
70
+ if user_args .B is not None :
71
+ lc = user_args .B [0 ]
72
+
73
+ if user_args .C is not None :
74
+ tc = user_args .C [0 ]
75
+ lc = user_args .C [0 ]
76
+
58
77
filters = list (self .DETECTOR_MAP .keys ()) if user_args .filter is None else user_args .filter [0 ].split (',' )
59
78
excludes = [] if user_args .exclude is None else user_args .exclude [0 ].split (',' )
60
79
detectors = self .get_detectors (filters , excludes )
61
80
path = user_args .path
62
81
if path .endswith (".clar" ):
63
- self .lint_file (path , detectors , True )
82
+ self .lint_file (path , detectors , True , lc , tc )
64
83
else :
65
84
for root , _ , files in os .walk (path ):
66
85
for file in files :
67
86
if file .endswith (".clar" ):
68
- self .lint_file (os .path .join (root , file ), detectors , True )
87
+ self .lint_file (os .path .join (root , file ), detectors , True , lc , tc )
69
88
70
89
if user_args .command == "detectors" :
71
90
convert_camel_case = lambda s : s [0 ] + '' .join (' ' + c if c .isupper () else c for c in s [1 :])
@@ -103,7 +122,8 @@ def get_detectors(self, filters: str, excludes: str):
103
122
104
123
return [self .DETECTOR_MAP [name ] for name in filtered_names ]
105
124
106
- def lint_file (self , filename , lints : [Visitor ], print_output : bool ):
125
+ def lint_file (self , filename , lints : [Visitor ], print_output : bool , leading : int , trailing : int ):
126
+
107
127
if print_output :
108
128
if self .isatty :
109
129
print (f"{ TerminalColors .HEADER } ====== Linting { filename } ... ======{ TerminalColors .ENDC } " )
@@ -113,7 +133,7 @@ def lint_file(self, filename, lints: [Visitor], print_output: bool):
113
133
source = file .read ()
114
134
115
135
runner : LinterRunner = LinterRunner (source , print_output , filename )
116
- runner .add_lints (lints )
136
+ runner .add_lints (lints , leading , trailing )
117
137
118
138
findings : [Finding ] = runner .run ()
119
139
0 commit comments