PyCQA / PyCQA/pycodestyle

Contextual diff lines checked

Open
#749 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.2k
Forks
754
PR merge metrics
No merged PRs in 30d

Description

pycodestyle --diff is great! More programs should accept diffs as input.

Unfortunately it appears to consider lines in the diff that are merely context. Consider the following diff:

diff --git a/example.py b/example.py
index 955628d..b6c2b66 100644
--- a/example.py
+++ b/example.py
@@ -1,2 +1,5 @@
 def invalid_but_irrelevant():
   print("I am invalid but also irrelevant")
+
+def invalid_but_relevant():
+  print("I am invalid and relevant")

(Also available as a gist.)

Line 2 (print("I am invalid but also irrelevant")) was not added in this diff, but pycodestyle still finds the problem with its indentation:

user@host:~/gists/98f18739ab30fb69d6154364dc1eee7a$ git diff HEAD~1 | pycodestyle --diff
./example.py:2:3: E111 indentation is not a multiple of four
./example.py:4:1: E302 expected 2 blank lines, found 1
./example.py:5:3: E111 indentation is not a multiple of four

I expect --diff to only consider lines added by a diff; otherwise code that's problematic but outside the scope of a change causes that change to fail linting checks.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example by piping git diff HEAD~1 to pycodestyle --diff, then trace the --diff input handling in the repository's single Python file. Done means context lines such as example.py:2 are ignored while added lines still produce the expected errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.