|
16 | 16 | import markdown_it |
17 | 17 | from cfbs.pretty import pretty_file |
18 | 18 |
|
| 19 | +from cfengine_cli.lint import lint_policy_file |
19 | 20 | from cfengine_cli.utils import UserError |
20 | 21 |
|
21 | 22 |
|
@@ -119,25 +120,9 @@ def fn_check_syntax(origin_path, snippet_path, language, first_line, _last_line) |
119 | 120 |
|
120 | 121 | match language: |
121 | 122 | case "cf": |
122 | | - try: |
123 | | - p = subprocess.run( |
124 | | - ["/var/cfengine/bin/cf-promises", snippet_abs_path], |
125 | | - capture_output=True, |
126 | | - text=True, |
127 | | - ) |
128 | | - err = p.stderr |
129 | | - |
130 | | - if err: |
131 | | - err = err.replace(snippet_abs_path, f"{origin_path}:{first_line}") |
132 | | - print(err) |
133 | | - except OSError: |
134 | | - raise UserError(f"'{snippet_abs_path}' doesn't exist") |
135 | | - except ValueError: |
136 | | - raise UserError("Invalid subprocess arguments") |
137 | | - except subprocess.CalledProcessError: |
138 | | - raise UserError(f"Couldn't run cf-promises on '{snippet_abs_path}'") |
139 | | - except subprocess.TimeoutExpired: |
140 | | - raise UserError("Timed out") |
| 123 | + r = lint_policy_file(snippet_abs_path) |
| 124 | + if r != 0: |
| 125 | + raise UserError(f"Error when checking '{snippet_abs_path}'") |
141 | 126 | case "json": |
142 | 127 | try: |
143 | 128 | with open(snippet_abs_path, "r") as f: |
@@ -207,14 +192,6 @@ def _process_markdown_code_blocks( |
207 | 192 | if not os.path.exists(path): |
208 | 193 | raise UserError("This path doesn't exist") |
209 | 194 |
|
210 | | - # TODO: Switch to tree-sitter parser here: |
211 | | - if ( |
212 | | - syntax_check |
213 | | - and "cf3" in languages |
214 | | - and not which("/var/cfengine/bin/cf-promises") |
215 | | - ): |
216 | | - raise UserError("cf-promises is not installed") |
217 | | - |
218 | 195 | for language in languages: |
219 | 196 | if language not in supported_languages: |
220 | 197 | raise UserError( |
|
0 commit comments