From 91676ab955a0dd86ffe8abe7395afec94399ae5d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Sep 2025 06:44:05 +0000 Subject: [PATCH 1/2] build(deps-dev): bump tree-sitter from 0.24.0 to 0.25.1 Bumps [tree-sitter](https://github.com/tree-sitter/py-tree-sitter) from 0.24.0 to 0.25.1. - [Release notes](https://github.com/tree-sitter/py-tree-sitter/releases) - [Commits](https://github.com/tree-sitter/py-tree-sitter/compare/v0.24.0...v0.25.1) --- updated-dependencies: - dependency-name: tree-sitter dependency-version: 0.25.1 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", ] From b838edcc3a67d9a03bdf18dfdd1effab1b982b68 Mon Sep 17 00:00:00 2001 From: Benjamin Bannier Date: Tue, 26 Aug 2025 08:54:16 +0200 Subject: [PATCH 2/2] Do not attempt to format code with errors Our current approach is not stable against changes to the exact error recovery strategy employed by tree-sitter. Instead of trying to make this work instead just give up when we encounter parse errors. --- tests/test_formatting.py | 29 ++++++++++++++--------------- zeekscript/cli.py | 6 +++++- 2 files changed, 19 insertions(+), 16 deletions(-) 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)