sanogueralorenzo
09/09/2020, 12:12 PM-input
only on changed files) and also to avoid the gradle overhead/plugin
# Get kotlin changed files
changedFiles=$(git --no-pager diff --diff-filter=d --name-only HEAD | grep '\.kt[s"]\?$')
if [ -n "$changedFiles" ]; then
# `paste -sd "," -` replaces newlines with commas so detekt cli -i parameter can take it
java -jar config/detekt/detekt-cli-1.11.2-all.jar --build-upon-default-config --config "config/detekt/detekt.yml" --baseline "config/detekt/baseline.xml" -p config/detekt/detekt-formatting-1.11.2.jar --auto-correct -i "$( printf "%s" "$changedFiles" | paste -sd "," - )"
if [ $? -ne 0 ]; then
echo "***********************************************"
echo " Detekt failed "
echo " Please fix the above issues before committing "
echo "***********************************************"
exit 1
fi
fi
The above takes around 2 seconds and it is working properly from the tests I've been doing
My main issue is that from java -jar
to --auto-correct
is something I already have in my top level detekt task and my top level detekt baseline task (and I wouldn't want to have all that script line repeated in several files since you will have to remember to update all of them when updating version.
Is there any way to reuse that part?
Thanks! 🙏Brais Gabin
09/09/2020, 12:22 PMsanogueralorenzo
09/09/2020, 12:25 PMjava -jar config/detekt/detekt-cli-1.11.2-all.jar --build-upon-default-config --config "config/detekt/detekt.yml" --baseline "config/detekt/baseline.xml" -p config/detekt/detekt-formatting-1.11.2.jar --auto-correct
into a unique script that can be reused by other scripts (by appending some parameters at the end depending on the script)Brais Gabin
09/09/2020, 1:02 PM