Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file_ops: Use tmp file for original linting #3681

Merged
merged 2 commits into from
Sep 2, 2024

Conversation

li-boxuan
Copy link
Collaborator

@li-boxuan li-boxuan commented Sep 1, 2024

Short description of the problem this fixes or functionality that this introduces. This may be used for the CHANGELOG

Fix a potential issue that might lead to file corruption when edit linting is enabled


Give a summary of what the PR does, explaining any non-trivial design decisions

#3124 introduces a feature for editing: running linter twice before and after the change and only extract new errors introduced by the agent. This has some potential issues and I am working on #3649 to address them, but I feel like I am not gonna finish it in the next few days, and that PR has become harder and harder to review, thus this PR, which only focuses on a small improvement.

So what's the issue? When we run linters on the original file before our edits, we need to copy the original file and use a temporary file to lint, because linting may have side-effect (e.g. modifying the file in-place). I used the word "may" because:

  1. Flake8 has no side-effect, so not a problem as of now.
  2. We don't enforce this or document this "no side-effect" as a requirement for linter implementation, so side-effect is allowed.

Regardless, the "after-edit-linting" uses the same approach: backup the file before linting to avoid data corruption. We should keep our "before-edit-linting" consistent.

Why no new unittest that reproduces the issue? Well, as I have mentioned earlier, flake8 has no side-effect, so technically it's not a bug but a flaw. Therefore, there's no way to write a test that reproduces the issue.

Copy link
Collaborator

@tobitege tobitege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! lgtm

Copy link
Collaborator

@tofarr tofarr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any linters that rely on relative paths between files that may be disrupted by this change?

@li-boxuan
Copy link
Collaborator Author

Are there any linters that rely on relative paths between files that may be disrupted by this change?

No, not that I am aware of, and it wouldn't make sense for single-file linters (our linter interface doesn't allow multi-file linting - even if it does, I am not aware of any linter that leverage relationships between files' relative paths).

Borderline is this PR only changes the "pre-edit-linting" behavior, meaning that it's okay to miss potential linting errors (in other words, false negatives are acceptable).

@li-boxuan li-boxuan merged commit 75d5591 into All-Hands-AI:main Sep 2, 2024
@li-boxuan li-boxuan deleted the linting/use-tmp-file branch September 2, 2024 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants