File tree Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Expand file tree Collapse file tree 3 files changed +66
-0
lines changed Original file line number Diff line number Diff line change
1
+ # golang
1
2
- id : go-lint
2
3
name : lint golang files
3
4
description : ensures golang code meets the configured lint criteria.
12
13
language : script
13
14
stages : [pre-push, manual]
14
15
pass_filenames : false
16
+ # rust
17
+ - id : rust-lint
18
+ name : lint rust files
19
+ description : ensures rust code meets the configured lint criteria.
20
+ entry : pre-commit-hooks/rust-lint.sh
21
+ language : script
22
+ pass_filenames : false
23
+ stages : [pre-commit, pre-push, manual]
24
+ - id : rust-fmt
25
+ name : format rust files
26
+ description : ensures rust code is formatted as the project expects.
27
+ entry : pre-commit-hooks/rust-fmt.sh
28
+ language : script
29
+ pass_filenames : false
30
+ stages : [pre-commit, pre-push, manual]
31
+ # typos
15
32
- id : detect-typos
16
33
name : Check for typos
17
34
description : Check the code for any typos
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # Exit immediately if a command exits with a non-zero status
4
+ set -e
5
+
6
+ # Function to format rust code
7
+ run_cargo_fmt () {
8
+ echo " Executing 'cargo fmt'"
9
+ cargo fmt
10
+ }
11
+
12
+ run_cargo_fmt
13
+
14
+ # Utilize pre-commit's stash functionality to get a diff
15
+ output=$( git diff --stat)
16
+
17
+ if [ -z " $output " ]; then
18
+ echo " No changes in any files."
19
+ else
20
+ echo " files that weren't formatted:"
21
+ echo " $output " | awk -F ' |' ' /\|/ { print $1 }'
22
+ exit 1
23
+ fi
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+
3
+ # Exit immediately if a command exits with a non-zero status.
4
+ set -e
5
+
6
+ # Function to run linters on the rust project
7
+ run_linter () {
8
+ echo " Executing clippy"
9
+
10
+ # Run the linter and capture the exit status
11
+ set +e
12
+ cargo clippy -- -D warnings
13
+ local linting_result=$?
14
+ set -e
15
+
16
+ # Check the linter result and provide feedback
17
+ if [[ $linting_result -ne 0 ]]; then
18
+ echo -e " \e[31mNOK!\e[0m"
19
+ echo " Run 'cargo clippy -- -D warnings' and fix the issues"
20
+ exit 1
21
+ else
22
+ echo -e " \e[32mOK!\e[0m"
23
+ fi
24
+ }
25
+
26
+ run_linter
You can’t perform that action at this time.
0 commit comments