Skip to content

Commit

Permalink
fix. Don't search correct indentation past EOF.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamere-allo-peter committed Apr 7, 2022
1 parent d749235 commit 2abb677
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
version = 0.5.2
version = 0.5.3
name = yamlfixer-opt-nc
description = automates the fixing of problems reported by yamllint
long_description = file: README.md
Expand Down
2 changes: 1 addition & 1 deletion yamlfixer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import time

__version__ = "0.5.2"
__version__ = "0.5.3"
__author__ = "OPT-NC"
__license__ = "GPLv3+"
__copyright__ = "Copyright (C) 2021-%s %s" % (time.strftime("%Y",
Expand Down
18 changes: 8 additions & 10 deletions yamlfixer/problemfixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ def __call__(self):
def get_indentation(self, offset=0):
"""Returns the indentation of the current (possibly offset) line."""
lnum = self.linenum
nblines = len(self.ffixer.lines)
if offset:
direction = int(offset/abs(offset))
lnum += direction
try:
while offset:
while (0 < lnum < len(self.ffixer.lines)) \
and not self.ffixer.lines[lnum].strip():
lnum += direction
offset -= direction
except IndexError:
# We're past EOF, so just take the last line of the file
# which is most probably empty anyway...
lnum = -1
while offset:
while (0 < lnum < nblines) and not self.ffixer.lines[lnum].strip():
lnum += direction
offset -= direction
if lnum == nblines:
# We are past EOF so just take the last line's indentation
lnum = -1
line = self.ffixer.lines[lnum]
return len(line) - len(line.lstrip())

Expand Down

0 comments on commit 2abb677

Please sign in to comment.