From b9bff1598d34f006501bc9f34199e9f574e4df24 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 30 Jan 2025 09:49:27 +1100 Subject: [PATCH 1/2] Add option to define your own rubocop command In development, you may choose to use this script in your Git pre-commit hook. Then you want the fastest possible execution to not be delayed in your Git operations. While the default is the safest option, you can now define your own optimised command to avoid loading the whole Rails app environment. --- script/rubocop-diff.sh | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/script/rubocop-diff.sh b/script/rubocop-diff.sh index 32dbef1ca8..31b044c5c6 100755 --- a/script/rubocop-diff.sh +++ b/script/rubocop-diff.sh @@ -7,7 +7,25 @@ # ./script/rubocop-diff.sh --cached || exit 1 # -rubocop="`dirname $0`/../bin/rubocop" +# If you prefer to use faster boot times of the Rubocop Server then you can +# define your way of calling rubocop: +# +# export RUBOCOP_BIN="rubocop --server" +# +# Or locked to the bundled version (needs update after `bundle update`): +# +# export RUBOCOP_BIN="`bundle show rubocop`/exe/rubocop --server" +# +# I don't know how to set that automatically though. +# +# But I observed some performance improvement: +# +# * Using default binstup with spring: boot: 6.2s, repeat: 0.4s, 0.4s, ... +# * Using rubocop server binstub without bundler: boot: 2s, repeat: 1s, 0.3s, ... +# * Using rubocop executable directly: boot: 2.1s, repeat: 1s, 0.16s, ... +# +# The default binstub is still the safest, always using the bundled version. +: ${RUBOCOP_BIN="`dirname $0`/../bin/rubocop"} cached="$1" # may be empty if git diff $cached --diff-filter=ACMR HEAD --quiet; then @@ -17,7 +35,8 @@ fi exec git diff $cached --name-only --relative --diff-filter=ACMR HEAD |\ xargs \ - $rubocop --force-exclusion \ - --fail-level A \ - --format simple \ - --parallel --cache true + $RUBOCOP_BIN \ + --force-exclusion \ + --fail-level A \ + --format simple \ + --parallel --cache true From 8bfbb74bf3001d0a339a70bb4423b38518ceee2a Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 4 Feb 2025 16:13:24 +1100 Subject: [PATCH 2/2] Pass any option to rubocop --- script/rubocop-diff.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/script/rubocop-diff.sh b/script/rubocop-diff.sh index 31b044c5c6..d1dca94e04 100755 --- a/script/rubocop-diff.sh +++ b/script/rubocop-diff.sh @@ -1,7 +1,11 @@ #!/bin/bash # # While you are developing, you can call this script to check all -# changed files. And then you can also tell Git to check before every +# changed files. You can auto-correct them if you wish: +# +# ./script/rubocop-diff.sh -a +# +# And then you can also tell Git to check before every # commit by adding this line to your `.git/hooks/pre-commit` file: # # ./script/rubocop-diff.sh --cached || exit 1 @@ -26,7 +30,12 @@ # # The default binstub is still the safest, always using the bundled version. : ${RUBOCOP_BIN="`dirname $0`/../bin/rubocop"} -cached="$1" # may be empty + +if [ "$1" = "--cached" ]; then + cached="$1" +else + rubocop_opt="$1" +fi if git diff $cached --diff-filter=ACMR HEAD --quiet; then # nothing changed @@ -39,4 +48,5 @@ exec git diff $cached --name-only --relative --diff-filter=ACMR HEAD |\ --force-exclusion \ --fail-level A \ --format simple \ - --parallel --cache true + --parallel --cache true \ + "$rubocop_opt"