diff --git a/pyproject.toml b/pyproject.toml index 56e5439..126aeff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", ] diff --git a/tests/test_formatting.py b/tests/test_formatting.py index c48f1fb..bef6a58 100755 --- a/tests/test_formatting.py +++ b/tests/test_formatting.py @@ -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): diff --git a/zeekscript/cli.py b/zeekscript/cli.py index 68407d0..407d38d 100644 --- a/zeekscript/cli.py +++ b/zeekscript/cli.py @@ -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 @@ -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)