@@ -110,7 +110,7 @@ def fn_extract(origin_path, snippet_path, _language, first_line, last_line):
110110 raise UserError (f"Couldn't open '{ origin_path } ' or '{ snippet_path } '" )
111111
112112
113- def fn_check_syntax (origin_path , snippet_path , language , first_line , _last_line ):
113+ def fn_check_syntax (origin_path , snippet_path , language , first_line , _last_line , snippet_number ):
114114 snippet_abs_path = os .path .abspath (snippet_path )
115115
116116 if not os .path .exists (snippet_path ):
@@ -120,9 +120,9 @@ def fn_check_syntax(origin_path, snippet_path, language, first_line, _last_line)
120120
121121 match language :
122122 case "cf" :
123- r = lint_policy_file (snippet_abs_path )
123+ r = lint_policy_file (snippet_abs_path , origin_path , first_line + 1 , snippet_number )
124124 if r != 0 :
125- raise UserError (f"Error when checking '{ snippet_abs_path } '" )
125+ raise UserError (f"Error when checking '{ origin_path } '" )
126126 case "json" :
127127 try :
128128 with open (snippet_abs_path , "r" ) as f :
@@ -183,19 +183,34 @@ def fn_autoformat(_origin_path, snippet_path, language, _first_line, _last_line)
183183 except json .decoder .JSONDecodeError :
184184 raise UserError (f"Invalid json in '{ snippet_path } '" )
185185
186+ def _translate_language (x ):
187+ if x == "cf3" or x == "cfengine3" :
188+ return "cf"
189+ if x == "yaml" :
190+ return "yml"
191+ return x
192+
193+
194+ SUPPORTED_LANGUAGES = ["cf" , "cfengine3" , "cf3" , "json" , "yml" , "yaml" ]
186195
187196def _process_markdown_code_blocks (
188197 path , languages , extract , syntax_check , output_check , autoformat , replace , cleanup
189198):
190- supported_languages = {"cf3" : "cf" , "json" : "json" , "yaml" : "yml" }
191-
192199 if not os .path .exists (path ):
193200 raise UserError ("This path doesn't exist" )
194201
202+ languages = set (languages )
203+ if "cf3" in languages or "cf" in languages or "cfengine3" in languages :
204+ languages .add ("cf3" )
205+ languages .add ("cfengine3" )
206+ languages .add ("cf" )
207+ if "yaml" in languages or "yml" in languages :
208+ languages .add ("yml" )
209+ languages .add ("yaml" )
195210 for language in languages :
196- if language not in supported_languages :
211+ if language not in SUPPORTED_LANGUAGES :
197212 raise UserError (
198- f"Unsupported language '{ language } '. The supported languages are: { ", " .join (supported_languages . keys () )} "
213+ f"Unsupported language '{ language } '. The supported languages are: { ", " .join (SUPPORTED_LANGUAGES )} "
199214 )
200215
201216 parsed_markdowns = get_markdown_files (path , languages )
@@ -211,8 +226,9 @@ def _process_markdown_code_blocks(
211226 cb ["first_line" ] += offset
212227 cb ["last_line" ] += offset
213228
214- language = supported_languages [code_block ["language" ]]
215- snippet_path = f"{ origin_path } .snippet-{ i + 1 } .{ language } "
229+ language = _translate_language (code_block ["language" ])
230+ snippet_number = i + 1
231+ snippet_path = f"{ origin_path } .snippet-{ snippet_number } .{ language } "
216232
217233 flags = code_block ["flags" ]
218234 if "noextract" in flags or "skip" in flags :
@@ -235,6 +251,7 @@ def _process_markdown_code_blocks(
235251 language ,
236252 code_block ["first_line" ],
237253 code_block ["last_line" ],
254+ snippet_number ,
238255 )
239256 except Exception as e :
240257 if cleanup :
@@ -332,7 +349,7 @@ def check_docs() -> int:
332349 cfengine dev docs-check"""
333350 _process_markdown_code_blocks (
334351 path = "." ,
335- languages = ["json" ],
352+ languages = ["json" , "cf3" ],
336353 extract = True ,
337354 syntax_check = True ,
338355 output_check = False ,
0 commit comments