Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2198: Introduce pre push hook for ktlint #2002

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions scripts/kotlin-lint-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

echo "********************************"
echo "Checking code formatting"
echo "********************************"

java -jar ../oppia-android-tools/ktlint --android app/src/**/*.kt data/src/**/*.kt domain/src/**/*.kt testing/src/**/*.kt utility/src/**/*.kt

status=$?

if [ "$status" = 0 ] ; then
echo "Lint completed successfully."
exit 0
else
echo "********************************"
echo "Ktlint issue found."
echo "Please fix the above issues.
You can also use the ktlint -F --android domain/src/**/*.kt utility/src/**/*.kt data/src/**/*.kt app/src/**/*.kt testing/src/**/*.kt
command to fix the most common issues."
echo "Please note, there might be a possibility where the above command will not fix the issue.
In that case, you will have to fix it yourself."
echo "********************************"
exit 1
fi
12 changes: 12 additions & 0 deletions scripts/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# This script will run the pre-push checks in the given order
# - ktlint
# - (others in the future)

bash scripts/kotlin-lint-check.sh

# TODO(#1736): Add Bazel Linter to the project
# TODO(#1735): Add Java Linter to the project
# TODO(#970): Add XML Linter to the project
# TODO(#2097): Add Buf Linter to the project
23 changes: 23 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

# INSTRUCTIONS:
# This script will move the pre-push hook from script folder to
# the .git/hooks folder
#
# Run the script from the oppia-android root folder:
#
# bash scripts/setup.sh
anandwana001 marked this conversation as resolved.
Show resolved Hide resolved
#
# NOTE: this script should be run once after the initial codebase setup
BenHenning marked this conversation as resolved.
Show resolved Hide resolved

# Move file from script folder to .git/hooks folder
cp scripts/pre-push.sh .git/hooks/pre-push

# Download ktlint
KTLINT="0.37.1"
echo Using Ktlint $KTLINT
mkdir -p ../oppia-android-tools
cd ../oppia-android-tools
curl -sSLOC - https://github.com/pinterest/ktlint/releases/download/$KTLINT/ktlint
chmod a+x ktlint
echo Ktlint file downloaded