Skip to content

Commit 2a55cd2

Browse files
committed
Renamed rule class methods (naming convention)
Renames - matchyaml -> match_file - matchtask -> match_task - matchtasks -> match_tasks - matcherror -> match_error - matchvar -> match_var - matchdir -> match_dir - create_matcherror -> create_match_error
1 parent 331be65 commit 2a55cd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+207
-515
lines changed

.config/dictionary.txt

Lines changed: 23 additions & 347 deletions
Large diffs are not rendered by default.

.pre-commit-config.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,14 @@ repos:
6464
rev: v9.0.1
6565
hooks:
6666
- id: cspell
67-
# entry: codespell --relative
68-
args: [--relative, --no-progress, --no-summary]
69-
name: Spell check with cspell
67+
entry: sh
68+
pass_filenames: false
69+
args:
70+
[
71+
"-c",
72+
"cspell-cli . --relative --no-progress --no-summary && cspell . --disable-dictionary=words --words-only --quiet --unique | sort --ignore-case > .config/dictionary.txt",
73+
]
74+
name: Spell check with cspell and remove unused dictionary entries
7075
- repo: https://github.com/python-jsonschema/check-jsonschema
7176
rev: 0.33.1
7277
hooks:

cspell.config.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ dictionaryDefinitions:
55
addWords: true
66
dictionaries:
77
# Use `cspell-cli trace word` to check where a work is defined
8-
- en_US
98
- bash
10-
- words
9+
- cpp
10+
- en_US
11+
- node
1112
- python
1213
- python-common
14+
- words
1315
enabled: true
1416
ignorePaths:
1517
- cspell.config.yaml
@@ -23,3 +25,12 @@ ignorePaths:
2325
# Other
2426
- "*.svg"
2527
- ".vscode/**"
28+
- build
29+
- _readthedocs
30+
- examples/playbooks/collections
31+
- site
32+
- test/schemas/node_modules
33+
- .config/dictionary.txt
34+
- "*.egg-info"
35+
- junit.xml
36+
- examples/broken/encoding.yml

docs/custom-rules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Each rule definition should have the following parts:
1717
- `description` explains what the rule checks for.
1818
- `tags` specifies one or more tags for including or excluding the rule.
1919

20-
### Match and matchtask methods
20+
### Match and match_task methods
2121

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

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

53-
The following is an example rule that uses the `matchtask` method:
53+
The following is an example rule that uses the `match_task` method:
5454

5555
```python
5656
{!../examples/rules/task_has_tag.py!}
5757
```
5858

59-
The task argument to `matchtask` contains a number of keys - the critical one is
59+
The task argument to `match_task` contains a number of keys - the critical one is
6060
_action_. The value of `task['action']` contains the module being used, and the
6161
arguments passed, both as key-value pairs and a list of other arguments (e.g.
6262
the command used with shell).

examples/rules/task_has_tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class TaskHasTag(AnsibleLintRule):
1818
description = "Tasks must have tag"
1919
tags = ["productivity", "tags"]
2020

21-
def matchtask(
21+
def match_task(
2222
self,
2323
task: Task,
2424
file: Lintable | None = None,

src/ansiblelint/_internal/rules.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def getmatches(self, file: Lintable) -> list[MatchError]:
100100
"""Return all matches while ignoring exceptions."""
101101
matches = []
102102
if not file.path.is_dir():
103-
for method in [self.matchlines, self.matchtasks, self.matchyaml]:
103+
for method in [self.matchlines, self.match_tasks, self.match_file]:
104104
try:
105105
matches.extend(method(file))
106106
except Exception as exc: # pylint: disable=broad-except # noqa: BLE001
@@ -113,14 +113,14 @@ def getmatches(self, file: Lintable) -> list[MatchError]:
113113
)
114114
_logger.debug("Ignored exception details", exc_info=True)
115115
else:
116-
matches.extend(self.matchdir(file))
116+
matches.extend(self.match_dir(file))
117117
return matches
118118

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

123-
def matchtask(
123+
def match_task(
124124
self,
125125
task: Task,
126126
file: Lintable | None = None,
@@ -133,19 +133,19 @@ def matchtask(
133133
"""
134134
return False
135135

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

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

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

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

src/ansiblelint/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{"jinja2": "**/*.j2"}, # jinja2 templates are not always parsable as something else
4040
{"jinja2": "**/*.j2.*"},
4141
{"yaml": ".github/**/*.{yaml,yml}"}, # github workflows
42-
{"text": "**/templates/**/*.*"}, # templates are likely not validable
42+
{"text": "**/templates/**/*.*"}, # templates will probably not validate
4343
{"execution-environment": "**/execution-environment.yml"},
4444
{"ansible-lint-config": "**/.ansible-lint"},
4545
{"ansible-lint-config": "**/.ansible-lint.{yaml,yml}"},
@@ -91,7 +91,7 @@
9191
"text/jinja2": "**/*.j2",
9292
}, # jinja2 templates are not always parsable as something else
9393
{"text/jinja2": "**/*.j2.*"},
94-
{"text": "**/templates/**/*.*"}, # templates are likely not validable
94+
{"text": "**/templates/**/*.*"}, # templates will likely not validate
9595
{"text/json": "**/*.json"}, # standardized
9696
{"text/markdown": "**/*.md"}, # https://tools.ietf.org/html/rfc7763
9797
{"text/rst": "**/*.rst"}, # https://en.wikipedia.org/wiki/ReStructuredText

src/ansiblelint/rules/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
match_types = {
4141
"matchlines": "line",
4242
"match": "line", # called by matchlines
43-
"matchtasks": "task",
44-
"matchtask": "task", # called by matchtasks
45-
"matchyaml": "yaml",
46-
"matchplay": "play", # called by matchyaml
47-
"matchdir": "dir",
43+
"match_tasks": "task",
44+
"match_task": "task", # called by match_tasks
45+
"match_file": "yaml",
46+
"matchplay": "play", # called by match_file
47+
"match_dir": "dir",
4848
}
4949
RE_JINJA_EXPRESSION = re.compile(r"{{.+?}}")
5050
RE_JINJA_STATEMENT = re.compile(r"{%.+?%}")
@@ -72,7 +72,7 @@ def unjinja(text: str) -> str:
7272
return text
7373

7474
# pylint: disable=too-many-arguments,too-many-positional-arguments
75-
def create_matcherror(
75+
def create_match_error(
7676
self,
7777
message: str = "",
7878
lineno: int = 1,
@@ -143,20 +143,20 @@ def matchlines(self, file: Lintable) -> list[MatchError]:
143143
message = ""
144144
if isinstance(result, str):
145145
message = result
146-
matcherror = self.create_matcherror(
146+
match_error = self.create_match_error(
147147
message=message,
148148
lineno=prev_line_no + 1,
149149
details=line,
150150
filename=file,
151151
)
152-
matches.append(matcherror)
152+
matches.append(match_error)
153153
return matches
154154

155-
def matchtasks(self, file: Lintable) -> list[MatchError]:
156-
"""Call matchtask for each task inside file and return aggregate results.
155+
def match_tasks(self, file: Lintable) -> list[MatchError]:
156+
"""Call match_task for each task inside file and return aggregate results.
157157
158-
Most rules will never need to override matchtasks because its main
159-
purpose is to call matchtask for each task/handlers in the same file,
158+
Most rules will never need to override match_tasks because its main
159+
purpose is to call match_task for each task/handlers in the same file,
160160
and to aggregate the results.
161161
"""
162162
matches: list[MatchError] = []
@@ -185,7 +185,7 @@ def matchtasks(self, file: Lintable) -> list[MatchError]:
185185
if self.needs_raw_task:
186186
task.normalized_task["__raw_task__"] = task.raw_task
187187

188-
result = self.matchtask(task, file=file)
188+
result = self.match_task(task, file=file)
189189
if not result:
190190
continue
191191

@@ -212,7 +212,7 @@ def matchtasks(self, file: Lintable) -> list[MatchError]:
212212
message = ""
213213
if isinstance(result, str):
214214
message = result
215-
match = self.create_matcherror(
215+
match = self.create_match_error(
216216
message=message,
217217
lineno=task.line,
218218
filename=file,
@@ -222,7 +222,7 @@ def matchtasks(self, file: Lintable) -> list[MatchError]:
222222
matches.append(match)
223223
return matches
224224

225-
def matchyaml(self, file: Lintable) -> list[MatchError]:
225+
def match_file(self, file: Lintable) -> list[MatchError]:
226226
matches: list[MatchError] = []
227227
if str(file.base_kind) != "text/yaml":
228228
return matches

src/ansiblelint/rules/args.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ArgsRule(AnsibleLintRule):
9999
RE_PATTERN = re.compile(r"(argument|option) '(?P<name>.*)' is of type")
100100
RE_VALUE_OF = re.compile(r"value of (?P<name>.*) must be one of:")
101101

102-
def matchtask(
102+
def match_task(
103103
self,
104104
task: Task,
105105
file: Lintable | None = None,
@@ -142,7 +142,7 @@ def matchtask(
142142
module_args.update(workarounds_inject_map[loaded_module.resolved_fqcn])
143143
if loaded_module.resolved_fqcn in workarounds_mutex_args_map:
144144
results.extend(
145-
self.create_matcherror(
145+
self.create_match_error(
146146
message=f"Module arguments {mutex_set} are mutually exclusive",
147147
lineno=task.line,
148148
tag="args[module]",
@@ -284,7 +284,7 @@ def _parse_failed_msg(
284284
return results
285285

286286
results.append(
287-
self.create_matcherror(
287+
self.create_match_error(
288288
message=error_message,
289289
lineno=task.line,
290290
tag="args[module]",

src/ansiblelint/rules/avoid_implicit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AvoidImplicitRule(AnsibleLintRule):
2626
tags = ["unpredictability"]
2727
version_changed = "6.8.0"
2828

29-
def matchtask(
29+
def match_task(
3030
self,
3131
task: Task,
3232
file: Lintable | None = None,

0 commit comments

Comments
 (0)