Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Commit babe7c2

Browse files
authored
Auto lint before committing (#1928)
1 parent 26f2f51 commit babe7c2

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

.devcontainer/devcontainer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
"files.watcherExclude": {
1212
"**/target/**": true
1313
},
14-
"rust-analyzer.checkOnSave.command": "clippy"
14+
"rust-analyzer.checkOnSave.command": "clippy",
15+
"rust-analyzer.linkedProjects": [
16+
"/workspaces/onefuzz/src/agent/Cargo.toml"
17+
],
18+
"python.defaultInterpreterPath": "/workspaces/onefuzz/src/venv/bin/python"
1519
},
1620
// Add the IDs of extensions you want installed when the container is created.
1721
"extensions": [

.devcontainer/post-create-script.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ pip install -r requirements.txt
5858
cd /workspaces/onefuzz/src/utils
5959
chmod u+x lint.sh
6060
pip install types-six
61+
62+
cp /workspaces/onefuzz/.devcontainer/pre-commit /workspaces/onefuzz/.git/hooks
63+
chmod u+x /workspaces/onefuzz/.git/hooks/pre-commit

.devcontainer/pre-commit

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
echo "Formatting..."
4+
dotnetFormatted=0
5+
rustFormatted=0
6+
pythonFormatted=0
7+
8+
for f in $(git diff --name-only --diff-filter=ACM)
9+
do
10+
if [[ $dotnetFormatted == 0 ]] && [[ $f == src/ApiService/* ]]; then
11+
echo "Formatting dotnet"
12+
cd /workspaces/onefuzz/src/ApiService
13+
dotnet format
14+
dotnetFormatted=1
15+
fi
16+
17+
if [[ $rustFormatted == 0 ]] && [[ $f == src/agent/* ]]; then
18+
echo "Formatting rust"
19+
cd /workspaces/onefuzz/src/agent
20+
cargo fmt
21+
rustFormatted=1
22+
fi
23+
24+
if [[ $pythonFormatted == 0 ]] && [[ $(grep -Eq 'src/(cli|api-service|pytypes)/*' <<< $f) ]]; then
25+
echo "Formatting python"
26+
cd /workspaces/onefuzz/src/utils
27+
./lint.sh
28+
pythonFormatted=1
29+
fi
30+
31+
if [[ $dotnetFormatted == 1 ]] && [[ $rustFormatted == 1 ]] && [[ $pythonFormatted == 1 ]]; then
32+
break
33+
fi
34+
done
35+
36+
echo "Done formatting"

0 commit comments

Comments
 (0)