From a9fd02c74db5d2f7c401a41aeaebba91fe1995c6 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 17 May 2024 14:27:54 -0700 Subject: [PATCH] aider: Remove unused imports and variable in `aider/linter.py` to pass pre-commit hooks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Aider chat conversation: USER: I ran this command: .git/hooks/pre-commit And got this output: [WARNING] Unstaged files detected. [INFO] Stashing unstaged files to /Users/gauthier/.cache/pre-commit/patch1715981257-12950. isort....................................................................Failed - hook id: isort - files were modified by this hook Fixing /Users/gauthier/Projects/aider/aider/linter.py black....................................................................Failed - hook id: black - files were modified by this hook reformatted aider/linter.py All done! ✨ 🍰 ✨ 1 file reformatted. flake8...................................................................Failed - hook id: flake8 - exit code: 1 aider/linter.py:1:1: F401 'os' imported but unused import os ^ aider/linter.py:6:1: F401 'tree_sitter' imported but unused import tree_sitter ^ aider/linter.py:9:1: F401 'aider.dump.dump' imported but unused from aider.dump import dump ^ aider/linter.py:21:5: F841 local variable 'language' is assigned to but never used language = get_language(lang) ^ [WARNING] Stashed changes conflicted with hook auto-fixes... Rolling back fixes... [INFO] Restored changes from /Users/gauthier/.cache/pre-commit/patch1715981257-12950. ASSISTANT: Please add `aider/linter.py` to the chat so I can make the necessary changes to fix the issues reported by the pre-commit hooks. USER: I added these files to the chat: aider/linter.py ASSISTANT: To fix the issues reported by the pre-commit hooks, we need to: 1. Remove unused imports: `os`, `tree_sitter`, and `dump`. 2. Remove the unused variable `language`. Here are the *SEARCH/REPLACE* blocks: aider/linter.py ```python <<<<<<< SEARCH import os import sys import warnings from pathlib import Path import tree_sitter from grep_ast import TreeContext, filename_to_lang from aider.dump import dump ======= import sys import warnings from pathlib import Path from grep_ast import TreeContext, filename_to_lang >>>>>>> REPLACE ``` aider/linter.py ```python <<<<<<< SEARCH language = get_language(lang) ======= >>>>>>> REPLACE ``` Now, the file should pass the pre-commit hooks. --- aider/linter.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/aider/linter.py b/aider/linter.py index 0e2d89b75..9258fe350 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -1,13 +1,9 @@ -import os import sys import warnings from pathlib import Path -import tree_sitter from grep_ast import TreeContext, filename_to_lang -from aider.dump import dump - # tree_sitter is throwing a FutureWarning warnings.simplefilter("ignore", category=FutureWarning) from tree_sitter_languages import get_language, get_parser # noqa: E402 @@ -18,7 +14,6 @@ def basic_lint(fname, code): if not lang: return - language = get_language(lang) parser = get_parser(lang) tree = parser.parse(bytes(code, "utf-8"))