Created
August 8, 2025 18:16
-
-
Save CuddlyBunion341/44b5975810a72a8636b7addb758e54a6 to your computer and use it in GitHub Desktop.
A simple script that runs rails linters on files in feature branch. Handy for pre-commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MAIN_BRANCH="master" | |
RUBOCOP_CMD="docker compose exec -T app bundle exec rubocop -a" | |
ERB_LINT_CMD="docker compose exec -T app bundle exec erb_lint -a" | |
ESLINT_CMD="docker compose exec -T app eslint --fix" | |
CHANGED_FILES=$(git diff --name-only $MAIN_BRANCH) | |
process_file() { | |
local FILE="$1" | |
case "${FILE##*.}" in | |
rb) | |
echo "Running $RUBOCOP_CMD on $FILE" | |
$RUBOCOP_CMD "$FILE" & | |
;; | |
erb) | |
echo "Running $ERB_LINT_CMD on $FILE" | |
$ERB_LINT_CMD "$FILE" & | |
;; | |
js) | |
echo "Running $ESLINT_CMD on $FILE" | |
$ESLINT_CMD "$FILE" & | |
;; | |
esac | |
} | |
for FILE in $CHANGED_FILES; do | |
process_file "$FILE" | |
done | |
wait | |
echo -e "\nFormatted files compared to branch '$MAIN_BRANCH':" | |
echo "---------------------------------------------" | |
echo "$CHANGED_FILES" | sed 's/^/ - /' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment