π OpenHands: AI-Driven Development
APP-1362 Remove V0 linter Package (#14055)
Tim O'Farrelle0a4c35c9c12
diff --git a/openhands/linter/__init__.py b/openhands/linter/__init__.pydeleted file mode 100644index dc0c91ba4a..0000000000--- a/openhands/linter/__init__.py+++ /dev/null@@ -1,11 +0,0 @@-"""Linter module for OpenHands.--Part of this Linter module is adapted from Aider (Apache 2.0 License, [original-code](https://github.com/paul-gauthier/aider/blob/main/aider/linter.py)).-- Please see the [original repository](https://github.com/paul-gauthier/aider) for more information.-- The detailed implementation of the linter can be found at: https://github.com/OpenHands/openhands-aci.-"""--from openhands_aci.linter import DefaultLinter, LintResult--__all__ = ['DefaultLinter', 'LintResult']diff --git a/openhands/runtime/plugins/agent_skills/file_ops/file_ops.py b/openhands/runtime/plugins/agent_skills/file_ops/file_ops.pyindex c8d3a75eeb..d24063bf12 100644--- a/openhands/runtime/plugins/agent_skills/file_ops/file_ops.py+++ b/openhands/runtime/plugins/agent_skills/file_ops/file_ops.py@@ -26,8 +26,6 @@ Note:import os-from openhands.linter import DefaultLinter, LintResult-CURRENT_FILE: str | None = NoneCURRENT_LINE = 1WINDOW = 100@@ -92,32 +90,6 @@ def _clamp(value: int, min_value: int, max_value: int) -> int:return max(min_value, min(value, max_value))-def _lint_file(file_path: str) -> tuple[str | None, int | None]:- """Perform linting on a file and identify the first error location.-- Lint the file at the given path and return a tuple with a boolean indicating if there are errors,- and the line number of the first error, if any.-- Args:- file_path: str: The path to the file to lint.-- Returns:- A tuple containing:- - The lint error message if found, None otherwise- - The line number of the first error, None if no errors- """- linter = DefaultLinter()- lint_error: list[LintResult] = linter.lint(file_path)- if not lint_error:- # Linting successful. No issues found.- return None, None- first_error_line = lint_error[0].line if len(lint_error) > 0 else None- error_text = 'ERRORS:\n' + '\n'.join(- [f'{file_path}:{err.line}:{err.column}: {err.message}' for err in lint_error]- )- return error_text, first_error_line--def _print_window(file_path: str | None,targeted_line: int,diff --git a/openhands/runtime/utils/edit.py b/openhands/runtime/utils/edit.pyindex 3014811fb2..6dc8a638ef 100644--- a/openhands/runtime/utils/edit.py+++ b/openhands/runtime/utils/edit.py@@ -5,9 +5,7 @@# - V1 application server (in this repo): openhands/app_server/# Unless you are working on deprecation, please avoid extending this legacy file and consult the V1 codepaths above.# Tag: Legacy-V0-import osimport re-import tempfilefrom abc import ABC, abstractmethodfrom typing import Any@@ -28,7 +26,6 @@ from openhands.events.observation import (FileWriteObservation,Observation,)-from openhands.linter import DefaultLinterfrom openhands.llm.llm import LLMfrom openhands.llm.llm_registry import LLMRegistryfrom openhands.utils.chunk_localizer import Chunk, get_top_k_chunk_matches@@ -187,63 +184,6 @@ class FileEditRuntimeMixin(FileEditRuntimeInterface):)return None- def _get_lint_error(- self,- suffix: str,- old_content: str,- new_content: str,- filepath: str,- diff: str,- ) -> ErrorObservation | None:- linter = DefaultLinter()- # Copy the original file to a temporary file (with the same ext) and lint it- with (- tempfile.NamedTemporaryFile(- suffix=suffix, mode='w+', encoding='utf-8'- ) as original_file_copy,- tempfile.NamedTemporaryFile(- suffix=suffix, mode='w+', encoding='utf-8'- ) as updated_file_copy,- ):- # Lint the original file- original_file_copy.write(old_content)- original_file_copy.flush()-- # Lint the updated file- updated_file_copy.write(new_content)- updated_file_copy.flush()-- updated_lint_error = linter.lint_file_diff(- original_file_copy.name, updated_file_copy.name- )-- if len(updated_lint_error) > 0:- _obs = FileEditObservation(- content=diff,- path=filepath,- prev_exist=True,- old_content=old_content,- new_content=new_content,- )- error_message = (- (- f'\n[Linting failed for edited file {filepath}. {len(updated_lint_error)} lint errors found.]\n'- '[begin attempted changes]\n'- f'{_obs.visualize_diff(change_applied=False)}\n'- '[end attempted changes]\n'- )- + '-' * 40- + '\n'- )- error_message += '-' * 20 + 'First 5 lint errors' + '-' * 20 + '\n'- for i, lint_error in enumerate(updated_lint_error[:5]):- error_message += f'[begin lint error {i}]\n'- error_message += lint_error.visualize().strip() + '\n'- error_message += f'[end lint error {i}]\n'- error_message += '-' * 40 + '\n'- return ErrorObservation(error_message)- return None-def llm_based_edit(self, action: FileEditAction, retry_num: int = 0) -> Observation:obs = self.read(FileReadAction(path=action.path))if (@@ -289,27 +229,6 @@ class FileEditRuntimeMixin(FileEditRuntimeInterface):if start == -1:updated_content = '\n'.join(old_file_lines + action.content.split('\n'))diff = get_diff(original_file_content, updated_content, action.path)- # Lint the updated content- if self.config.sandbox.enable_auto_lint:- suffix = os.path.splitext(action.path)[1]-- error_obs = self._get_lint_error(- suffix,- original_file_content,- updated_content,- action.path,- diff,- )- if error_obs is not None:- self.write(- FileWriteAction(path=action.path, content=updated_content)- )- return self.correct_edit(- file_content=updated_content,- error_obs=error_obs,- retry_num=retry_num,- )-obs = self.write(FileWriteAction(path=action.path, content=updated_content))return FileEditObservation(content=diff,@@ -381,21 +300,6 @@ class FileEditRuntimeMixin(FileEditRuntimeInterface):updated_content = '\n'.join(updated_lines)diff = get_diff(original_file_content, updated_content, action.path)- # Lint the updated content- if self.config.sandbox.enable_auto_lint:- suffix = os.path.splitext(action.path)[1]- error_obs = self._get_lint_error(- suffix, original_file_content, updated_content, action.path, diff- )- if error_obs is not None:- error_obs.llm_metrics = self.draft_editor_llm.metrics- self.write(FileWriteAction(path=action.path, content=updated_content))- return self.correct_edit(- file_content=updated_content,- error_obs=error_obs,- retry_num=retry_num,- )-obs = self.write(FileWriteAction(path=action.path, content=updated_content))ret_obs = FileEditObservation(content=diff,