Skip to content

Commit 4e79a72

Browse files
Merge pull request #89 from CarterPerez-dev/chore/issue-77-pt3
issue 77 pt3 golangci
2 parents 1316d31 + 7168174 commit 4e79a72

File tree

17 files changed

+330
-179
lines changed

17 files changed

+330
-179
lines changed

.github/workflows/lint.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ jobs:
8787
type: biome
8888
path: TEMPLATES/fullstack-template/frontend
8989
# Go
90+
- name: simple-vulnerability-scanner
91+
type: go
92+
path: PROJECTS/beginner/simple-vulnerability-scanner
9093
- name: docker-security-audit
9194
type: go
92-
path: PROJECTS/beginner/docker-security-audit
95+
path: PROJECTS/intermediate/docker-security-audit
9396

9497
defaults:
9598
run:
@@ -142,9 +145,13 @@ jobs:
142145
if: matrix.type == 'go'
143146
uses: actions/setup-go@v5
144147
with:
145-
go-version: '1.21'
148+
go-version-file: ${{ matrix.path }}/go.mod
146149
cache-dependency-path: ${{ matrix.path }}/go.sum
147150

151+
- name: Install golangci-lint
152+
if: matrix.type == 'go'
153+
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
154+
148155
# Ruff Linting
149156
- name: Run ruff
150157
if: matrix.type == 'ruff'
@@ -183,7 +190,7 @@ jobs:
183190
id: golangci
184191
run: |
185192
echo "Running golangci-lint..."
186-
if golangci-lint run --out-format=colored-line-number > golangci-output.txt 2>&1; then
193+
if golangci-lint run > golangci-output.txt 2>&1; then
187194
echo "GOLANGCI_PASSED=true" >> $GITHUB_ENV
188195
echo "No golangci-lint errors found!"
189196
else

.pre-commit-config.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,24 @@ repos:
9292
exclude: (\.venv|__pycache__|\.pytest_cache)/
9393

9494

95-
# TODO: add golangci checks for GO projects
95+
# Go golangci-lint Checks
96+
- repo: local
97+
hooks:
98+
- id: golangci-lint-simple-vulnerability-scanner
99+
name: golangci-lint (simple-vulnerability-scanner)
100+
entry: bash -c 'cd PROJECTS/beginner/simple-vulnerability-scanner && golangci-lint run --fix'
101+
language: system
102+
files: ^PROJECTS/beginner/simple-vulnerability-scanner/
103+
types: [go]
104+
pass_filenames: false
96105

106+
- id: golangci-lint-docker-security-audit
107+
name: golangci-lint (docker-security-audit)
108+
entry: bash -c 'cd PROJECTS/intermediate/docker-security-audit && golangci-lint run --fix'
109+
language: system
110+
files: ^PROJECTS/intermediate/docker-security-audit/
111+
types: [go]
112+
pass_filenames: false
97113

98114
# Biome Frontend Checks
99115
- repo: local

PROJECTS/beginner/base64-tool/src/base64_tool/cli.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737

3838

3939
app = typer.Typer(
40-
name="b64tool",
41-
help=("Multi-format encoding/decoding CLI "
42-
"with recursive layer detection"),
43-
no_args_is_help=True,
44-
pretty_exceptions_show_locals=False,
40+
name = "b64tool",
41+
help = ("Multi-format encoding/decoding CLI "
42+
"with recursive layer detection"),
43+
no_args_is_help = True,
44+
pretty_exceptions_show_locals = False,
4545
)
4646

47-
_console = Console(stderr=True)
47+
_console = Console(stderr = True)
4848

4949

5050
def _version_callback(value: bool) -> None:
@@ -60,201 +60,201 @@ def main(
6060
typer.Option(
6161
"--version",
6262
"-v",
63-
help="Show version and exit.",
64-
callback=_version_callback,
65-
is_eager=True,
63+
help = "Show version and exit.",
64+
callback = _version_callback,
65+
is_eager = True,
6666
),
6767
] = False,
6868
) -> None:
6969
pass
7070

7171

72-
@app.command(name="encode")
72+
@app.command(name = "encode")
7373
def encode_cmd(
7474
data: Annotated[
7575
str | None,
76-
typer.Argument(help="Data to encode."),
76+
typer.Argument(help = "Data to encode."),
7777
] = None,
7878
fmt: Annotated[
7979
EncodingFormat,
8080
typer.Option(
8181
"--format",
8282
"-f",
83-
help="Target encoding format.",
83+
help = "Target encoding format.",
8484
),
8585
] = EncodingFormat.BASE64,
8686
file: Annotated[
8787
Path | None,
8888
typer.Option(
8989
"--file",
9090
"-i",
91-
help="Read input from file.",
91+
help = "Read input from file.",
9292
),
9393
] = None,
9494
form: Annotated[
9595
bool,
9696
typer.Option(
9797
"--form",
98-
help="Use form-encoding for URL (space becomes +).",
98+
help = "Use form-encoding for URL (space becomes +).",
9999
),
100100
] = False,
101101
) -> None:
102102
try:
103103
raw = resolve_input_bytes(data, file)
104104
if fmt == EncodingFormat.URL and form:
105-
result = encode_url(raw, form=True)
105+
result = encode_url(raw, form = True)
106106
else:
107107
result = encode(raw, fmt)
108108
print_encoded(result, fmt)
109109
except typer.BadParameter:
110110
raise
111111
except Exception as exc:
112112
_console.print(f"[red]Error:[/red] {exc}")
113-
raise typer.Exit(code=ExitCode.ERROR) from None
113+
raise typer.Exit(code = ExitCode.ERROR) from None
114114

115115

116-
@app.command(name="decode")
116+
@app.command(name = "decode")
117117
def decode_cmd(
118118
data: Annotated[
119119
str | None,
120-
typer.Argument(help="Data to decode."),
120+
typer.Argument(help = "Data to decode."),
121121
] = None,
122122
fmt: Annotated[
123123
EncodingFormat,
124124
typer.Option(
125125
"--format",
126126
"-f",
127-
help="Source encoding format.",
127+
help = "Source encoding format.",
128128
),
129129
] = EncodingFormat.BASE64,
130130
file: Annotated[
131131
Path | None,
132132
typer.Option(
133133
"--file",
134134
"-i",
135-
help="Read input from file.",
135+
help = "Read input from file.",
136136
),
137137
] = None,
138138
form: Annotated[
139139
bool,
140140
typer.Option(
141141
"--form",
142-
help="Use form-decoding for URL (+ becomes space).",
142+
help = "Use form-decoding for URL (+ becomes space).",
143143
),
144144
] = False,
145145
) -> None:
146146
try:
147147
text = resolve_input_text(data, file)
148148
if fmt == EncodingFormat.URL and form:
149-
result = decode_url(text, form=True)
149+
result = decode_url(text, form = True)
150150
else:
151151
result = decode(text, fmt)
152152
print_decoded(result)
153153
except typer.BadParameter:
154154
raise
155155
except Exception as exc:
156156
_console.print(f"[red]Error:[/red] {exc}")
157-
raise typer.Exit(code=ExitCode.ERROR) from None
157+
raise typer.Exit(code = ExitCode.ERROR) from None
158158

159159

160-
@app.command(name="detect")
160+
@app.command(name = "detect")
161161
def detect_cmd(
162162
data: Annotated[
163163
str | None,
164-
typer.Argument(help="Data to analyze."),
164+
typer.Argument(help = "Data to analyze."),
165165
] = None,
166166
file: Annotated[
167167
Path | None,
168168
typer.Option(
169169
"--file",
170170
"-i",
171-
help="Read input from file.",
171+
help = "Read input from file.",
172172
),
173173
] = None,
174174
verbose: Annotated[
175175
bool,
176176
typer.Option(
177177
"--verbose",
178178
"-V",
179-
help="Show per-format score breakdown.",
179+
help = "Show per-format score breakdown.",
180180
),
181181
] = False,
182182
) -> None:
183183
try:
184184
text = resolve_input_text(data, file)
185185
results = detect_encoding(text)
186186
scores = score_all_formats(text) if verbose else None
187-
print_detection(results, verbose_scores=scores)
187+
print_detection(results, verbose_scores = scores)
188188
except typer.BadParameter:
189189
raise
190190
except Exception as exc:
191191
_console.print(f"[red]Error:[/red] {exc}")
192-
raise typer.Exit(code=ExitCode.ERROR) from None
192+
raise typer.Exit(code = ExitCode.ERROR) from None
193193

194194

195-
@app.command(name="peel")
195+
@app.command(name = "peel")
196196
def peel_cmd(
197197
data: Annotated[
198198
str | None,
199-
typer.Argument(help="Data to recursively decode."),
199+
typer.Argument(help = "Data to recursively decode."),
200200
] = None,
201201
file: Annotated[
202202
Path | None,
203203
typer.Option(
204204
"--file",
205205
"-i",
206-
help="Read input from file.",
206+
help = "Read input from file.",
207207
),
208208
] = None,
209209
max_depth: Annotated[
210210
int,
211211
typer.Option(
212212
"--max-depth",
213213
"-d",
214-
help="Maximum decoding layers.",
214+
help = "Maximum decoding layers.",
215215
),
216216
] = PEEL_MAX_DEPTH,
217217
verbose: Annotated[
218218
bool,
219219
typer.Option(
220220
"--verbose",
221221
"-V",
222-
help="Show per-format score breakdown at each layer.",
222+
help = "Show per-format score breakdown at each layer.",
223223
),
224224
] = False,
225225
) -> None:
226226
try:
227227
text = resolve_input_text(data, file)
228-
result = peel(text, max_depth=max_depth, verbose=verbose)
229-
print_peel_result(result, verbose=verbose)
228+
result = peel(text, max_depth = max_depth, verbose = verbose)
229+
print_peel_result(result, verbose = verbose)
230230
except typer.BadParameter:
231231
raise
232232
except Exception as exc:
233233
_console.print(f"[red]Error:[/red] {exc}")
234-
raise typer.Exit(code=ExitCode.ERROR) from None
234+
raise typer.Exit(code = ExitCode.ERROR) from None
235235

236236

237-
@app.command(name="chain")
237+
@app.command(name = "chain")
238238
def chain_cmd(
239239
data: Annotated[
240240
str | None,
241-
typer.Argument(help="Data to encode through chain."),
241+
typer.Argument(help = "Data to encode through chain."),
242242
] = None,
243243
steps: Annotated[
244244
str,
245245
typer.Option(
246246
"--steps",
247247
"-s",
248-
help=("Comma-separated encoding formats "
249-
"(e.g. base64,hex,url)."),
248+
help = ("Comma-separated encoding formats "
249+
"(e.g. base64,hex,url)."),
250250
),
251251
] = "base64",
252252
file: Annotated[
253253
Path | None,
254254
typer.Option(
255255
"--file",
256256
"-i",
257-
help="Read input from file.",
257+
help = "Read input from file.",
258258
),
259259
] = None,
260260
) -> None:
@@ -275,7 +275,7 @@ def chain_cmd(
275275
raise
276276
except Exception as exc:
277277
_console.print(f"[red]Error:[/red] {exc}")
278-
raise typer.Exit(code=ExitCode.ERROR) from None
278+
raise typer.Exit(code = ExitCode.ERROR) from None
279279

280280

281281
def _parse_chain_steps(raw: str) -> list[EncodingFormat]:

PROJECTS/beginner/base64-tool/src/base64_tool/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ScoreWeight:
6262
URL_RATIO_CAP: Final[float] = 0.35
6363
URL_DECODE_CHANGED: Final[float] = 0.15
6464

65+
6566
BASE64_CHARSET: Final[
6667
frozenset[str]
6768
] = frozenset("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=")
@@ -75,4 +76,3 @@ class ScoreWeight:
7576
HEX_CHARSET: Final[frozenset[str]] = frozenset("0123456789abcdefABCDEF")
7677

7778
HEX_SEPARATORS: Final[frozenset[str]] = frozenset(" :.-")
78-

0 commit comments

Comments
 (0)