Skip to content

Commit 8d38688

Browse files
authored
chore(linters): Fix ruff linter issues manually (#866)
* RUF043 - Pattern passed to `match=` contains metacharacters but is neither escaped nor raw * ERA001 - Found commented code * DOC201 - `return` is not documented in docstring * A001 - Variable `dir` is shadowing a Python builtin * D103 - Missing docstring in public function * E501 - Line too long (99 > 79) * N806 - Variable `procArgs` in function should be lowercase
1 parent 9017b56 commit 8d38688

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

src/pre_commit_terraform/_cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ def invoke_cli_app(cli_args: list[str]) -> ReturnCodeType:
1818
1919
Includes initializing parsers of all the sub-apps and
2020
choosing what to execute.
21+
22+
Returns:
23+
ReturnCodeType: The return code of the app.
2124
"""
2225
root_cli_parser = initialize_argument_parser()
2326
parsed_cli_args = root_cli_parser.parse_args(cli_args)

src/pre_commit_terraform/_cli_parsing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ def attach_subcommand_parsers_to(root_cli_parser: ArgumentParser, /) -> None:
3232

3333

3434
def initialize_argument_parser() -> ArgumentParser:
35-
"""Return the root argument parser with sub-commands."""
35+
"""Return the root argument parser with sub-commands.
36+
37+
Returns:
38+
ArgumentParser: The root parser with sub-commands attached.
39+
"""
3640
root_cli_parser = ArgumentParser(prog=f'python -m {__package__ !s}')
3741
attach_subcommand_parsers_to(root_cli_parser)
3842
return root_cli_parser

src/pre_commit_terraform/terraform_docs_replace.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
def populate_argument_parser(subcommand_parser: ArgumentParser) -> None:
15+
"""Populate the parser for the subcommand."""
1516
subcommand_parser.description = (
1617
'Run terraform-docs on a set of files. Follows the standard '
1718
'convention of pulling the documentation from main.tf in order to '
@@ -47,13 +48,19 @@ def populate_argument_parser(subcommand_parser: ArgumentParser) -> None:
4748

4849

4950
def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
51+
"""Run the entry-point of the CLI app.
52+
53+
Returns:
54+
ReturnCodeType: The return code of the app.
55+
"""
5056
warnings.warn(
5157
'`terraform_docs_replace` hook is DEPRECATED.'
5258
'For migration instructions see '
5359
'https://github.com/antonbabenko/pre-commit-terraform/issues/248'
5460
'#issuecomment-1290829226',
5561
category=UserWarning,
56-
stacklevel=1, # It's should be 2, but tests are failing w/ values >1. As it's deprecated hook, it's safe to leave it as is w/o fixing it later.
62+
stacklevel=1, # It's should be 2, but tests are failing w/ values >1.
63+
# As it's deprecated hook, it's safe to leave it as is w/o fixing it.
5764
)
5865

5966
dirs: list[str] = []
@@ -65,24 +72,24 @@ def invoke_cli_app(parsed_cli_args: Namespace) -> ReturnCodeType:
6572

6673
retval = ReturnCode.OK
6774

68-
for dir in dirs:
75+
for directory in dirs:
6976
try:
70-
procArgs = []
71-
procArgs.append('terraform-docs')
77+
proc_args = []
78+
proc_args.append('terraform-docs')
7279
if cast_to('bool', parsed_cli_args.sort):
73-
procArgs.append('--sort-by-required')
74-
procArgs.extend(
80+
proc_args.append('--sort-by-required')
81+
proc_args.extend(
7582
(
7683
'md',
77-
f'./{dir}',
84+
f'./{directory}',
7885
'>',
7986
'./{dir}/{dest}'.format(
80-
dir=dir,
87+
dir=directory,
8188
dest=cast_to('str', parsed_cli_args.dest),
8289
),
8390
),
8491
)
85-
subprocess.check_call(' '.join(procArgs), shell=True)
92+
subprocess.check_call(' '.join(proc_args), shell=True)
8693
except subprocess.CalledProcessError as e:
8794
print(e)
8895
retval = ReturnCode.ERROR

tests/pytest/_cli_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
@pytest.mark.parametrize(
2424
('raised_error', 'expected_stderr'),
2525
(
26-
# pytest.param(PreCommitTerraformExit('sentinel'), 'App exiting: sentinel', id='app-exit'),
2726
pytest.param(
2827
PreCommitTerraformRuntimeError('sentinel'),
2928
'App execution took an unexpected turn: sentinel. Exiting...',
@@ -97,7 +96,7 @@ def invoke_cli_app(self, parsed_cli_args: Namespace) -> ReturnCodeType:
9796
[CustomCmdStub()],
9897
)
9998

100-
with pytest.raises(PreCommitTerraformExit, match='^sentinel$'):
99+
with pytest.raises(PreCommitTerraformExit, match=r'^sentinel$'):
101100
invoke_cli_app(['sentinel'])
102101

103102
captured_outputs = capsys.readouterr()

0 commit comments

Comments
 (0)