Skip to content

Commit 09d5543

Browse files
authored
feat: introduce pre-commit to lint code (#41)
* feat: introduce pre-commit to lint code * fix: install pre-commit pkg and hook
1 parent 8f742d4 commit 09d5543

File tree

11 files changed

+37
-18
lines changed

11 files changed

+37
-18
lines changed

.github/workflows/build-test-publish.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: tj-actions/[email protected]
2121
- name: Build & Test (Publish)
2222
run: |
23+
pip install pre-commit && pre-commit install
2324
docker login -u '${{ secrets.DOCKER_USERNAME }}' -p '${{ secrets.DOCKER_PASSWORD }}'
2425
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
2526
if [[ "$file" == *"Dockerfile" ]]; then
@@ -40,7 +41,7 @@ jobs:
4041
elif [[ "$tag" == *"alpine"* ]]; then
4142
docker run clang-tools:$tag clang-format --version | grep -E "clang-format version"
4243
docker run clang-tools:$tag clang-tidy --version | grep "LLVM version"
43-
else
44+
else
4445
docker run clang-tools:$tag clang-format --version | grep -E "clang-format version $tag"
4546
docker run clang-tools:$tag clang-tidy --version | grep "LLVM version $tag"
4647
fi

.hadolint.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.3.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- id: check-added-large-files
9+
- id: detect-private-key
10+
- repo: https://github.com/hadolint/hadolint
11+
rev: v2.12.0
12+
hooks:
13+
- id: hadolint-docker
14+
args:
15+
[
16+
--ignore,DL3008,
17+
--ignore,DL3018,
18+
--ignore,SC2086,
19+
]
20+
- repo: https://github.com/shellcheck-py/shellcheck-py
21+
rev: v0.9.0.5
22+
hooks:
23+
- id: shellcheck

13/sources.list.jammy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
3939
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
4040
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
4141
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
42-
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
42+
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse

14/sources.list.jammy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
3939
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
4040
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
4141
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
42-
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
42+
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse

15/sources.list.kinetic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ kinetic-security main restricted
3939
deb http://security.ubuntu.com/ubuntu/ kinetic-security universe
4040
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security universe
4141
deb http://security.ubuntu.com/ubuntu/ kinetic-security multiverse
42-
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security multiverse
42+
# deb-src http://security.ubuntu.com/ubuntu/ kinetic-security multiverse

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ prune: ## clean all that is not actively used
7070
@docker system prune -af
7171
@echo "== Prune ✅ image(s) Succeeded"
7272

73-
lint: check-file ## Lint the $(DOCKERFILE) content
74-
@echo "== Linting $(DOCKERFILE)..."
75-
@echo "Output Lint results"
76-
@docker run --rm -i -v $$PWD/.hadolint.yaml:/.config/hadolint.yaml hadolint/hadolint hadolint - < $(DOCKERFILE)
73+
lint: ## Lint code
74+
@echo "== Running pre-commit against all-files..."
75+
@pre-commit run --all-files
7776
@echo "== Lint ✅ Succeeded"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $ docker run -v $PWD:/src xianpengshen/clang-tools:12 clang-format --dry-run -i
4242
$ docker run xianpengshen/clang-tools:12 clang-tidy --version
4343
LLVM (http://llvm.org/):
4444
LLVM version 12.0.0
45-
45+
4646
Optimized build.
4747
Default target: x86_64-pc-linux-gnu
4848
Host CPU: cascadelake
@@ -83,7 +83,7 @@ $ docker run clang-tools clang-tidy helloworld.c \
8383
-checks=boost-*,bugprone-*,performance-*,readability-*,portability-*,modernize-*,clang-analyzer-cplusplus-*,clang-analyzer-*,cppcoreguidelines-*
8484
```
8585

86-
### Use specific tag in `Dockerfile`
86+
### Use specific tag in `Dockerfile`
8787

8888
If you want to use a specific tag of clang-tools, you can build image by passing `--build-arg`
8989

all/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN set -ex \
1010
&& apt-get update \
1111
&& for CLANG_VERSION in $CLANG_VERSIONS; do \
1212
apt-get --no-install-recommends -y install clang-format-$CLANG_VERSION clang-tidy-$CLANG_VERSION; done \
13-
&& rm -rf /var/lib/apt/lists/*
13+
&& rm -rf /var/lib/apt/lists/*
1414

1515

1616
ENV CLANG_VERSIONS="16 15 14 13"
@@ -26,7 +26,7 @@ RUN set -ex \
2626
./llvm.sh $CLANG_VERSION \
2727
&& apt-get --no-install-recommends -y install clang-format-$CLANG_VERSION clang-tidy-$CLANG_VERSION; done \
2828
&& rm llvm.sh \
29-
&& rm -rf /var/lib/apt/lists/*
29+
&& rm -rf /var/lib/apt/lists/*
3030

3131

3232
# Integrity testing

all/sources.list.jammy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted
3939
deb http://security.ubuntu.com/ubuntu/ jammy-security universe
4040
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
4141
deb http://security.ubuntu.com/ubuntu/ jammy-security multiverse
42-
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse
42+
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse

demo/compile_commands.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
"command": "/usr/bin/g++ -Wall -Werror helloworld.cpp",
55
"file": "/helloworld.cpp"
66
}
7-
]
7+
]

0 commit comments

Comments
 (0)