Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
437 changes: 0 additions & 437 deletions .config/dictionary.txt

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ repos:
rev: v9.0.1
hooks:
- id: cspell
# entry: codespell --relative
args: [--relative, --no-progress, --no-summary]
name: Spell check with cspell
entry: sh
pass_filenames: false
args:
[
"-c",
"cspell-cli . --relative --no-progress --no-summary && cspell . --disable-dictionary=words --words-only --quiet --unique | sort --ignore-case > .config/dictionary.txt",
]
name: Spell check with cspell and remove unused dictionary entries
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.33.1
hooks:
Expand Down
15 changes: 13 additions & 2 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ dictionaryDefinitions:
addWords: true
dictionaries:
# Use `cspell-cli trace word` to check where a work is defined
- en_US
- bash
- words
- cpp
- en_US
- node
- python
- python-common
- words
enabled: true
ignorePaths:
- cspell.config.yaml
Expand All @@ -23,3 +25,12 @@ ignorePaths:
# Other
- "*.svg"
- ".vscode/**"
- build
- _readthedocs
- examples/playbooks/collections
- site
- test/schemas/node_modules
- .config/dictionary.txt
- "*.egg-info"
- junit.xml
- examples/broken/encoding.yml
8 changes: 4 additions & 4 deletions docs/custom-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Each rule definition should have the following parts:
- `description` explains what the rule checks for.
- `tags` specifies one or more tags for including or excluding the rule.

### Match and matchtask methods
### Match and match_task methods

Each rule definition should also invoke one of the following methods:

Expand All @@ -26,7 +26,7 @@ Each rule definition should also invoke one of the following methods:
- True or a custom message if the line does match the test. (This allows one
rule to test multiple behaviors - see e.g. the
_CommandsInsteadOfModulesRule_.)
- `matchtask` operates on a single task or handler, such that tasks get
- `match_task` operates on a single task or handler, such that tasks get
standardized to always contain a _module_ key and _module_arguments_ key.
Other common task modifiers, such as _when_, _with_items_, etc., are also
available as keys if present in the task.
Expand All @@ -50,13 +50,13 @@ class DeprecatedVariableRule(AnsibleLintRule):
return '${' in line
```

The following is an example rule that uses the `matchtask` method:
The following is an example rule that uses the `match_task` method:

```python
{!../examples/rules/task_has_tag.py!}
```

The task argument to `matchtask` contains a number of keys - the critical one is
The task argument to `match_task` contains a number of keys - the critical one is
_action_. The value of `task['action']` contains the module being used, and the
arguments passed, both as key-value pairs and a list of other arguments (e.g.
the command used with shell).
Expand Down
2 changes: 1 addition & 1 deletion examples/rules/task_has_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TaskHasTag(AnsibleLintRule):
description = "Tasks must have tag"
tags = ["productivity", "tags"]

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
12 changes: 6 additions & 6 deletions src/ansiblelint/_internal/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def getmatches(self, file: Lintable) -> list[MatchError]:
"""Return all matches while ignoring exceptions."""
matches = []
if not file.path.is_dir():
for method in [self.matchlines, self.matchtasks, self.matchyaml]:
for method in [self.matchlines, self.match_tasks, self.match_file]:
try:
matches.extend(method(file))
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
Expand All @@ -113,14 +113,14 @@ def getmatches(self, file: Lintable) -> list[MatchError]:
)
_logger.debug("Ignored exception details", exc_info=True)
else:
matches.extend(self.matchdir(file))
matches.extend(self.match_dir(file))
return matches

def matchlines(self, file: Lintable) -> list[MatchError]:
"""Return matches found for a specific line."""
return []

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand All @@ -133,19 +133,19 @@ def matchtask(
"""
return False

def matchtasks(self, file: Lintable) -> list[MatchError]:
def match_tasks(self, file: Lintable) -> list[MatchError]:
"""Return matches for a tasks file."""
return []

def matchyaml(self, file: Lintable) -> list[MatchError]:
def match_file(self, file: Lintable) -> list[MatchError]:
"""Return matches found for a specific YAML text."""
return []

def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
"""Return matches found for a specific playbook."""
return []

def matchdir(self, lintable: Lintable) -> list[MatchError]:
def match_dir(self, lintable: Lintable) -> list[MatchError]:
"""Return matches for lintable folders."""
return []

Expand Down
4 changes: 2 additions & 2 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
{"jinja2": "**/*.j2"}, # jinja2 templates are not always parsable as something else
{"jinja2": "**/*.j2.*"},
{"yaml": ".github/**/*.{yaml,yml}"}, # github workflows
{"text": "**/templates/**/*.*"}, # templates are likely not validable
{"text": "**/templates/**/*.*"}, # templates will probably not validate
{"execution-environment": "**/execution-environment.yml"},
{"ansible-lint-config": "**/.ansible-lint"},
{"ansible-lint-config": "**/.ansible-lint.{yaml,yml}"},
Expand Down Expand Up @@ -91,7 +91,7 @@
"text/jinja2": "**/*.j2",
}, # jinja2 templates are not always parsable as something else
{"text/jinja2": "**/*.j2.*"},
{"text": "**/templates/**/*.*"}, # templates are likely not validable
{"text": "**/templates/**/*.*"}, # templates will likely not validate
{"text/json": "**/*.json"}, # standardized
{"text/markdown": "**/*.md"}, # https://tools.ietf.org/html/rfc7763
{"text/rst": "**/*.rst"}, # https://en.wikipedia.org/wiki/ReStructuredText
Expand Down
30 changes: 15 additions & 15 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
match_types = {
"matchlines": "line",
"match": "line", # called by matchlines
"matchtasks": "task",
"matchtask": "task", # called by matchtasks
"matchyaml": "yaml",
"matchplay": "play", # called by matchyaml
"matchdir": "dir",
"match_tasks": "task",
"match_task": "task", # called by match_tasks
"match_file": "yaml",
"matchplay": "play", # called by match_file
"match_dir": "dir",
}
RE_JINJA_EXPRESSION = re.compile(r"{{.+?}}")
RE_JINJA_STATEMENT = re.compile(r"{%.+?%}")
Expand Down Expand Up @@ -72,7 +72,7 @@ def unjinja(text: str) -> str:
return text

# pylint: disable=too-many-arguments,too-many-positional-arguments
def create_matcherror(
def create_match_error(
self,
message: str = "",
lineno: int = 1,
Expand Down Expand Up @@ -143,20 +143,20 @@ def matchlines(self, file: Lintable) -> list[MatchError]:
message = ""
if isinstance(result, str):
message = result
matcherror = self.create_matcherror(
match_error = self.create_match_error(
message=message,
lineno=prev_line_no + 1,
details=line,
filename=file,
)
matches.append(matcherror)
matches.append(match_error)
return matches

def matchtasks(self, file: Lintable) -> list[MatchError]:
"""Call matchtask for each task inside file and return aggregate results.
def match_tasks(self, file: Lintable) -> list[MatchError]:
"""Call match_task for each task inside file and return aggregate results.

Most rules will never need to override matchtasks because its main
purpose is to call matchtask for each task/handlers in the same file,
Most rules will never need to override match_tasks because its main
purpose is to call match_task for each task/handlers in the same file,
and to aggregate the results.
"""
matches: list[MatchError] = []
Expand Down Expand Up @@ -185,7 +185,7 @@ def matchtasks(self, file: Lintable) -> list[MatchError]:
if self.needs_raw_task:
task.normalized_task["__raw_task__"] = task.raw_task

result = self.matchtask(task, file=file)
result = self.match_task(task, file=file)
if not result:
continue

Expand All @@ -212,7 +212,7 @@ def matchtasks(self, file: Lintable) -> list[MatchError]:
message = ""
if isinstance(result, str):
message = result
match = self.create_matcherror(
match = self.create_match_error(
message=message,
lineno=task.line,
filename=file,
Expand All @@ -222,7 +222,7 @@ def matchtasks(self, file: Lintable) -> list[MatchError]:
matches.append(match)
return matches

def matchyaml(self, file: Lintable) -> list[MatchError]:
def match_file(self, file: Lintable) -> list[MatchError]:
matches: list[MatchError] = []
if str(file.base_kind) != "text/yaml":
return matches
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/rules/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ArgsRule(AnsibleLintRule):
RE_PATTERN = re.compile(r"(argument|option) '(?P<name>.*)' is of type")
RE_VALUE_OF = re.compile(r"value of (?P<name>.*) must be one of:")

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down Expand Up @@ -142,7 +142,7 @@ def matchtask(
module_args.update(workarounds_inject_map[loaded_module.resolved_fqcn])
if loaded_module.resolved_fqcn in workarounds_mutex_args_map:
results.extend(
self.create_matcherror(
self.create_match_error(
message=f"Module arguments {mutex_set} are mutually exclusive",
lineno=task.line,
tag="args[module]",
Expand Down Expand Up @@ -284,7 +284,7 @@ def _parse_failed_msg(
return results

results.append(
self.create_matcherror(
self.create_match_error(
message=error_message,
lineno=task.line,
tag="args[module]",
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/avoid_implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AvoidImplicitRule(AnsibleLintRule):
tags = ["unpredictability"]
version_changed = "6.8.0"

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/command_instead_of_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class CommandsInsteadOfModulesRule(AnsibleLintRule):
"rpm": ["--nodeps"],
}

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/command_instead_of_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UseCommandInsteadOfShellRule(AnsibleLintRule, TransformMixin):
tags = ["command-shell", "idiom"]
version_changed = "6.18.0"

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
6 changes: 3 additions & 3 deletions src/ansiblelint/rules/complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
raise TypeError(msg)
if len(tasks) > self._collection.options.max_tasks:
results.append(
self.create_matcherror(
self.create_match_error(
message=f"Maximum tasks allowed in a play is {self._collection.options.max_tasks}.",
tag=f"{self.id}[play]",
filename=file,
Expand All @@ -46,7 +46,7 @@ def matchplay(self, file: Lintable, data: dict[str, Any]) -> list[MatchError]:
)
return results

def matchtask(self, task: Task, file: Lintable | None = None) -> list[MatchError]:
def match_task(self, task: Task, file: Lintable | None = None) -> list[MatchError]:
"""Check if the task is a block and count the number of items inside it."""
results: list[MatchError] = []

Expand All @@ -58,7 +58,7 @@ def matchtask(self, task: Task, file: Lintable | None = None) -> list[MatchError
block_depth = self.calculate_block_depth(task)
if block_depth > self._collection.options.max_block_depth:
results.append(
self.create_matcherror(
self.create_match_error(
message=f"Replace nested block with an include_tasks to make code easier to maintain. Maximum block depth allowed is {self._collection.options.max_block_depth}.",
lineno=task.line,
tag=f"{self.id}[nesting]",
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/deprecated_bare_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class UsingBareVariablesIsDeprecatedRule(AnsibleLintRule):
tags = ["deprecations"]
version_changed = "6.19.0"

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/deprecated_local_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TaskNoLocalActionRule(AnsibleLintRule, TransformMixin):
tags = ["deprecations"]
version_changed = "4.0.0"

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/deprecated_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class DeprecatedModuleRule(AnsibleLintRule):
"include",
]

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/rules/empty_string_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ComparisonToEmptyStringRule(AnsibleLintRule):

empty_string_compare = re.compile(r"[=!]= ?(\"{2}|'{2})")

def matchtask(
def match_task(
self,
task: Task,
file: Lintable | None = None,
Expand Down
Loading
Loading