mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-31 21:37:16 +00:00
Add script for bulk autocorrect with Rubocop
We also had an old script which wasn't used and needed manual steps.
This commit is contained in:
27
script/rubocop-autocorrect.sh
Executable file
27
script/rubocop-autocorrect.sh
Executable file
@@ -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
|
||||
@@ -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 <removed_cop_name>
|
||||
#
|
||||
# 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"
|
||||
Reference in New Issue
Block a user