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

Allow configurations for each rule stored in ansiblelint.config.options #1534

Merged
merged 1 commit into from Apr 30, 2021

Conversation

ssato
Copy link
Contributor

@ssato ssato commented Apr 18, 2021

Add ansiblelint.config.options.rules: Dict[str, Any] to store configurations for rules and allow utilizing them from each rule to customize these behaviour more flexibly.

Because it seems that ansiblelint.cli.{load,merge}_config is able to load and set options.rules.*, users will be able to customize each rules by those configurations automatically like the following only with this change, I think:

# .ansible-lint
  ... (snip) ...

rules:
  <rule_id>:
     <rule_config_key_a>: <rule_config_value_a>
     ... (snip) ...

Along with the enhancement, I update two rules, RoleNames and YamllintRule, to fix pylint "super-init-not-called" errors.

@ssato ssato changed the title Enhancement to allow configurations for each rule stored in ansiblelint.config.options Allow configurations for each rule stored in ansiblelint.config.options Apr 18, 2021
@ssato ssato changed the title Allow configurations for each rule stored in ansiblelint.config.options enhancement: Allow configurations for each rule stored in ansiblelint.config.options Apr 18, 2021
@ssbarnea ssbarnea self-requested a review April 22, 2021 14:39
@ssbarnea
Copy link
Member

@ssato Can you please mention one case where this would be needed? So far I used only global options for rules but I so realize that this may be a problem for a custom rule, especially if it needs something that cannot be implemented using magic tags.

@ssbarnea ssbarnea changed the title enhancement: Allow configurations for each rule stored in ansiblelint.config.options Allow configurations for each rule stored in ansiblelint.config.options Apr 22, 2021
@ssato
Copy link
Contributor Author

ssato commented Apr 23, 2021

@ssbarnea Thanks a lot for your comment!

@ssato Can you please mention one case where this would be needed? So far I used only global options for rules but I so realize that this may be a problem for a custom rule, especially if it needs something that cannot be implemented using magic tags.

Please take a look at such cases of custom rules implemented experimentally need specific options for them below.

Similar thing is already possible if custom rule can load and parse configurations for them by themselves, however, IMHO, it's better to implement a standard way to load and get configurations for each rule in rules.AnsibleLintRule to reduce risks caused by bugs in custom rules having such code at a minimum.

Add ansiblelint.config.options.rules: Dict[str, Any] to store
configurations for each rule and utilize them from each rule to allow
customize behaviors of rules more flexibly.

Signed-Off-By: Satoru SATOH <satoru.satoh@gmail.com>
@ssato ssato force-pushed the feature/each-rule-configs branch from 63f3889 to 09291dc Compare April 30, 2021 15:14
@ssbarnea ssbarnea merged commit 3b09b80 into ansible:master Apr 30, 2021
@ssato ssato deleted the feature/each-rule-configs branch May 2, 2021 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants