Syntax gate
syntax_gate
Refuse syntax regressions in Python, TOML and JSON before writing.
The gate compares the file as it is on disk with the content the batch would write, both in memory, so a refusal happens before a single byte is written. It only guards against a regression: a file that did not parse before the batch is never blocked, so an edit repairing it stays possible. New Python and TOML files must parse; new JSON files are unchecked. JSON comments and trailing commas are tolerated. Data parser recursion limits produce no verdict and the content is considered parseable.
Python parsing uses :func:ast.parse of the running interpreter, which must
be at least as recent as the edited project's syntax.
syntax_regression(file_rel, before, after)
Report a batch turning a supported file into unparseable content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_rel
|
str
|
Path of the file, relative to the batch root. |
required |
before
|
str | None
|
Current content, |
required |
after
|
str
|
Content the batch would write. |
required |
Returns:
| Type | Description |
|---|---|
ValidationError | None
|
A validation error naming the first syntax error of after, or |
ValidationError | None
|
|
ValidationError | None
|
or new files whose format policy skips checking. |