Skip to content

Commit

Permalink
Count errors on the root node too
Browse files Browse the repository at this point in the history
Fixes #377
  • Loading branch information
Wilfred committed Mar 3, 2023
1 parent 045d6a2 commit 2d1a2c9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ parenthesis heuristics.

### Parsing

Fixed an issue where parse errors were undercounted, particularly in
YAML files.

Improved parsing for Makefiles.

## 0.44 (released 2nd March 2023)
Expand Down
5 changes: 5 additions & 0 deletions sample_files/cli_tests/bad_yaml_after.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
key1:
- key2:
{{ helm-expression }}

new_key: yes
3 changes: 3 additions & 0 deletions sample_files/cli_tests/bad_yaml_before.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
key1:
- key2:
{{ helm-expression }}
6 changes: 5 additions & 1 deletion src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,11 +1240,15 @@ pub fn to_syntax<'a>(
let nl_pos = NewlinePositions::from(src);
let mut cursor = tree.walk();

let mut error_count: usize = 0;
if cursor.node().is_error() {
error_count += 1;
}

// The tree always has a single root, whereas we want nodes for
// each top level syntax item.
cursor.goto_first_child();

let mut error_count: usize = 0;
let nodes = all_syntaxes_from_cursor(
arena,
src,
Expand Down
13 changes: 13 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,16 @@ fn makefile_text_as_atom() {
let predicate_fn = predicate::str::contains("CCFLAGS");
cmd.assert().stdout(predicate_fn);
}

#[test]
fn yaml_parse_errors() {
use predicates::prelude::*;

let mut cmd = Command::cargo_bin("difft").unwrap();

cmd.arg("sample_files/cli_tests/bad_yaml_before.yml")
.arg("sample_files/cli_tests/bad_yaml_after.yml");

let predicate_fn = predicate::str::contains("exceeded DFT_PARSE_ERROR_LIMIT");
cmd.assert().stdout(predicate_fn);
}

0 comments on commit 2d1a2c9

Please sign in to comment.