From 0493680d571f41a2e478dd52437d8cbf24aab601 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 17 May 2024 14:00:42 -0700 Subject: [PATCH] aider: Update the linter to check for both 'ERROR' and 'MISSING' nodes. # Aider chat conversation: USER: is node.type 'ERROR" a standard across all tree sitter languages? ASSISTANT: The `node.type == 'ERROR'` check is specific to the Tree-sitter library and is used to identify syntax errors in the parsed code. This is a standard feature across all languages supported by Tree-sitter. Would you like to proceed with any changes or enhancements to the `aider/linter.py` file? If so, please specify the changes you need. USER: is MISSING ever used to indicate a parsing/syntax problem ASSISTANT: Yes, in Tree-sitter, `MISSING` is also used to indicate a parsing or syntax problem. Specifically, it indicates that a required element is missing in the syntax tree. Would you like to update the `aider/linter.py` file to also check for `MISSING` nodes? If so, I can provide the necessary changes. USER: yes ASSISTANT: To update the `aider/linter.py` file to also check for `MISSING` nodes, we need to modify the `traverse_tree` function. Here are the necessary changes: aider/linter.py ```python <<<<<<< SEARCH if node.type == 'ERROR': print(f"Syntax error at line: {node.start_point[0] + 1}") ======= if node.type == 'ERROR' or node.is_missing: error_type = 'Syntax error' if node.type == 'ERROR' else 'Missing element' print(f"{error_type} at line: {node.start_point[0] + 1}") >>>>>>> REPLACE ``` This change will ensure that the linter checks for both `ERROR` and `MISSING` nodes and reports them accordingly. --- aider/linter.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aider/linter.py b/aider/linter.py index 986a2a9a8..5506f30df 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -22,8 +22,9 @@ def parse_file_for_errors(file_path): # Traverse the tree to find errors def traverse_tree(node): - if node.type == 'ERROR': - print(f"Syntax error at line: {node.start_point[0] + 1}") + if node.type == 'ERROR' or node.is_missing: + error_type = 'Syntax error' if node.type == 'ERROR' else 'Missing element' + print(f"{error_type} at line: {node.start_point[0] + 1}") for child in node.children: traverse_tree(child)