Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--write: Introduce TransformMixin for Rules #2023

Merged
merged 4 commits into from
Mar 19, 2022

Conversation

cognifloyd
Copy link
Contributor

@cognifloyd cognifloyd commented Mar 19, 2022

If a Rule wants to opt-in to transforming, or modifying, files, it can add the TransformMixin and implement the transform() method.

from ansiblelint.rules import AnsibleLintRule, TransformMixin


class FooBarRule(AnsibleLintRule, TransformMixin):
    ...
    def transform(self, match: MatchError, lintable: Lintable, data: list|dict|str):
        """Edit `data` to address the `match` identified by this rule in the `lintable` file."""

This wires up the Transformer to look for TransformMixin rules and run their transform() method.

NOTE: This is a minimized version of TransformMixin to highlight the primary TrnasformMixin interface and show how the Transformer will use it. The Transforms need other features and utils which will be added in follow-up PRs.

Commits:

  • Stub TransformMixin for Rules
  • Run transforms on non-YAML files (eg Jinja)
  • Refactor running rule transforms

@cognifloyd cognifloyd requested a review from a team as a code owner March 19, 2022 01:31
@cognifloyd cognifloyd self-assigned this Mar 19, 2022
@cognifloyd cognifloyd requested review from ssbarnea and removed request for a team March 19, 2022 01:31
@cognifloyd cognifloyd changed the title --write: Introduce TransforMixin for Rules --write: Introduce TransformMixin for Rules Mar 19, 2022
@ssbarnea ssbarnea changed the title --write: Introduce TransformMixin for Rules --write: Introduce TransformMixin for Rules Mar 19, 2022
@ssbarnea ssbarnea merged commit 93d7c09 into ansible:main Mar 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants