From b6149d6cb50c435873633feb90e520053f10baca Mon Sep 17 00:00:00 2001 From: MaxymVlasov Date: Thu, 3 Apr 2025 23:39:11 +0300 Subject: [PATCH] chore(liners): Suppress ruff rulles which shoudn't be fixed --- src/pre_commit_terraform/_cli.py | 11 ++++++----- src/pre_commit_terraform/_errors.py | 5 ++++- .../terraform_docs_replace.py | 15 +++++++++++---- tests/pytest/terraform_docs_replace_test.py | 5 +++-- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/pre_commit_terraform/_cli.py b/src/pre_commit_terraform/_cli.py index 2ad7c5e31..934c907d2 100644 --- a/src/pre_commit_terraform/_cli.py +++ b/src/pre_commit_terraform/_cli.py @@ -25,7 +25,7 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType: root_cli_parser = initialize_argument_parser() parsed_cli_args = root_cli_parser.parse_args(cli_args) invoke_cli_app = cast_to( - # FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220 + # FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220 # noqa: TD001, TD002, TD003, FIX001, E501 All these suppressions caused by "FIXME" comment 'CLIAppEntryPointCallableType', parsed_cli_args.invoke_cli_app, ) @@ -33,23 +33,24 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType: try: return invoke_cli_app(parsed_cli_args) except PreCommitTerraformExit as exit_err: - print(f'App exiting: {exit_err !s}', file=sys.stderr) + # 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: - print( + print( # noqa: T201 f'App execution took an unexpected turn: {unhandled_exc !s}. ' 'Exiting...', file=sys.stderr, ) return ReturnCode.ERROR except PreCommitTerraformBaseError as unhandled_exc: - print( + print( # noqa: T201 f'A surprising exception happened: {unhandled_exc !s}. Exiting...', file=sys.stderr, ) return ReturnCode.ERROR except KeyboardInterrupt as ctrl_c_exc: - print( + print( # noqa: T201 f'User-initiated interrupt: {ctrl_c_exc !s}. Exiting...', file=sys.stderr, ) diff --git a/src/pre_commit_terraform/_errors.py b/src/pre_commit_terraform/_errors.py index 7bdb738da..6d0019808 100644 --- a/src/pre_commit_terraform/_errors.py +++ b/src/pre_commit_terraform/_errors.py @@ -12,5 +12,8 @@ class PreCommitTerraformRuntimeError( """An exception representing a runtime error condition.""" -class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit): +# N818 - The name mimics the built-in SystemExit and is meant to have exactly +# the same semantics. For this reason, it shouldn't have Error in the name to +# maintain resemblance. +class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit): # noqa: N818 """An exception for terminating execution from deep app layers.""" diff --git a/src/pre_commit_terraform/terraform_docs_replace.py b/src/pre_commit_terraform/terraform_docs_replace.py index d273d6dac..ae77f1efc 100644 --- a/src/pre_commit_terraform/terraform_docs_replace.py +++ b/src/pre_commit_terraform/terraform_docs_replace.py @@ -68,7 +68,9 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType: if os.path.realpath(filename) not in dirs and ( filename.endswith(('.tf', '.tfvars')) ): - dirs.append(os.path.dirname(filename)) + # PTH120 - It should use 'pathlib', but this hook is deprecated and + # we don't want to spent time on testing fixes for it + dirs.append(os.path.dirname(filename)) # noqa: PTH120 retval = ReturnCode.OK @@ -89,8 +91,13 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType: ), ), ) - subprocess.check_call(' '.join(proc_args), shell=True) - except subprocess.CalledProcessError as e: - print(e) + # S602 - 'shell=True' is insecure, but this hook is deprecated and + # we don't want to spent time on testing fixes for it + subprocess.check_call(' '.join(proc_args), shell=True) # noqa: S602 + # PERF203 - try-except shouldn't be in a loop, but it's deprecated + # hook, so leave as is + except subprocess.CalledProcessError as e: # noqa: PERF203 + # T201 - Leave print statement as is, as this is deprecated hook + print(e) # noqa: T201 retval = ReturnCode.ERROR return retval diff --git a/tests/pytest/terraform_docs_replace_test.py b/tests/pytest/terraform_docs_replace_test.py index 38cd12c3f..c4190c3c0 100644 --- a/tests/pytest/terraform_docs_replace_test.py +++ b/tests/pytest/terraform_docs_replace_test.py @@ -120,5 +120,6 @@ def test_control_flow_negative( ) assert invoke_cli_app(parsed_cli_args) == ReturnCode.ERROR - - check_call_mock.assert_called_once_with(expected_cmd, shell=True) + # S604 - 'shell=True' is insecure, but this hook is deprecated and we don't + # want to spent time on testing fixes for it + check_call_mock.assert_called_once_with(expected_cmd, shell=True) # noqa: S604