From 04be17ba900402bbe45b7e84372da01b956bd89b Mon Sep 17 00:00:00 2001 From: Konrad Weihmann Date: Sat, 15 Jun 2024 13:06:20 +0200 Subject: [PATCH] core: fix write back of fixed files and write each file one by one in a sorted fashion Relates to #585 Signed-off-by: Konrad Weihmann --- oelint_adv/core.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/oelint_adv/core.py b/oelint_adv/core.py index 5639637..b76fea7 100644 --- a/oelint_adv/core.py +++ b/oelint_adv/core.py @@ -7,6 +7,7 @@ from functools import partial from typing import Dict, Iterable, List, Tuple, Union +from oelint_parser.cls_item import Item from oelint_parser.cls_item import Comment from oelint_parser.cls_stash import Stash from oelint_parser.constants import CONSTANTS @@ -151,15 +152,14 @@ def group_run(group: List[str], issues += r.check(f, stash) fixedfiles = list(set(fixedfiles)) for f in fixedfiles: - _items = [f] + stash.GetLinksForFile(f) - for i in _items: - items = stash.GetItemsFor(filename=i, nolink=True) + items: List[Item] = stash.GetItemsFor(filename=f) + for file in {x.Origin for x in items}: if not state.nobackup: - os.rename(i, i + '.bak') # pragma: no cover - with open(i, 'w') as o: - o.write(''.join([x.RealRaw for x in items])) + os.rename(file, file + '.bak') # pragma: no cover + with open(file, 'w') as o: + o.write(''.join([x.RealRaw for x in sorted(items, key=lambda key: key.InFileLine) if x.Origin == file])) if not quiet: - print('{path}:{lvl}:{msg}'.format(path=os.path.abspath(i), # noqa: T201 - it's fine here; # pragma: no cover + print('{path}:{lvl}:{msg}'.format(path=os.path.abspath(file), # noqa: T201 - it's fine here; # pragma: no cover lvl='debug', msg='Applied automatic fixes')) if any(isinstance(x, FileNotApplicableInlineSuppression) for x in rules):