Merge pull request #10722 from mkllnk/rubocop-autocorrect-script

Add script for bulk autocorrect with Rubocop
This commit is contained in:
Maikel
2023-04-24 10:58:43 +10:00
committed by GitHub
8 changed files with 51 additions and 68 deletions

View File

@@ -1,41 +1,11 @@
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400`
# on 2023-04-14 06:27:24 UTC using RuboCop version 1.50.1.
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1400 --no-auto-gen-timestamp`
# using RuboCop version 1.50.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'Gemfile'
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/DeprecatedAttributeAssignment:
Exclude:
- 'engines/catalog/catalog.gemspec'
- 'engines/dfc_provider/dfc_provider.gemspec'
- 'engines/order_management/order_management.gemspec'
- 'engines/web/web.gemspec'
# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- 'engines/catalog/catalog.gemspec'
- 'engines/dfc_provider/dfc_provider.gemspec'
- 'engines/order_management/order_management.gemspec'
- 'engines/web/web.gemspec'
# Offense count: 4
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
@@ -114,13 +84,6 @@ Layout/EmptyLinesAroundBlockBody:
- 'spec/requests/checkout/concurrency_spec.rb'
- 'spec/system/admin/order_cycles/list_spec.rb'
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'spec/spec_helper.rb'
# Offense count: 2
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
@@ -236,7 +199,7 @@ Layout/LineEndStringConcatenationIndentation:
- 'spec/system/consumer/cookies_spec.rb'
- 'spec/system/consumer/shopping/cart_spec.rb'
# Offense count: 605
# Offense count: 615
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
@@ -449,7 +412,7 @@ Layout/TrailingEmptyLines:
Exclude:
- 'Rakefile'
# Offense count: 67
# Offense count: 70
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:

View File

@@ -14,11 +14,11 @@ gem "aws-sdk-s3", require: false
gem "image_processing"
gem 'activemerchant', '>= 1.78.0'
gem 'rexml'
gem 'angular-rails-templates', '>= 0.3.0'
gem 'awesome_nested_set'
gem 'ransack', '~> 2.6.0'
gem 'responders'
gem 'rexml'
gem 'webpacker', '~> 5'
gem 'i18n'
@@ -70,8 +70,8 @@ gem 'rswag-api'
gem 'rswag-ui'
gem 'omniauth_openid_connect'
gem 'openid_connect', '~> 1.3'
gem 'omniauth-rails_csrf_protection'
gem 'openid_connect', '~> 1.3'
gem 'angularjs-rails', '1.8.0'
gem 'bugsnag'
@@ -150,6 +150,7 @@ group :test, :development do
gem 'capybara'
gem 'cuprite'
gem 'database_cleaner', require: false
gem 'debug', '>= 1.0.0'
gem "factory_bot_rails", '6.2.0', require: false
gem 'fuubar', '~> 2.5.1'
gem 'json_spec', '~> 1.1.4'
@@ -160,7 +161,6 @@ group :test, :development do
gem 'rswag-specs'
gem 'shoulda-matchers'
gem 'timecop'
gem 'debug', '>= 1.0.0'
end
group :test do
@@ -175,10 +175,10 @@ end
group :development do
gem 'debugger-linecache'
gem 'rails-erd'
gem 'foreman'
gem 'listen'
gem 'pry', '~> 0.13.0'
gem 'rails-erd'
gem 'rubocop'
gem 'rubocop-rails'
gem 'spring'

View File

@@ -11,5 +11,5 @@ Gem::Specification.new do |s|
s.summary = "Catalog domain of the OFN solution."
s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE.txt", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.metadata['rubygems_mfa_required'] = 'true'
end

View File

@@ -14,9 +14,9 @@ Gem::Specification.new do |spec|
'specifications'
spec.files = Dir["{app,config,lib}/**/*"] + ['README.md']
spec.test_files = Dir['spec/**/*']
spec.add_dependency 'active_model_serializers', '~> 0.8.4'
spec.add_dependency 'jwt', '~> 2.2'
spec.add_dependency 'rspec', '~> 3.9'
spec.metadata['rubygems_mfa_required'] = 'true'
end

View File

@@ -11,5 +11,5 @@ Gem::Specification.new do |s|
s.summary = "Order Management domain of the OFN solution."
s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE.txt", "Rakefile", "README.rdoc"]
s.test_files = Dir["spec/**/*"]
s.metadata['rubygems_mfa_required'] = 'true'
end

View File

@@ -11,5 +11,5 @@ Gem::Specification.new do |s|
s.summary = "Web domain of the OFN solution."
s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE.txt", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]
s.metadata['rubygems_mfa_required'] = 'true'
end

39
script/rubocop-autocorrect.sh Executable file
View File

@@ -0,0 +1,39 @@
#!/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."
exit 1
fi
# Refresh todo file so that following commits include only related changes:
bundle exec rubocop --regenerate-todo --no-auto-gen-timestamp
git commit --all --message "Regenerate Rubocop's TODO file"
# Iterate over all safe cops.
# Looking at the 5 lines following the autocorrection comment works for our
# current todo file. If cops start to add more comment lines in the future then
# this may break and not find those cops.
# Alternatives include using `sed` for parsing or running rubocop in fail-fast
# mode to find the next failing cop.
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"
bundle exec rubocop --regenerate-todo --except "$cop"
echo "Safely autocorrect $cop" > .git/COMMIT_EDITMSG
echo "" >> .git/COMMIT_EDITMSG
bundle exec rubocop --autocorrect >> .git/COMMIT_EDITMSG
git add --all
git commit --file .git/COMMIT_EDITMSG
done

View File

@@ -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"