diff --git a/script/rubocop-autocorrect.sh b/script/rubocop-autocorrect.sh new file mode 100755 index 0000000000..c046d8e05c --- /dev/null +++ b/script/rubocop-autocorrect.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Fixes safe cops automatically and creates a commit for each. +# + +if git add --dry-run --all | grep --quiet .; then + echo "Dirty working tree. Please start on a fresh branch." + exit 1 +fi + +# Refresh todo file so that following commits include only related changes: +bundle exec rubocop --regenerate-todo +git commit --all --message "Regenerate Rubocop's TODO file" + +# Iterate over all safe cops: +grep "This cop supports safe autocorrection" -A 5 .rubocop_todo.yml\ + | grep '^[A-Z]'\ + | tr -d :\ + | while read cop; do + echo "Trying to autocorrect safely: $cop" + bundle exec rubocop --regenerate-todo --except "$cop" + + echo "Safely autocorrect $cop\n" > .git/COMMIT_EDITMSG + bundle exec rubocop --autocorrect >> .git/COMMIT_EDITMSG + git add --all + git commit --file .git/COMMIT_EDITMSG + done diff --git a/script/rubocop_autocorrect b/script/rubocop_autocorrect deleted file mode 100755 index f9e7cac2fc..0000000000 --- a/script/rubocop_autocorrect +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -# Usage -# -# 1. Clean any git unstagged or untracked changes. Consider creating a new branch -# 2. Remove a cop's exclusion paragraph from the .rubocop_todo.yml -# 3. Run: -# -# $ ./script/rubocop_autocorrect -# -# This will commit all the changes. - -set -e - -COP="$1" - -bundle exec rubocop -a --only "$COP" -git add -A -git commit -m "Auto correct Rubocop's ${COP} cop"