From 06f98cb4f2072753c6cd205a84e600db88efbef1 Mon Sep 17 00:00:00 2001 From: Pawel Langowski Date: Thu, 20 Jun 2024 09:41:19 +0200 Subject: [PATCH] rule_var_multilineindent: fix(): Fix bug that caused index to go out of bounds Signed-off-by: Pawel Langowski --- oelint_adv/rule_base/rule_var_multilineindent.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/oelint_adv/rule_base/rule_var_multilineindent.py b/oelint_adv/rule_base/rule_var_multilineindent.py index 49e9f68..062424a 100644 --- a/oelint_adv/rule_base/rule_var_multilineindent.py +++ b/oelint_adv/rule_base/rule_var_multilineindent.py @@ -66,11 +66,13 @@ def fix(self, _file: str, stash: Stash) -> List[str]: _likeliest_indent, _indent_map = self.__line_stats(i.VarValueStripped, i.VarNameComplete, i.VarOp) _likeliest_indent = max(4, _likeliest_indent) _lines = i.RealRaw.splitlines() - # _lines = [x for x in RegexRpl.split(r'\t|\x1b', i.RealRaw) if x and x.strip()] + found = False for index, value in enumerate(_indent_map): - if value != _likeliest_indent: - i.Raw = i.Raw.replace(_lines[index + 1], " " * _likeliest_indent + _lines[index + 1].lstrip()) - i.RealRaw = i.RealRaw.replace(_lines[index + 1], " " * _likeliest_indent + _lines[index + 1].lstrip()) + if value != _likeliest_indent and index != 0: + found = True + _lines[index] = " " * _likeliest_indent + _lines[index].lstrip() res.append(_file) + if found: + i.Raw = "\n".join(_lines) + i.RealRaw = "\n".join(_lines) return res -