@@ -109,8 +109,16 @@ def fn_extract(origin_path, snippet_path, _language, first_line, last_line):
109109 raise UserError (f"Couldn't open '{ origin_path } ' or '{ snippet_path } '" )
110110
111111
112+ def lint_json_file (snippet_abs_path , origin_path , snippet_number , first_line , prefix = None ):
113+ with open (snippet_abs_path , "r" ) as f :
114+ json .loads (f .read ())
115+ if prefix :
116+ print (prefix , end = "" )
117+ print (f"PASS: Snippet { snippet_number } at '{ origin_path } :{ first_line } ' (json)" )
118+ return 0
119+
112120def fn_check_syntax (
113- origin_path , snippet_path , language , first_line , _last_line , snippet_number
121+ origin_path , snippet_path , language , first_line , _last_line , snippet_number , prefix = None
114122):
115123 snippet_abs_path = os .path .abspath (snippet_path )
116124
@@ -122,14 +130,13 @@ def fn_check_syntax(
122130 match language :
123131 case "cf" :
124132 r = lint_policy_file (
125- snippet_abs_path , origin_path , first_line + 1 , snippet_number
133+ snippet_abs_path , origin_path , first_line + 1 , snippet_number , prefix
126134 )
127135 if r != 0 :
128136 raise UserError (f"Error when checking '{ origin_path } '" )
129137 case "json" :
130138 try :
131- with open (snippet_abs_path , "r" ) as f :
132- json .loads (f .read ())
139+ lint_json_file (snippet_abs_path , origin_path , snippet_number , first_line , prefix )
133140 except json .decoder .JSONDecodeError as e :
134141 raise UserError (f"Error when checking '{ snippet_abs_path } ': { str (e )} " )
135142 except Exception as e :
@@ -220,7 +227,12 @@ def _process_markdown_code_blocks(
220227
221228 parsed_markdowns = get_markdown_files (path , languages )
222229
223- for origin_path in parsed_markdowns ["files" ].keys ():
230+ origin_paths = sorted (parsed_markdowns ["files" ].keys ())
231+ origin_paths_len = len (origin_paths )
232+
233+ for origin_paths_i , origin_path in enumerate (origin_paths ):
234+ percentage = int (100 * (origin_paths_i + 1 )/ origin_paths_len )
235+ prefix = f"[{ origin_paths_i + 1 } /{ origin_paths_len } ({ percentage } %)] "
224236 offset = 0
225237 for i , code_block in enumerate (
226238 parsed_markdowns ["files" ][origin_path ]["code-blocks" ]
@@ -257,6 +269,7 @@ def _process_markdown_code_blocks(
257269 code_block ["first_line" ],
258270 code_block ["last_line" ],
259271 snippet_number ,
272+ prefix
260273 )
261274 except Exception as e :
262275 if cleanup :
0 commit comments