Skip to content

Commit e41252b

Browse files
authored
chore(liners): Suppress ruff rules which shouldn't be fixed (#869)
1 parent 8d38688 commit e41252b

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

src/pre_commit_terraform/_cli.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,32 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
2525
root_cli_parser = initialize_argument_parser()
2626
parsed_cli_args = root_cli_parser.parse_args(cli_args)
2727
invoke_cli_app = cast_to(
28-
# FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220
28+
# FIXME: attempt typing per https://stackoverflow.com/a/75666611/595220 # noqa: TD001, TD002, TD003, FIX001, E501 All these suppressions caused by "FIXME" comment
2929
'CLIAppEntryPointCallableType',
3030
parsed_cli_args.invoke_cli_app,
3131
)
3232

3333
try:
3434
return invoke_cli_app(parsed_cli_args)
3535
except PreCommitTerraformExit as exit_err:
36-
print(f'App exiting: {exit_err !s}', file=sys.stderr)
36+
# T201 - FIXME here and below - we will replace 'print' with logging later
37+
print(f'App exiting: {exit_err !s}', file=sys.stderr) # noqa: T201
3738
raise
3839
except PreCommitTerraformRuntimeError as unhandled_exc:
39-
print(
40+
print( # noqa: T201
4041
f'App execution took an unexpected turn: {unhandled_exc !s}. '
4142
'Exiting...',
4243
file=sys.stderr,
4344
)
4445
return ReturnCode.ERROR
4546
except PreCommitTerraformBaseError as unhandled_exc:
46-
print(
47+
print( # noqa: T201
4748
f'A surprising exception happened: {unhandled_exc !s}. Exiting...',
4849
file=sys.stderr,
4950
)
5051
return ReturnCode.ERROR
5152
except KeyboardInterrupt as ctrl_c_exc:
52-
print(
53+
print( # noqa: T201
5354
f'User-initiated interrupt: {ctrl_c_exc !s}. Exiting...',
5455
file=sys.stderr,
5556
)

src/pre_commit_terraform/_errors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ class PreCommitTerraformRuntimeError(
1212
"""An exception representing a runtime error condition."""
1313

1414

15-
class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit):
15+
# N818 - The name mimics the built-in SystemExit and is meant to have exactly
16+
# the same semantics. For this reason, it shouldn't have Error in the name to
17+
# maintain resemblance.
18+
class PreCommitTerraformExit(PreCommitTerraformBaseError, SystemExit): # noqa: N818
1619
"""An exception for terminating execution from deep app layers."""

src/pre_commit_terraform/terraform_docs_replace.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6868
if os.path.realpath(filename) not in dirs and (
6969
filename.endswith(('.tf', '.tfvars'))
7070
):
71-
dirs.append(os.path.dirname(filename))
71+
# PTH120 - It should use 'pathlib', but this hook is deprecated and
72+
# we don't want to spent time on testing fixes for it
73+
dirs.append(os.path.dirname(filename)) # noqa: PTH120
7274

7375
retval = ReturnCode.OK
7476

@@ -89,8 +91,13 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
8991
),
9092
),
9193
)
92-
subprocess.check_call(' '.join(proc_args), shell=True)
93-
except subprocess.CalledProcessError as e:
94-
print(e)
94+
# S602 - 'shell=True' is insecure, but this hook is deprecated and
95+
# we don't want to spent time on testing fixes for it
96+
subprocess.check_call(' '.join(proc_args), shell=True) # noqa: S602
97+
# PERF203 - try-except shouldn't be in a loop, but it's deprecated
98+
# hook, so leave as is
99+
except subprocess.CalledProcessError as e: # noqa: PERF203
100+
# T201 - Leave print statement as is, as this is deprecated hook
101+
print(e) # noqa: T201
95102
retval = ReturnCode.ERROR
96103
return retval

tests/pytest/terraform_docs_replace_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,6 @@ def test_control_flow_negative(
120120
)
121121

122122
assert invoke_cli_app(parsed_cli_args) == ReturnCode.ERROR
123-
124-
check_call_mock.assert_called_once_with(expected_cmd, shell=True)
123+
# S604 - 'shell=True' is insecure, but this hook is deprecated and we don't
124+
# want to spent time on testing fixes for it
125+
check_call_mock.assert_called_once_with(expected_cmd, shell=True) # noqa: S604

0 commit comments

Comments
 (0)