Skip to content

Commit

Permalink
Sync with internal repository
Browse files Browse the repository at this point in the history
Thank you for all your contributions.
Contributions:
    Yuki Igarashi: 2 commits, 50 lines
    Ryo Miyajima: 1 commits, 38 lines

git-pysen-release-hash: 30f522dccd4a43d4f8b80919a430fb24bbbbcff9

Co-authored-by: Yuki Igarashi <[email protected]>
Co-authored-by: Ryo Miyajima <[email protected]>
  • Loading branch information
bonprosoft and sergeant-wizard committed Mar 27, 2021
1 parent d1169fa commit 102a6bd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pip install "pysen[lint]"

```sh
# pipenv
pipenv install --dev "pysen[lint]==0.9.0"
pipenv install --dev "pysen[lint]==0.9.1"
# poetry
poetry add -D pysen==0.9.0 -E lint
poetry add -D pysen==0.9.1 -E lint
```


Expand Down
2 changes: 1 addition & 1 deletion pysen/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.9.0"
__version__ = "0.9.1"
14 changes: 12 additions & 2 deletions pysen/error_lines.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import re
from pathlib import Path
from typing import Callable, Iterable, Optional
from typing import Callable, Generator, Iterable, Optional

import unidiff

Expand Down Expand Up @@ -90,10 +90,20 @@ def _is_changed(line: unidiff.patch.Line) -> bool:
_warn_parse_error(patch, logger)
continue

def filter_hunk(
hunk: unidiff.patch.Hunk,
) -> Generator[unidiff.patch.Line, None, None]:
for line in hunk:
if _is_changed(line):
yield line
elif line.source_line_no is not None:
if start_line <= line.source_line_no <= end_line:
yield line

yield Diagnostic(
start_line=start_line,
end_line=end_line,
start_column=1,
file_path=file_path,
diff="".join(map(str, filter(_is_changed, hunk))),
diff="".join(map(str, filter_hunk(hunk))),
)
24 changes: 23 additions & 1 deletion tests/test_error_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ class Hoge:
""" # NOQA

diff_err4 = """--- /home/user/pysen/foo.py 2021-03-25 16:43:53.875256 +0000
+++ /home/user/pysen/foo.py 2021-03-25 16:44:02.267033 +0000
@@ -1,8 +1,5 @@
{
foo: "",
-
-
bar: [],
-
baz: {},
}
""" # NOQA


def test_standard_parser() -> None:
err1, err2 = parse_error_lines(std_err)
Expand Down Expand Up @@ -134,7 +147,7 @@ def test_diff_parser() -> None:
err = errors[0]
assert err.start_line == 152
assert err.end_line == 152
assert err.diff == "+\n"
assert err.diff == "+\n parser.add_argument(\n"

# has only source diff
errors = list(parse_error_diffs(diff_err3, _parse_file_path))
Expand All @@ -143,3 +156,12 @@ def test_diff_parser() -> None:
assert err.start_line == 152
assert err.end_line == 152
assert err.diff == "-\n\n"

# has multiple deletion
errors = list(parse_error_diffs(diff_err4, _parse_file_path))

assert len(errors) == 1
err1 = errors[0]
assert err1.start_line == 3
assert err1.end_line == 6
assert err1.diff == "-\n-\n bar: [],\n-\n"

0 comments on commit 102a6bd

Please sign in to comment.