Skip to content

Commit 6ca38dc

Browse files
committed
refactor: Implement more Lefthook functionality.
1 parent 5d529a6 commit 6ca38dc

10 files changed

+589
-89
lines changed

.lefthook.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ pre-commit:
4949
shfmt --simplify --write --language-dialect=auto --indent=4 --case-indent --space-redirects {staged_files}
5050
stage_fixed: true
5151

52-
# trivy-vuln:
53-
# tags: "always,secrets"
54-
# run: >-
55-
# trivy fs --config trivy-vuln.yaml --ignorefile .trivyignore.yaml {staged_files}
56-
# stage_fixed: false
52+
trivy-vuln:
53+
tags: "always,secrets"
54+
run: >-
55+
trivy fs --config trivy-vuln.yaml --ignorefile .trivyignore.yaml .
56+
stage_fixed: false
5757

58-
# trivy-license:
59-
# tags: "always,secrets"
60-
# run: >-
61-
# trivy fs --config trivy-license.yaml --ignorefile .trivyignore.yaml {staged_files}
62-
# stage_fixed: false
58+
trivy-license:
59+
tags: "always,secrets"
60+
run: >-
61+
trivy fs --config trivy-license.yaml --ignorefile .trivyignore.yaml .
62+
stage_fixed: false
6363

6464
trufflehog:
6565
tags: "always,secrets"
@@ -74,11 +74,22 @@ pre-commit:
7474
stage_fixed: true
7575

7676
scripts:
77+
# If the file is marked as executable, it should start with a hashbang.
7778
"executable_must_have_hashbang.sh":
7879
runner: bash
80+
81+
# Shell scripts MUST have a file extension.
7982
"script_must_have_extension.sh":
8083
runner: bash
8184

85+
# File MUST always end with a trailing linebreak.
86+
"end_of_file.py":
87+
runner: python3.10
88+
89+
# Remove trailing whitespace from lines.
90+
"remove_trailing_whitespace.py":
91+
runner: python3.10
92+
8293
commit-msg:
8394
commands:
8495
conventional_commit:

.lefthook/.style.yapf

Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
[style]
2+
# Align closing bracket with visual indentation.
3+
align_closing_bracket_with_visual_indent=True
4+
5+
# Allow dictionary keys to exist on multiple lines. For example:
6+
#
7+
# x = {
8+
# ('this is the first element of a tuple',
9+
# 'this is the second element of a tuple'):
10+
# value,
11+
# }
12+
allow_multiline_dictionary_keys=False
13+
14+
# Allow lambdas to be formatted on more than one line.
15+
allow_multiline_lambdas=False
16+
17+
# Allow splitting before a default / named assignment in an argument list.
18+
allow_split_before_default_or_named_assigns=True
19+
20+
# Allow splits before the dictionary value.
21+
allow_split_before_dict_value=True
22+
23+
# Let spacing indicate operator precedence. For example:
24+
#
25+
# a = 1 * 2 + 3 / 4
26+
# b = 1 / 2 - 3 * 4
27+
# c = (1 + 2) * (3 - 4)
28+
# d = (1 - 2) / (3 + 4)
29+
# e = 1 * 2 - 3
30+
# f = 1 + 2 + 3 + 4
31+
#
32+
# will be formatted as follows to indicate precedence:
33+
#
34+
# a = 1*2 + 3/4
35+
# b = 1/2 - 3*4
36+
# c = (1+2) * (3-4)
37+
# d = (1-2) / (3+4)
38+
# e = 1*2 - 3
39+
# f = 1 + 2 + 3 + 4
40+
#
41+
arithmetic_precedence_indication=False
42+
43+
# Number of blank lines surrounding top-level function and class
44+
# definitions.
45+
blank_lines_around_top_level_definition=1
46+
47+
# Insert a blank line before a class-level docstring.
48+
blank_line_before_class_docstring=True
49+
50+
# Insert a blank line before a module docstring.
51+
blank_line_before_module_docstring=True
52+
53+
# Insert a blank line before a 'def' or 'class' immediately nested
54+
# within another 'def' or 'class'. For example:
55+
#
56+
# class Foo:
57+
# # <------ this blank line
58+
# def method():
59+
# ...
60+
blank_line_before_nested_class_or_def=True
61+
62+
# Do not split consecutive brackets. Only relevant when
63+
# dedent_closing_brackets is set. For example:
64+
#
65+
# call_func_that_takes_a_dict(
66+
# {
67+
# 'key1': 'value1',
68+
# 'key2': 'value2',
69+
# }
70+
# )
71+
#
72+
# would reformat to:
73+
#
74+
# call_func_that_takes_a_dict({
75+
# 'key1': 'value1',
76+
# 'key2': 'value2',
77+
# })
78+
coalesce_brackets=True
79+
80+
# The column limit.
81+
column_limit=90
82+
83+
# The style for continuation alignment. Possible values are:
84+
#
85+
# - SPACE: Use spaces for continuation alignment. This is default behavior.
86+
# - FIXED: Use fixed number (CONTINUATION_INDENT_WIDTH) of columns
87+
# (ie: CONTINUATION_INDENT_WIDTH/INDENT_WIDTH tabs) for continuation
88+
# alignment.
89+
# - VALIGN-RIGHT: Vertically align continuation lines with indent
90+
# characters. Slightly right (one more indent character) if cannot
91+
# vertically align continuation lines with indent characters.
92+
#
93+
# For options FIXED, and VALIGN-RIGHT are only available when USE_TABS is
94+
# enabled.
95+
continuation_align_style=SPACE
96+
97+
# Indent width used for line continuations.
98+
continuation_indent_width=4
99+
100+
# Put closing brackets on a separate line, dedented, if the bracketed
101+
# expression can't fit in a single line. Applies to all kinds of brackets,
102+
# including function definitions and calls. For example:
103+
#
104+
# config = {
105+
# 'key1': 'value1',
106+
# 'key2': 'value2',
107+
# } # <--- this bracket is dedented and on a separate line
108+
#
109+
# time_series = self.remote_client.query_entity_counters(
110+
# entity='dev3246.region1',
111+
# key='dns.query_latency_tcp',
112+
# transform=Transformation.AVERAGE(window=timedelta(seconds=60)),
113+
# start_ts=now()-timedelta(days=3),
114+
# end_ts=now(),
115+
# ) # <--- this bracket is dedented and on a separate line
116+
dedent_closing_brackets=True
117+
118+
# Disable the heuristic which places each list element on a separate line
119+
# if the list is comma-terminated.
120+
disable_ending_comma_heuristic=False
121+
122+
# Place each dictionary entry onto its own line.
123+
each_dict_entry_on_separate_line=True
124+
125+
; # The regex for an i18n comment. The presence of this comment stops
126+
; # reformatting of that line, because the comments are required to be
127+
; # next to the string they translate.
128+
; i18n_comment=
129+
130+
; # The i18n function call names. The presence of this function stops
131+
; # reformattting on that line, because the string it has cannot be moved
132+
; # away from the i18n comment.
133+
; i18n_function_call=
134+
135+
# Indent blank lines.
136+
indent_blank_lines=False
137+
138+
# Indent the dictionary value if it cannot fit on the same line as the
139+
# dictionary key. For example:
140+
#
141+
# config = {
142+
# 'key1':
143+
# 'value1',
144+
# 'key2': value1 +
145+
# value2,
146+
# }
147+
indent_dictionary_value=True
148+
149+
# The number of columns to use for indentation.
150+
indent_width=4
151+
152+
# Join short lines into one line. E.g., single line 'if' statements.
153+
join_multiple_lines=False
154+
155+
# Do not include spaces around selected binary operators. For example:
156+
#
157+
# 1 + 2 * 3 - 4 / 5
158+
#
159+
# will be formatted as follows when configured with "*,/":
160+
#
161+
# 1 + 2*3 - 4/5
162+
no_spaces_around_selected_binary_operators=
163+
164+
# Use spaces around default or named assigns.
165+
spaces_around_default_or_named_assign=False
166+
167+
# Use spaces around the power operator.
168+
spaces_around_power_operator=True
169+
170+
# The number of spaces required before a trailing comment.
171+
# This can be a single value (representing the number of spaces
172+
# before each trailing comment) or list of values (representing
173+
# alignment column values; trailing comments within a block will
174+
# be aligned to the first column value that is greater than the maximum
175+
# line length within the block). For example:
176+
#
177+
# With spaces_before_comment=5:
178+
#
179+
# 1 + 1 # Adding values
180+
#
181+
# will be formatted as:
182+
#
183+
# 1 + 1 # Adding values <-- 5 spaces between the end of the statement and comment
184+
#
185+
# With spaces_before_comment=15, 20:
186+
#
187+
# 1 + 1 # Adding values
188+
# two + two # More adding
189+
#
190+
# longer_statement # This is a longer statement
191+
# short # This is a shorter statement
192+
#
193+
# a_very_long_statement_that_extends_beyond_the_final_column # Comment
194+
# short # This is a shorter statement
195+
#
196+
# will be formatted as:
197+
#
198+
# 1 + 1 # Adding values <-- end of line comments in block aligned to col 15
199+
# two + two # More adding
200+
#
201+
# longer_statement # This is a longer statement <-- end of line comments in block aligned to col 20
202+
# short # This is a shorter statement
203+
#
204+
# a_very_long_statement_that_extends_beyond_the_final_column # Comment <-- the end of line comments are aligned based on the line length
205+
# short # This is a shorter statement
206+
#
207+
spaces_before_comment=1
208+
209+
# Insert a space between the ending comma and closing bracket of a list,
210+
# etc.
211+
space_between_ending_comma_and_closing_bracket=True
212+
213+
# Split before arguments
214+
split_all_comma_separated_values=False
215+
216+
# Split before arguments, but do not split all subexpressions recursively
217+
# (unless needed).
218+
split_all_top_level_comma_separated_values=True
219+
220+
# Split before arguments if the argument list is terminated by a
221+
# comma.
222+
split_arguments_when_comma_terminated=True
223+
224+
# Set to True to prefer splitting before '+', '-', '*', '/', '//', or '@'
225+
# rather than after.
226+
split_before_arithmetic_operator=True
227+
228+
# Set to True to prefer splitting before '&', '|' or '^' rather than
229+
# after.
230+
split_before_bitwise_operator=True
231+
232+
# Split before the closing bracket if a list or dict literal doesn't fit on
233+
# a single line.
234+
split_before_closing_bracket=True
235+
236+
# Split before a dictionary or set generator (comp_for). For example, note
237+
# the split before the 'for':
238+
#
239+
# foo = {
240+
# variable: 'Hello world, have a nice day!'
241+
# for variable in bar if variable != 42
242+
# }
243+
split_before_dict_set_generator=True
244+
245+
# Split before the '.' if we need to split a longer expression:
246+
#
247+
# foo = ('This is a really long string: {}, {}, {}, {}'.format(a, b, c, d))
248+
#
249+
# would reformat to something like:
250+
#
251+
# foo = ('This is a really long string: {}, {}, {}, {}'
252+
# .format(a, b, c, d))
253+
split_before_dot=True
254+
255+
# Split after the opening paren which surrounds an expression if it doesn't
256+
# fit on a single line.
257+
split_before_expression_after_opening_paren=True
258+
259+
# If an argument / parameter list is going to be split, then split before
260+
# the first argument.
261+
split_before_first_argument=True
262+
263+
# Set to True to prefer splitting before 'and' or 'or' rather than
264+
# after.
265+
split_before_logical_operator=True
266+
267+
# Split named assignments onto individual lines.
268+
split_before_named_assigns=True
269+
270+
# Set to True to split list comprehensions and generators that have
271+
# non-trivial expressions and multiple clauses before each of these
272+
# clauses. For example:
273+
#
274+
# result = [
275+
# a_long_var + 100 for a_long_var in xrange(1000)
276+
# if a_long_var % 10]
277+
#
278+
# would reformat to something like:
279+
#
280+
# result = [
281+
# a_long_var + 100
282+
# for a_long_var in xrange(1000)
283+
# if a_long_var % 10]
284+
split_complex_comprehension=False
285+
286+
# The penalty for splitting right after the opening bracket.
287+
split_penalty_after_opening_bracket=0
288+
289+
# The penalty for splitting the line after a unary operator.
290+
split_penalty_after_unary_operator=10000
291+
292+
# The penalty of splitting the line around the '+', '-', '*', '/', '//',
293+
# ``%``, and '@' operators.
294+
split_penalty_arithmetic_operator=300
295+
296+
# The penalty for splitting right before an if expression.
297+
split_penalty_before_if_expr=0
298+
299+
# The penalty of splitting the line around the '&', '|', and '^'
300+
# operators.
301+
split_penalty_bitwise_operator=0
302+
303+
# The penalty for splitting a list comprehension or generator
304+
# expression.
305+
split_penalty_comprehension=80
306+
307+
# The penalty for characters over the column limit.
308+
split_penalty_excess_character=0
309+
310+
# The penalty incurred by adding a line split to the unwrapped line. The
311+
# more line splits added the higher the penalty.
312+
split_penalty_for_added_line_split=0
313+
314+
# The penalty of splitting a list of "import as" names. For example:
315+
#
316+
# from a_very_long_or_indented_module_name_yada_yad import (long_argument_1,
317+
# long_argument_2,
318+
# long_argument_3)
319+
#
320+
# would reformat to something like:
321+
#
322+
# from a_very_long_or_indented_module_name_yada_yad import (
323+
# long_argument_1, long_argument_2, long_argument_3)
324+
split_penalty_import_names=0
325+
326+
# The penalty of splitting the line around the 'and' and 'or'
327+
# operators.
328+
split_penalty_logical_operator=300
329+
330+
# Use the Tab character for indentation.
331+
use_tabs=False

0 commit comments

Comments
 (0)