Skip to content

Commit 024e8bf

Browse files
authored
Upgraded linters (#2898)
1 parent fd71b3f commit 024e8bf

File tree

7 files changed

+59
-57
lines changed

7 files changed

+59
-57
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ repos:
6363
args: [--relative, --no-progress, --no-summary]
6464
name: Spell check with cspell
6565
- repo: https://github.com/sirosen/check-jsonschema
66-
rev: 0.19.2
66+
rev: 0.20.0
6767
hooks:
6868
- id: check-github-workflows
6969
- repo: https://github.com/pre-commit/pre-commit-hooks.git
@@ -112,7 +112,7 @@ repos:
112112
hooks:
113113
- id: doc8
114114
- repo: https://github.com/adrienverge/yamllint.git
115-
rev: v1.28.0
115+
rev: v1.29.0
116116
hooks:
117117
- id: yamllint
118118
exclude: >
@@ -181,7 +181,7 @@ repos:
181181
plugins/.*
182182
)$
183183
- repo: https://github.com/pycqa/pylint
184-
rev: v2.15.9
184+
rev: v2.16.0b0
185185
hooks:
186186
- id: pylint
187187
args:

plugins/modules/fake_module.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
def main() -> None:
99
"""Return the module instance."""
1010
return AnsibleModule(
11-
argument_spec=dict(
12-
data=dict(default=None),
13-
path=dict(default=None, type=str),
14-
file=dict(default=None, type=str),
15-
)
11+
argument_spec={
12+
"data": {"default": None},
13+
"path": {"default": None},
14+
"file": {"default": None},
15+
}
1616
)

src/ansiblelint/utils.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def play_children(
300300
v = template(
301301
os.path.abspath(basedir),
302302
v,
303-
dict(playbook_dir=PLAYBOOK_DIR or os.path.abspath(basedir)),
303+
{"playbook_dir": PLAYBOOK_DIR or os.path.abspath(basedir)},
304304
fail_on_undefined=False,
305305
)
306306
return delegate_map[k](basedir, k, v, parent_type)
@@ -523,7 +523,7 @@ def _look_for_role_files(
523523

524524
def _kv_to_dict(v: str) -> dict[str, Any]:
525525
(command, args, kwargs) = tokenize(v)
526-
return dict(__ansible_module__=command, __ansible_arguments__=args, **kwargs)
526+
return {"__ansible_module__": command, "__ansible_arguments__": args, **kwargs}
527527

528528

529529
def _sanitize_task(task: dict[str, Any]) -> dict[str, Any]:
@@ -564,10 +564,10 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]:
564564
if is_nested_task(task):
565565
_extract_ansible_parsed_keys_from_task(result, task, ansible_parsed_keys)
566566
# Add dummy action for block/always/rescue statements
567-
result["action"] = dict(
568-
__ansible_module__="block/always/rescue",
569-
__ansible_module_original__="block/always/rescue",
570-
)
567+
result["action"] = {
568+
"__ansible_module__": "block/always/rescue",
569+
"__ansible_module_original__": "block/always/rescue",
570+
}
571571

572572
return result
573573

@@ -604,9 +604,10 @@ def normalize_task_v2(task: dict[str, Any]) -> dict[str, Any]:
604604
# the opposite. Mainly we currently consider normalized the module listing
605605
# used by `ansible-doc -t module -l 2>/dev/null`
606606
action = removeprefix(action, "ansible.builtin.")
607-
result["action"] = dict(
608-
__ansible_module__=action, __ansible_module_original__=action_unnormalized
609-
)
607+
result["action"] = {
608+
"__ansible_module__": action,
609+
"__ansible_module_original__": action_unnormalized,
610+
}
610611

611612
if "_raw_params" in arguments:
612613
# Doing a split here is really bad as it would break jinja2 templating

test/test_ansiblelintrule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def test_unjinja() -> None:
1717
assert AnsibleLintRule.unjinja(text) == output
1818

1919

20-
@pytest.mark.parametrize("rule_config", ({}, dict(foo=True, bar=1)))
20+
@pytest.mark.parametrize("rule_config", ({}, {"foo": True, "bar": 1}))
2121
def test_rule_config(rule_config: dict[str, Any], monkeypatch: MonkeyPatch) -> None:
2222
"""Check that a rule config is inherited from options."""
2323
rule_id = "rule-0"

test/test_matcherrror.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_matcherror_invalid() -> None:
6767
r"^MatchError\(\) missing a required argument: one of 'message' or 'rule'$"
6868
)
6969
with pytest.raises(TypeError, match=expected_err):
70-
MatchError()
70+
raise MatchError()
7171

7272

7373
@pytest.mark.parametrize(

test/test_skiputils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,31 +189,31 @@ def test_append_skipped_rules(
189189
("task", "expected"),
190190
(
191191
pytest.param(
192-
dict(
193-
name="ensure apache is at the latest version",
194-
yum={"name": "httpd", "state": "latest"},
195-
),
192+
{
193+
"name": "ensure apache is at the latest version",
194+
"yum": {"name": "httpd", "state": "latest"},
195+
},
196196
False,
197197
),
198198
pytest.param(
199-
dict(
200-
name="Attempt and graceful roll back",
201-
block=[
199+
{
200+
"name": "Attempt and graceful roll back",
201+
"block": [
202202
{"name": "Force a failure", "ansible.builtin.command": "/bin/false"}
203203
],
204-
rescue=[
204+
"rescue": [
205205
{
206206
"name": "Force a failure in middle of recovery!",
207207
"ansible.builtin.command": "/bin/false",
208208
}
209209
],
210-
always=[
210+
"always": [
211211
{
212212
"name": "Always do this",
213213
"ansible.builtin.debug": {"msg": "This always executes"},
214214
}
215215
],
216-
),
216+
},
217217
True,
218218
),
219219
),

test/test_utils.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def test_tokenize(
8383
("reference_form", "alternate_forms"),
8484
(
8585
pytest.param(
86-
dict(name="hello", action="command chdir=abc echo hello world"),
87-
(dict(name="hello", command="chdir=abc echo hello world"),),
86+
{"name": "hello", "action": "command chdir=abc echo hello world"},
87+
({"name": "hello", "command": "chdir=abc echo hello world"},),
8888
id="simple_command",
8989
),
9090
pytest.param(
@@ -113,12 +113,13 @@ def test_normalize(
113113

114114
def test_normalize_complex_command() -> None:
115115
"""Test that tasks specified differently are normalized same way."""
116-
task1 = dict(
117-
name="hello", action={"module": "pip", "name": "df", "editable": "false"}
118-
)
119-
task2 = dict(name="hello", pip={"name": "df", "editable": "false"})
120-
task3 = dict(name="hello", pip="name=df editable=false")
121-
task4 = dict(name="hello", action="pip name=df editable=false")
116+
task1 = {
117+
"name": "hello",
118+
"action": {"module": "pip", "name": "df", "editable": "false"},
119+
}
120+
task2 = {"name": "hello", "pip": {"name": "df", "editable": "false"}}
121+
task3 = {"name": "hello", "pip": "name=df editable=false"}
122+
task4 = {"name": "hello", "action": "pip name=df editable=false"}
122123
assert utils.normalize_task(task1, "tasks.yml") == utils.normalize_task(
123124
task2, "tasks.yml"
124125
)
@@ -134,47 +135,47 @@ def test_normalize_complex_command() -> None:
134135
("task", "expected_form"),
135136
(
136137
pytest.param(
137-
dict(
138-
name="ensure apache is at the latest version",
139-
yum={"name": "httpd", "state": "latest"},
140-
),
141-
dict(
142-
delegate_to=Sentinel,
143-
name="ensure apache is at the latest version",
144-
action={
138+
{
139+
"name": "ensure apache is at the latest version",
140+
"yum": {"name": "httpd", "state": "latest"},
141+
},
142+
{
143+
"delegate_to": Sentinel,
144+
"name": "ensure apache is at the latest version",
145+
"action": {
145146
"__ansible_module__": "yum",
146147
"__ansible_module_original__": "yum",
147148
"__ansible_arguments__": [],
148149
"name": "httpd",
149150
"state": "latest",
150151
},
151-
),
152+
},
152153
),
153154
pytest.param(
154-
dict(
155-
name="Attempt and graceful roll back",
156-
block=[
155+
{
156+
"name": "Attempt and graceful roll back",
157+
"block": [
157158
{
158159
"name": "Install httpd and memcached",
159160
"ansible.builtin.yum": ["httpd", "memcached"],
160161
"state": "present",
161162
}
162163
],
163-
),
164-
dict(
165-
name="Attempt and graceful roll back",
166-
block=[
164+
},
165+
{
166+
"name": "Attempt and graceful roll back",
167+
"block": [
167168
{
168169
"name": "Install httpd and memcached",
169170
"ansible.builtin.yum": ["httpd", "memcached"],
170171
"state": "present",
171172
}
172173
],
173-
action={
174+
"action": {
174175
"__ansible_module__": "block/always/rescue",
175176
"__ansible_module_original__": "block/always/rescue",
176177
},
177-
),
178+
},
178179
),
179180
),
180181
)
@@ -241,15 +242,15 @@ def test_template(template: str, output: str) -> None:
241242
result = utils.template(
242243
basedir="/base/dir",
243244
value=template,
244-
variables=dict(playbook_dir="/a/b/c"),
245+
variables={"playbook_dir": "/a/b/c"},
245246
fail_on_error=False,
246247
)
247248
assert result == output
248249

249250

250251
def test_task_to_str_unicode() -> None:
251252
"""Ensure that extracting messages from tasks preserves Unicode."""
252-
task = dict(fail=dict(msg="unicode é ô à"))
253+
task = {"fail": {"msg": "unicode é ô à"}}
253254
result = utils.task_to_str(utils.normalize_task(task, "filename.yml"))
254255
assert result == "fail msg=unicode é ô à"
255256

0 commit comments

Comments
 (0)