From f71e5ee43c22eb8dcd9643c05b39a5e4b623fa9f Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 20 Apr 2023 10:41:36 +1000 Subject: [PATCH] Limit number of rubocop autocorrect runs The typical use case is to create a small number of commits for a pull request to ease the review. And you can still run it for all cops with `-n 999` or `-n -0`. --- script/rubocop-autocorrect.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/script/rubocop-autocorrect.sh b/script/rubocop-autocorrect.sh index b4f7c4186e..b49e19639b 100755 --- a/script/rubocop-autocorrect.sh +++ b/script/rubocop-autocorrect.sh @@ -1,7 +1,12 @@ -#!/bin/sh +#!/bin/bash # # Fixes safe cops automatically and creates a commit for each. # +# Usage: +# ./script/rubocop-autocorrect.sh [-n 7] +# +# The optional parameter is passed to `head` to limit the number of iterations. +# Use `-n -0` to remove the limit. if git add --dry-run --all | grep --quiet .; then echo "Dirty working tree. Please start on a fresh branch." @@ -15,6 +20,7 @@ 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]'\ + | head "${@:1}"\ | tr -d :\ | while read cop; do echo "Trying to autocorrect safely: $cop"