Skip to content

Commit aa12c13

Browse files
authored
pre-commit: run sonarlintMain task (#1368)
Recently thanks to a surge in new contributors, it has been observed that many of their commits contain code that does not pass Sonarlint checks. This results in the CI checks failing, and contributors have to push new commits to address the Sonarlint complaints. Introduce a new pre-commit hook procedure that also runs Sonarlint right before a commit gets created, which should exit with a non-zero status code so that the commit does not get made if it does not pass Sonarlint checks. Running Sonarlint checks is a passive task - in other words, it does not take the initiative of editing the code in order to make it pass the tests, so it's safe to call the Gradle task by just calling ./gradlew sonarlintMain Hopefully with this we get less unexpected failures on our CI pipeline and more motivated contributors. Signed-off-by: Chris Sdogkos <[email protected]>
1 parent 4e1c132 commit aa12c13

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

scripts/pre-commit

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ if [ "$spotlessExitCode" -ne 0 ]; then
4444
exit "$spotlessExitCode"
4545
fi
4646

47+
echo "**Running Sonarlint checks**"
48+
./gradlew sonarlintMain
49+
sonarlintExitCode=$?
50+
if [ "$sonarlintExitCode" -ne 0 ]; then
51+
pop_stash
52+
exit "$sonarlintMain"
53+
fi
54+
4755
# Spotless possibly found changes, apply them, excluding untracked files
4856
git add -u
4957

0 commit comments

Comments
 (0)