From cfcebd12db8193174b808ae94334dc9f5d94ae9a Mon Sep 17 00:00:00 2001 From: Ryan W Date: Sat, 30 Dec 2023 16:30:37 -0800 Subject: [PATCH] Add rubocop-rails-omakase gem --- .rubocop.yml | 4 ++++ Gemfile | 1 + Gemfile.lock | 12 ++++++++++++ bin/rubocop | 14 ++++++-------- config/application.rb | 2 +- config/environments/development.rb | 2 +- config/initializers/backtrace_silencers.rb | 2 +- config/initializers/wrap_parameters.rb | 2 +- ..._create_active_storage_tables.active_storage.rb | 2 +- ...184103_create_action_text_tables.action_text.rb | 2 +- spec/requests/articles_spec.rb | 1 - spec/views/articles/edit.html.erb_spec.rb | 3 +-- spec/views/articles/new.html.erb_spec.rb | 3 +-- 13 files changed, 31 insertions(+), 19 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3a8ba5e..b578f91 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,10 @@ require: - rubocop-rails - rubocop-rspec +# Omakase Ruby styling for Rails +inherit_gem: + rubocop-rails-omakase: rubocop.yml + AllCops: TargetRubyVersion: 3.3.0 TargetRailsVersion: 7.1.0 diff --git a/Gemfile b/Gemfile index 92a77e6..bc92058 100644 --- a/Gemfile +++ b/Gemfile @@ -55,6 +55,7 @@ group :development, :test do gem "debug", platforms: %i[ mri windows ] gem "rspec-rails" gem "rubocop-rails" + gem "rubocop-rails-omakase", require: false gem "rubocop-rspec" end diff --git a/Gemfile.lock b/Gemfile.lock index 5008ade..b564e4d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -257,11 +257,22 @@ GEM rubocop (~> 1.41) rubocop-factory_bot (2.24.0) rubocop (~> 1.33) + rubocop-minitest (0.34.2) + rubocop (>= 1.39, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-performance (1.20.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) rubocop-rails (2.23.1) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails-omakase (1.0.0) + rubocop + rubocop-minitest + rubocop-performance + rubocop-rails rubocop-rspec (2.25.0) rubocop (~> 1.40) rubocop-capybara (~> 2.17) @@ -330,6 +341,7 @@ DEPENDENCIES redis (~> 5.0) rspec-rails rubocop-rails + rubocop-rails-omakase rubocop-rspec selenium-webdriver sprockets-rails diff --git a/bin/rubocop b/bin/rubocop index 66a026a..369a05b 100755 --- a/bin/rubocop +++ b/bin/rubocop @@ -8,14 +8,12 @@ # this file is here to facilitate running it. # -require 'pathname' -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', - Pathname.new(__FILE__).realpath) +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) -bundle_binstub = File.expand_path('bundle', __dir__) +bundle_binstub = File.expand_path("bundle", __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. @@ -23,7 +21,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this end end -require 'rubygems' -require 'bundler/setup' +require "rubygems" +require "bundler/setup" -load Gem.bin_path('rubocop', 'rubocop') +load Gem.bin_path("rubocop", "rubocop") diff --git a/config/application.rb b/config/application.rb index a58559a..fd793ab 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,7 +28,7 @@ module Railsondocker # Please, add to the `ignore` list any other `lib` subdirectories that do # not contain `.rb` files, or that should not be reloaded or eager loaded. # Common ones are `templates`, `generators`, or `middleware`, for example. - config.autoload_lib(ignore: %w(assets tasks)) + config.autoload_lib(ignore: %w[assets tasks]) # Configuration for the application, engines, and railties goes here. # diff --git a/config/environments/development.rb b/config/environments/development.rb index 96e5564..8bb6bd5 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -17,7 +17,7 @@ Rails.application.configure do config.consider_all_requests_local = true # Allow access when running in docker - config.web_console.allowed_ips = ["172.16.0.0/12", "192.168.0.0/16"] + config.web_console.allowed_ips = [ "172.16.0.0/12", "192.168.0.0/16" ] # Enable server timing config.server_timing = true diff --git a/config/initializers/backtrace_silencers.rb b/config/initializers/backtrace_silencers.rb index d43cc1d..74f30e8 100644 --- a/config/initializers/backtrace_silencers.rb +++ b/config/initializers/backtrace_silencers.rb @@ -7,4 +7,4 @@ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". -Rails.backtrace_cleaner.remove_silencers! if ENV['BACKTRACE'] +Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 2f3c0db..71befc3 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -7,7 +7,7 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] + wrap_parameters format: [ :json ] end # To enable root element in JSON for ActiveRecord objects. diff --git a/db/migrate/20211216184102_create_active_storage_tables.active_storage.rb b/db/migrate/20211216184102_create_active_storage_tables.active_storage.rb index 8a7bfe1..0abe016 100644 --- a/db/migrate/20211216184102_create_active_storage_tables.active_storage.rb +++ b/db/migrate/20211216184102_create_active_storage_tables.active_storage.rb @@ -52,6 +52,6 @@ class CreateActiveStorageTables < ActiveRecord::Migration[5.2] setting = config.options[config.orm][:primary_key_type] primary_key_type = setting || :primary_key foreign_key_type = setting || :bigint - [primary_key_type, foreign_key_type] + [ primary_key_type, foreign_key_type ] end end diff --git a/db/migrate/20211216184103_create_action_text_tables.action_text.rb b/db/migrate/20211216184103_create_action_text_tables.action_text.rb index 1be48d7..c1c0a9d 100644 --- a/db/migrate/20211216184103_create_action_text_tables.action_text.rb +++ b/db/migrate/20211216184103_create_action_text_tables.action_text.rb @@ -21,6 +21,6 @@ class CreateActionTextTables < ActiveRecord::Migration[6.0] setting = config.options[config.orm][:primary_key_type] primary_key_type = setting || :primary_key foreign_key_type = setting || :bigint - [primary_key_type, foreign_key_type] + [ primary_key_type, foreign_key_type ] end end diff --git a/spec/requests/articles_spec.rb b/spec/requests/articles_spec.rb index ba7b562..b647838 100644 --- a/spec/requests/articles_spec.rb +++ b/spec/requests/articles_spec.rb @@ -13,7 +13,6 @@ # sticking to rails and rspec-rails APIs to keep things simple and stable. RSpec.describe "/articles", type: :request do - # Article. As you add validations to Article, be sure to # adjust the attributes here as well. let(:valid_attributes) { diff --git a/spec/views/articles/edit.html.erb_spec.rb b/spec/views/articles/edit.html.erb_spec.rb index 524958f..da53b40 100644 --- a/spec/views/articles/edit.html.erb_spec.rb +++ b/spec/views/articles/edit.html.erb_spec.rb @@ -12,10 +12,9 @@ RSpec.describe "articles/edit", type: :view do render assert_select "form[action=?][method=?]", article_path(@article), "post" do - assert_select "input[name=?]", "article[title]" - #TODO: with rich_text, this is not a textarea + # TODO: with rich_text, this is not a textarea # assert_select "textarea[name=?]", "article[content]" end end diff --git a/spec/views/articles/new.html.erb_spec.rb b/spec/views/articles/new.html.erb_spec.rb index c149e2a..6c58ebf 100644 --- a/spec/views/articles/new.html.erb_spec.rb +++ b/spec/views/articles/new.html.erb_spec.rb @@ -12,10 +12,9 @@ RSpec.describe "articles/new", type: :view do render assert_select "form[action=?][method=?]", articles_path, "post" do - assert_select "input[name=?]", "article[title]" - #TODO: with rich_text, this is not a textarea + # TODO: with rich_text, this is not a textarea # assert_select "textarea[name=?]", "article[content]" end end