Skip to content

Commit f7717cd

Browse files
authored
chore(linters): Introduce ruff and fix issues (#831)
1 parent e41252b commit f7717cd

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ repos:
9898
- id: shellcheck
9999

100100
# Python
101+
- repo: https://github.com/astral-sh/ruff-pre-commit
102+
rev: v0.8.4
103+
hooks:
104+
- id: ruff
105+
args:
106+
- --fix
107+
- id: ruff-format
108+
101109
- repo: https://github.com/pre-commit/mirrors-mypy.git
102110
rev: v1.15.0
103111
hooks:

ruff.toml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Assume Python 3.9
2+
target-version = "py39"
3+
4+
line-length = 79 # To decrease PR diff size
5+
6+
namespace-packages = ["src/pre_commit_terraform/", "tests/pytest/"]
7+
8+
[format]
9+
quote-style = "single"
10+
11+
[lint.flake8-quotes]
12+
inline-quotes = "single"
13+
14+
[lint.pydocstyle]
15+
convention = "pep257"
16+
17+
[lint]
18+
select = ["ALL"]
19+
preview = true
20+
ignore = [
21+
"CPY001", # Skip copyright notice requirement at top of files
22+
]
23+
24+
[lint.isort]
25+
# force-single-line = true # To decrease PR diff size
26+
lines-after-imports = 2
27+
28+
[lint.flake8-pytest-style]
29+
parametrize-values-type = "tuple"
30+
31+
[lint.per-file-ignores]
32+
# Exceptions for test files
33+
"tests/**.py" = [
34+
"S101", # Allow use of `assert` in test files
35+
"PLC2701", # Allow importing internal files needed for testing
36+
"PLR6301", # Allow 'self' parameter in method definitions (required for test stubs)
37+
"ARG002", # Allow unused arguments in instance methods (required for test stubs)
38+
"S404", # Allow importing 'subprocess' module to testing call external tools needed by these hooks
39+
40+
]

src/pre_commit_terraform/_cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
2121
2222
Returns:
2323
ReturnCodeType: The return code of the app.
24+
25+
Raises:
26+
PreCommitTerraformExit: If the app is exiting with error.
2427
"""
2528
root_cli_parser = initialize_argument_parser()
2629
parsed_cli_args = root_cli_parser.parse_args(cli_args)
@@ -33,7 +36,8 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
3336
try:
3437
return invoke_cli_app(parsed_cli_args)
3538
except PreCommitTerraformExit as exit_err:
36-
# T201 - FIXME here and below - we will replace 'print' with logging later
39+
# T201 - FIXME here and below - we will replace 'print' with
40+
# logging later
3741
print(f'App exiting: {exit_err !s}', file=sys.stderr) # noqa: T201
3842
raise
3943
except PreCommitTerraformRuntimeError as unhandled_exc:

src/pre_commit_terraform/terraform_docs_replace.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
"""Terraform Docs Replace Hook.
2+
3+
This hook is deprecated and will be removed in the future.
4+
Please, use 'terraform_docs' hook instead.
5+
"""
6+
17
import os
2-
import subprocess
8+
9+
# S404 - Allow importing 'subprocess' module to call external tools
10+
# needed by these hooks. FIXME - should be moved to separate module
11+
# when more hooks will be introduced
12+
import subprocess # noqa: S404
313
import warnings
414
from argparse import ArgumentParser, Namespace
515
from typing import cast as cast_to

0 commit comments

Comments
 (0)