diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d59c8d987..93278fd92 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -98,6 +98,14 @@ repos: - id: shellcheck # Python +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.8.4 + hooks: + - id: ruff + args: + - --fix + - id: ruff-format + - repo: https://github.com/pre-commit/mirrors-mypy.git rev: v1.15.0 hooks: diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 000000000..8bb19749a --- /dev/null +++ b/ruff.toml @@ -0,0 +1,40 @@ +# Assume Python 3.9 +target-version = "py39" + +line-length = 79 # To decrease PR diff size + +namespace-packages = ["src/pre_commit_terraform/", "tests/pytest/"] + +[format] +quote-style = "single" + +[lint.flake8-quotes] +inline-quotes = "single" + +[lint.pydocstyle] +convention = "pep257" + +[lint] +select = ["ALL"] +preview = true +ignore = [ + "CPY001", # Skip copyright notice requirement at top of files +] + +[lint.isort] +# force-single-line = true # To decrease PR diff size +lines-after-imports = 2 + +[lint.flake8-pytest-style] +parametrize-values-type = "tuple" + +[lint.per-file-ignores] +# Exceptions for test files +"tests/**.py" = [ + "S101", # Allow use of `assert` in test files + "PLC2701", # Allow importing internal files needed for testing + "PLR6301", # Allow 'self' parameter in method definitions (required for test stubs) + "ARG002", # Allow unused arguments in instance methods (required for test stubs) + "S404", # Allow importing 'subprocess' module to testing call external tools needed by these hooks + +] diff --git a/src/pre_commit_terraform/_cli.py b/src/pre_commit_terraform/_cli.py index 934c907d2..976429790 100644 --- a/src/pre_commit_terraform/_cli.py +++ b/src/pre_commit_terraform/_cli.py @@ -21,6 +21,9 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType: Returns: ReturnCodeType: The return code of the app. + + Raises: + PreCommitTerraformExit: If the app is exiting with error. """ root_cli_parser = initialize_argument_parser() parsed_cli_args = root_cli_parser.parse_args(cli_args) @@ -33,7 +36,8 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType: try: return invoke_cli_app(parsed_cli_args) except PreCommitTerraformExit as exit_err: - # T201 - FIXME here and below - we will replace 'print' with logging later + # T201 - FIXME here and below - we will replace 'print' with + # logging later print(f'App exiting: {exit_err !s}', file=sys.stderr) # noqa: T201 raise except PreCommitTerraformRuntimeError as unhandled_exc: diff --git a/src/pre_commit_terraform/terraform_docs_replace.py b/src/pre_commit_terraform/terraform_docs_replace.py index ae77f1efc..07be3593b 100644 --- a/src/pre_commit_terraform/terraform_docs_replace.py +++ b/src/pre_commit_terraform/terraform_docs_replace.py @@ -1,5 +1,15 @@ +"""Terraform Docs Replace Hook. + +This hook is deprecated and will be removed in the future. +Please, use 'terraform_docs' hook instead. +""" + import os -import subprocess + +# S404 - Allow importing 'subprocess' module to call external tools +# needed by these hooks. FIXME - should be moved to separate module +# when more hooks will be introduced +import subprocess # noqa: S404 import warnings from argparse import ArgumentParser, Namespace from typing import cast as cast_to