Skip to content

Commit

Permalink
chore: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 1, 2023
1 parent 42e0ac8 commit 441ea4d
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/ansiblelint/rules/partial_become.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
from ansiblelint.rules import AnsibleLintRule, TransformMixin

if TYPE_CHECKING:


from ansiblelint.errors import MatchError
from ansiblelint.file_utils import Lintable
from ansiblelint.utils import Task
Expand All @@ -45,7 +43,9 @@ class BecomeUserWithoutBecomeRule(AnsibleLintRule, TransformMixin):
tags = ["unpredictability"]
version_added = "historic"

def matchplay(self: BecomeUserWithoutBecomeRule, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
def matchplay(
self: BecomeUserWithoutBecomeRule, file: Lintable, data: dict[str, Any]
) -> list[MatchError]:
"""Match become_user without become in play.
:param file: The file to lint.
Expand All @@ -58,15 +58,14 @@ def matchplay(self: BecomeUserWithoutBecomeRule, file: Lintable, data: dict[str,
partial = "become_user" in data and "become" not in data
if partial:
error = self.create_matcherror(
message=self.shortdesc,
filename=file,
tag=f"{self.id}[play]",
lineno=data[LINE_NUMBER_KEY],
)
message=self.shortdesc,
filename=file,
tag=f"{self.id}[play]",
lineno=data[LINE_NUMBER_KEY],
)
errors.append(error)
return errors


def matchtask(
self: BecomeUserWithoutBecomeRule,
task: Task,
Expand All @@ -83,11 +82,11 @@ def matchtask(
partial = "become_user" in data and "become" not in data
if partial:
error = self.create_matcherror(
message=self.shortdesc,
filename=file,
tag=f"{self.id}[task]",
lineno=task[LINE_NUMBER_KEY],
)
message=self.shortdesc,
filename=file,
tag=f"{self.id}[task]",
lineno=task[LINE_NUMBER_KEY],
)
errors.append(error)
return errors

Expand Down Expand Up @@ -135,8 +134,9 @@ def transform(
match.fixed = True
return


def is_ineligible_for_transform(self: BecomeUserWithoutBecomeRule, data: CommentedMap) -> bool:
def is_ineligible_for_transform(
self: BecomeUserWithoutBecomeRule, data: CommentedMap
) -> bool:
"""Check if the data is eligible for transformation.
:param data: The data to check.
Expand Down Expand Up @@ -192,15 +192,20 @@ def _transform_play(self, play: CommentedMap) -> None:
if buit and not bit and not bip:
# Preserve the end comment if become_user is the last key
comment = None
if list(task.keys())[-1] == "become_user" and "become_user" in task.ca.items:
if (
list(task.keys())[-1] == "become_user"
and "become_user" in task.ca.items
):
comment = task.ca.items.pop("become_user")
task.pop("become_user")
if comment:
self._attach_comment_end(task, comment)
if remove_play_become_user:
del play["become_user"]

def _attach_comment_end(self, obj: CommentedMap | CommentedSeq, comment: Any) -> None:
def _attach_comment_end(
self, obj: CommentedMap | CommentedSeq, comment: Any
) -> None:
"""Attach a comment to the end of the object.
:param obj: The object to attach the comment to.
Expand All @@ -218,6 +223,7 @@ def _attach_comment_end(self, obj: CommentedMap | CommentedSeq, comment: Any) ->
return
self._attach_comment_end(obj[-1], comment)


# testing code to be loaded only with pytest or when executed the rule file
if "pytest" in sys.modules:
from ansiblelint.rules import RulesCollection # pylint: disable=ungrouped-imports
Expand Down

0 comments on commit 441ea4d

Please sign in to comment.