Skip to content

Commit f3c2648

Browse files
chore(linters): Reorder linters, make hadolint ignores more specific (#832)
* Introduce hadolint config file and reorder linters * Move hadolint ignores to meaningful locations Sadly, but hadolint ignore doesn't work if there any symbol on the same line - ignore stop working. That's why set justification on different line to hadolint ignore comment --------- Co-authored-by: George L. Yermulnik <[email protected]>
1 parent f61a87e commit f3c2648

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

.pre-commit-config.yaml

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ repos:
4747
hooks:
4848
- id: gitleaks
4949

50-
#
51-
# YAML Linters
52-
#
50+
# Dockerfile
51+
- repo: https://github.com/hadolint/hadolint
52+
rev: v2.12.1-beta
53+
hooks:
54+
- id: hadolint
55+
56+
# YAML
5357
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
5458
rev: 0.2.3
5559
hooks:
@@ -71,14 +75,29 @@ repos:
7175
args:
7276
- --strict
7377

74-
# JSON5 Linter
78+
# JSON5
7579
- repo: https://github.com/pre-commit/mirrors-prettier
7680
rev: v3.1.0
7781
hooks:
7882
- id: prettier
7983
# https://prettier.io/docs/en/options.html#parser
8084
files: .json5$
8185

86+
# Bash
87+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
88+
rev: 3.0.0
89+
hooks:
90+
- id: shfmt
91+
args:
92+
- -l
93+
- -i
94+
- '2'
95+
- -ci
96+
- -sr
97+
- -w
98+
- id: shellcheck
99+
100+
# Python
82101
- repo: https://github.com/pre-commit/mirrors-mypy.git
83102
rev: v1.15.0
84103
hooks:
@@ -133,31 +152,3 @@ repos:
133152
- --lineprecision-report=.tox/.tmp/.test-results/mypy--py-3.9
134153
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.9
135154
pass_filenames: false
136-
137-
- repo: https://github.com/jumanjihouse/pre-commit-hooks
138-
rev: 3.0.0
139-
hooks:
140-
- id: shfmt
141-
args:
142-
- -l
143-
- -i
144-
- '2'
145-
- -ci
146-
- -sr
147-
- -w
148-
- id: shellcheck
149-
150-
# Dockerfile linter
151-
- repo: https://github.com/hadolint/hadolint
152-
rev: v2.12.1-beta
153-
hooks:
154-
- id: hadolint
155-
args:
156-
- --ignore=DL3007 # Using latest
157-
- --ignore=DL3013 # Pin versions in pip
158-
- --ignore=DL3027 # Do not use apt
159-
- --ignore=DL3059 # Docker `RUN`s shouldn't be consolidated here
160-
- --ignore=DL4006 # Not related to alpine
161-
- --ignore=SC1091 # Useless check
162-
- --ignore=SC2015 # Useless check
163-
- --ignore=SC3037 # Not related to alpine

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ RUN if [ "$INSTALL_ALL" != "false" ]; then \
6565
echo "TRIVY_VERSION=latest" >> /.env \
6666
; fi
6767

68+
# Docker `RUN`s shouldn't be consolidated here
69+
# hadolint global ignore=DL3059
6870
RUN /install/opentofu.sh
6971
RUN /install/terraform.sh
7072

@@ -81,12 +83,15 @@ RUN /install/trivy.sh
8183

8284

8385
# Checking binaries versions and write it to debug file
86+
87+
# SC2086 - We do not need to quote "$F" variable, because it's not contain spaces
88+
# DL4006 - Not Applicable for /bin/sh in alpine images. Disable, as recommended by check itself
89+
# hadolint ignore=SC2086,DL4006
8490
RUN . /.env && \
8591
F=tools_versions_info && \
8692
pre-commit --version >> $F && \
8793
(if [ "$OPENTOFU_VERSION" != "false" ]; then ./tofu --version | head -n 1 >> $F; else echo "opentofu SKIPPED" >> $F ; fi) && \
8894
(if [ "$TERRAFORM_VERSION" != "false" ]; then ./terraform --version | head -n 1 >> $F; else echo "terraform SKIPPED" >> $F ; fi) && \
89-
9095
\
9196
(if [ "$CHECKOV_VERSION" != "false" ]; then echo "checkov $(checkov --version)" >> $F; else echo "checkov SKIPPED" >> $F ; fi) && \
9297
(if [ "$HCLEDIT_VERSION" != "false" ]; then echo "hcledit $(./hcledit version)" >> $F; else echo "hcledit SKIPPED" >> $F ; fi) && \
@@ -98,7 +103,7 @@ RUN . /.env && \
98103
(if [ "$TFSEC_VERSION" != "false" ]; then echo "tfsec $(./tfsec --version)" >> $F; else echo "tfsec SKIPPED" >> $F ; fi) && \
99104
(if [ "$TFUPDATE_VERSION" != "false" ]; then echo "tfupdate $(./tfupdate --version)" >> $F; else echo "tfupdate SKIPPED" >> $F ; fi) && \
100105
(if [ "$TRIVY_VERSION" != "false" ]; then echo "trivy $(./trivy --version)" >> $F; else echo "trivy SKIPPED" >> $F ; fi) && \
101-
echo -e "\n\n" && cat $F && echo -e "\n\n"
106+
printf "\n\n\n" && cat $F && printf "\n\n\n"
102107

103108

104109

tests/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
# We use `latest` tag for tests proposes
2+
# hadolint ignore=DL3007
13
FROM pre-commit-terraform:latest
24

3-
RUN apt update && \
4-
apt install -y \
5-
datamash \
6-
time && \
7-
# Cleanup
8-
rm -rf /var/lib/apt/lists/*
5+
RUN apk add --no-cache \
6+
datamash=~1.8
97

108
WORKDIR /pct
119
ENTRYPOINT [ "/pct/tests/hooks_performance_test.sh" ]

0 commit comments

Comments
 (0)