Skip to content

Commit

Permalink
fix: check just before fixed-method
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed May 28, 2024
1 parent 91b15c5 commit 765402a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,13 @@ def __init__(self, filename,
self.fix_w292 = self.fix_w291
self.fix_w293 = self.fix_w291

def _check_affected_anothers(self, result) -> bool:
"""Check if the fix affects the number of lines of another remark."""
line_index = result['line'] - 1
target = self.source[line_index]
original_target = self.original_source[line_index]
return target != original_target

def _fix_source(self, results):
try:
(logical_start, logical_end) = _find_logical(self.source)
Expand All @@ -541,14 +548,6 @@ def _fix_source(self, results):
if result['line'] in completed_lines:
continue

# NOTE: Skip if the correction by the fixed-method affects
# the number of lines of another remark.
_line_index = result['line'] - 1
_target = self.source[_line_index]
_original_target = self.original_source[_line_index]
if _target != _original_target:
continue

fixed_methodname = 'fix_' + result['id'].lower()
if hasattr(self, fixed_methodname):
fix = getattr(self, fixed_methodname)
Expand All @@ -570,8 +569,12 @@ def _fix_source(self, results):
completed_lines):
continue

if self._check_affected_anothers(result):
continue

Check warning on line 573 in autopep8.py

View check run for this annotation

Codecov / codecov/patch

autopep8.py#L573

Added line #L573 was not covered by tests
modified_lines = fix(result, logical)
else:
if self._check_affected_anothers(result):
continue
modified_lines = fix(result)

if modified_lines is None:
Expand Down

0 comments on commit 765402a

Please sign in to comment.