Skip to content

Commit

Permalink
Required refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Nov 23, 2022
1 parent b41c4f3 commit 101b261
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
# .ansible-lint

profile: null # min, basic, moderate,safety, shared, production

# exclude_paths included in this file are parsed relative to this file's location
# and not relative to the CWD of execution. CLI arguments passed to the --exclude
# option are parsed relative to the CWD of execution.
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def main(argv: list[str] | None = None) -> int: # noqa: C901
from ansiblelint.rules import RulesCollection
from ansiblelint.runner import _get_matches

rules = RulesCollection(options.rulesdirs, profile=options.profile)
rules = RulesCollection(options.rulesdirs, profile_name=options.profile)

if options.list_profiles:
from ansiblelint.generate_docs import profiles_as_rich
Expand Down
6 changes: 5 additions & 1 deletion src/ansiblelint/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,11 @@ def merge_config(file_config: dict[Any, Any], cli_config: Namespace) -> Namespac
# do not include "write_list" here. See special logic below.
}

scalar_map = {"loop_var_prefix": None, "project_dir": ".", "profile": None}
scalar_map = {
"loop_var_prefix": None,
"project_dir": ".",
"profile": None,
}

if not file_config:
# use defaults if we don't have a config file and the commandline
Expand Down
10 changes: 6 additions & 4 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,14 @@ def __init__(
self,
rulesdirs: list[str] | None = None,
options: Namespace = default_options,
profile: list[str] | None = None,
profile_name: str | None = None,
conditional: bool = True,
) -> None:
"""Initialize a RulesCollection instance."""
self.options = options
self.profile = profile or []
self.profile = []
if profile_name:
self.profile = PROFILES[profile_name]
if rulesdirs is None:
rulesdirs = []
self.rulesdirs = expand_paths_vars(rulesdirs)
Expand All @@ -396,8 +398,8 @@ def __init__(
self.rules = sorted(self.rules)

# when we have a profile we unload some of the rules
if self.profile:
filter_rules_with_profile(self.rules, self.profile[0])
if profile_name:
filter_rules_with_profile(self.rules, profile_name)

def register(self, obj: AnsibleLintRule, conditional: bool = False) -> None:
"""Register a rule."""
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/rules/role_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def matchtask(
results = []
if task["action"]["__ansible_module__"] in ROLE_IMPORT_ACTION_NAMES:
name = task["action"].get("name", "")
# breakpoint()
if "/" in name:
results.append(
self.create_matcherror(
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/rules/syntax_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def _get_ansible_syntax_check_matches(lintable: Lintable) -> list[MatchError]:
if pattern.tag == "empty-playbook":
rule = WarningRule()

# breakpoint()
results.append(
MatchError(
message=title,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/ansible-lint-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"additionalProperties": false,
"examples": [".ansible-lint", ".config/ansible-lint.yml"],
"properties": {
"profiles": {
"profile": {
"title": "Profile",
"type": ["null", "string"],
"enum": ["min", "basic", "moderate", "safety", "shared", "production", null]
Expand Down
1 change: 0 additions & 1 deletion src/ansiblelint/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def __init__(self, collection: RulesCollection) -> None:

def _call_runner(self, path: str) -> list[MatchError]:
runner = Runner(path, rules=self.collection)
# breakpoint()
return runner.run()

def run(self, filename: str) -> list[MatchError]:
Expand Down

0 comments on commit 101b261

Please sign in to comment.