Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ requires-python = ">= 3.10"

dependencies = [
"argcomplete>=3.6.1",
"tree-sitter==0.24.0",
"tree-sitter==0.25.2",
"tree-sitter-zeek==0.2.9",
]

Expand Down
29 changes: 14 additions & 15 deletions tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,26 +169,25 @@ def test_mid_error(self):
)

def test_mid_record_error(self):
self.assertFormatting(
"""type foo: record {
_, error = self._format(
tu.normalize(
"""type foo: record {
a: count; ##< A field
b count; ##< A broken field
c: count; ##< Another field, better not skipped!
d: count; ##< Ditto.
};
""",
"""type foo: record {
a: count; ##< A field
b count; ##< A broken field
c : count; ##< Another field, better not skipped!
d: count; ##< Ditto.
};
""",
(
"\tb count; ##< A broken field",
2,
'cannot parse line 2, col 3: "count; ##< A broken field\n\tc"',
),
"""
)
)

# TODO(bbannier): The way we currently format this is not idempotent,
# so only check that we return the expected error. This is okay since
# we do not format files with errors anyway.
assert error == (
"type foo: record {",
0,
'cannot parse line 0, col 10: "record {\n\ta: count; ##< A field\n\tb"',
)

def test_single_char_mid_error(self):
Expand Down
6 changes: 5 additions & 1 deletion zeekscript/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)


def cmd_format(args: argparse.Namespace) -> int:
def cmd_format(args: argparse.Namespace) -> int: # noqa: PLR0911
"""This function implements Zeek script formatting for the command line.

It determines input and output streams, parses each input into a Script
Expand Down Expand Up @@ -85,6 +85,10 @@ def do_write(source: bytes) -> None:
print_error(f"{fname}: {msg}")
else:
print_error(msg)

# Do not attempt to format code with errors.
do_write(script.source)
return 1
except Error as err:
print_error("parsing error: " + str(err))
do_write(script.source)
Expand Down
Loading