Skip to content

Commit a94de2b

Browse files
committed
Enable pyright hook
1 parent 0ff4ee7 commit a94de2b

File tree

17 files changed

+85
-38
lines changed

17 files changed

+85
-38
lines changed

.pre-commit-config.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,31 @@ repos:
177177
test/local-content/.*|
178178
plugins/.*
179179
)$
180+
# - repo: https://github.com/RobertCraigie/pyright-python
181+
# rev: v1.1.389
182+
# hooks:
183+
# - id: pyright
184+
# additional_dependencies:
185+
# - nodejs-wheel-binaries
186+
# - ansible-compat>=24.8.0
187+
# - black>=22.10.0
188+
# - cryptography>=39.0.1
189+
# - filelock>=3.12.2
190+
# - importlib_metadata
191+
# - jinja2
192+
# - license-expression >= 30.3.0
193+
# - pip>=22.3.1
194+
# - pytest-mock
195+
# - pytest>=7.2.2
196+
# - rich>=13.2.0
197+
# - ruamel-yaml-clib>=0.2.8
198+
# - ruamel-yaml>=0.18.6
199+
# - subprocess-tee
200+
# - types-PyYAML
201+
# - types-jsonschema>=4.20.0.0
202+
# - types-setuptools
203+
# - wcmatch
204+
# - yamllint
180205
- repo: https://github.com/pycqa/pylint
181206
rev: v3.3.1
182207
hooks:
@@ -186,7 +211,7 @@ repos:
186211
additional_dependencies:
187212
- ansible-compat>=24.8.0
188213
- ansible-core>=2.14.0
189-
- black>=22.10.0
214+
- black>=24.10.0
190215
- docutils
191216
- filelock>=3.12.2
192217
- importlib_metadata

.taplo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
[formatting]
2+
# compatibility with toml-sort-fix pre-commit hook
23
array_trailing_comma = false
4+
compact_arrays = true
5+
compact_inline_tables = true
6+
inline_table_expand = false

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
},
4343
"editor.defaultFormatter": "ms-python.black-formatter",
4444
"editor.formatOnSave": true
45-
}
45+
},
46+
"evenBetterToml.formatter.arrayTrailingComma": true
4647
}

conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""PyTest Fixtures."""
22

3-
import importlib
43
import os
54
import platform
65
import subprocess
76
import sys
87
import warnings
8+
from importlib.util import find_spec
99
from pathlib import Path
1010

1111
import pytest
@@ -16,9 +16,7 @@
1616

1717
# checking if user is running pytest without installing test dependencies:
1818
missing = [
19-
module
20-
for module in ["ansible", "black", "mypy", "pylint"]
21-
if not importlib.util.find_spec(module)
19+
module for module in ["ansible", "black", "mypy", "pylint"] if not find_spec(module)
2220
]
2321
if missing:
2422
pytest.exit(

pyproject.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@ module = [
113113
[tool.pylint.IMPORTS]
114114
preferred-modules = ["py:pathlib", "unittest:pytest"]
115115

116-
[tool.pylint.MAIN]
117-
extension-pkg-allow-list = ["black.parsing"]
118-
119116
[tool.pylint.MASTER]
120117
bad-names = [
121118
# spell-checker:ignore linenumber
@@ -133,6 +130,7 @@ disable = [
133130
"line-too-long", # covered by black
134131
"protected-access", # covered by ruff SLF001
135132
"too-many-branches", # covered by ruff C901
133+
"wrong-import-order", # covered by ruff
136134
# TODO(ssbarnea): remove temporary skips adding during initial adoption:
137135
"duplicate-code",
138136
# unable to disable it inside tests
@@ -155,17 +153,20 @@ output-format = "colorized"
155153
score = "n"
156154

157155
[tool.pyright]
156+
exclude = ["venv", ".cache"]
158157
include = ["src"]
158+
mode = "standard"
159159
# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#sample-pyprojecttoml-file
160-
pythonVersion = "3.10"
161-
# https://github.com/microsoft/pyright/issues/777
162-
"stubPath" = ""
160+
# pythonVersion = "3.10"
161+
# reportMissingImports = false
162+
# https://github.com/microsoft/pyright/issues/9494
163+
reportPossiblyUnboundVariable = false
163164

164165
# spell-checker:ignore filterwarnings norecursedirs optionflags
165166
[tool.pytest.ini_options]
166167
# do not add options here as this will likely break either console runs or IDE
167168
# integration like vscode or pycharm
168-
addopts = "-p no:pytest_cov"
169+
addopts = "-p no:pytest_cov --failed-first"
169170
# https://code.visualstudio.com/docs/python/testing
170171
# coverage is re-enabled in `tox.ini`. That approach is safer than
171172
# `--no-cov` which prevents activation from tox.ini and which also fails

src/ansiblelint/_internal/rules.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class BaseRule:
5656
_help: str | None = None
5757
# Added when a rule is registered into a collection, gives access to options
5858
_collection: RulesCollection | None = None
59+
# Allow rules to provide a custom short description instead of using __doc__
60+
_shortdesc: str = ""
5961

6062
@property
6163
def help(self) -> str:
@@ -83,7 +85,7 @@ def url(self) -> str:
8385
@property
8486
def shortdesc(self) -> str:
8587
"""Return the short description of the rule, basically the docstring."""
86-
return self.__doc__ or ""
88+
return self._shortdesc or self.__doc__ or ""
8789

8890
def getmatches(self, file: Lintable) -> list[MatchError]:
8991
"""Return all matches while ignoring exceptions."""
@@ -190,7 +192,7 @@ class RuntimeErrorRule(BaseRule):
190192
"""Unexpected internal error."""
191193

192194
id = "internal-error"
193-
shortdesc = "Unexpected internal error"
195+
_shortdesc = "Unexpected internal error"
194196
severity = "VERY_HIGH"
195197
tags = ["core"]
196198
version_added = "v5.0.0"

src/ansiblelint/rules/args.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class ValidationPassedError(Exception):
7373
class CustomAnsibleModule(basic.AnsibleModule): # type: ignore[misc]
7474
"""Mock AnsibleModule class."""
7575

76-
def __init__(self, *args: str, **kwargs: Any) -> None:
76+
def __init__(self, *args: Any, **kwargs: Any) -> None:
7777
"""Initialize AnsibleModule mock."""
7878
kwargs["no_log"] = True
7979
super().__init__(*args, **kwargs)

src/ansiblelint/rules/avoid_implicit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AvoidImplicitRule(AnsibleLintRule):
1717
"""Rule that identifies use of undocumented or discouraged implicit behaviors."""
1818

1919
id = "avoid-implicit"
20-
shortdesc = "Avoid implicit behaviors"
20+
_shortdesc = "Avoid implicit behaviors"
2121
description = (
2222
"Items which are templated should use ``template`` instead of "
2323
"``copy`` with ``content`` to ensure correctness."

src/ansiblelint/rules/fqcn.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def matchtask(
126126

127127
if module not in self.module_aliases:
128128
loaded_module = load_plugin(module)
129+
if not isinstance(loaded_module.resolved_fqcn, str):
130+
msg = f"Invalid value ({loaded_module.resolved_fqcn})for resolved_fqcn attribute of {module} module."
131+
_logger.warning(msg)
132+
return []
129133
target = loaded_module.resolved_fqcn
130134
self.module_aliases[module] = target
131135
if target is None:

src/ansiblelint/rules/key_order.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class KeyOrderRule(AnsibleLintRule, TransformMixin):
6969
"""Ensure specific order of keys in mappings."""
7070

7171
id = "key-order"
72-
shortdesc = __doc__
7372
severity = "LOW"
7473
tags = ["formatting"]
7574
version_added = "v6.6.2"

0 commit comments

Comments
 (0)