Skip to content

Commit

Permalink
Update transform for key-order rule (#3719)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sorin Sbarnea <ssbarnea@redhat.com>
Co-authored-by: Shatakshi Mishra <shatakshimishra01@gmail.com>
Co-authored-by: Joachim Schwarm <joachim@schwarm.co>
Co-authored-by: Ruchi Pakhle <72685035+Ruchip16@users.noreply.github.com>
  • Loading branch information
6 people authored Sep 6, 2023
1 parent d803b1f commit 50ff711
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/ansiblelint/rules/key_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def matchtask(
) -> list[MatchError]:
result = []
raw_task = task["__raw_task__"]
keys = [key for key in raw_task if not key.startswith("_")]
keys = [str(key) for key in raw_task if not key.startswith("_")]
sorted_keys = sorted(keys, key=functools.cmp_to_key(task_property_sorter))
if keys != sorted_keys:
result.append(
Expand All @@ -104,10 +104,10 @@ def transform(
data: CommentedMap | CommentedSeq | str,
) -> None:
if match.tag == "key-order[task]":
if not isinstance(match.transform_meta, KeyOrderTMeta):
return
task = self.seek(match.yaml_path, data)
sorted_keys = match.message.split(":")[1].split(",")
for key in sorted_keys:
key = key.strip()
for key in match.transform_meta.fixed:
task[key] = task.pop(key)
match.fixed = True

Expand Down

0 comments on commit 50ff711

Please sign in to comment.