Skip to content

Commit

Permalink
add rubocop-rails-omakase gem
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeta committed Jan 18, 2025
1 parent 44db252 commit 08407c5
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 63 deletions.
68 changes: 7 additions & 61 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,8 @@
require: rubocop-rails
# Omakase Ruby styling for Rails
inherit_gem: { rubocop-rails-omakase: rubocop.yml }

Rails:
Enabled: true
AllCops:
TargetRubyVersion: 2.6
Layout/SpaceInsideHashLiteralBraces:
Enabled: false
Layout/SpaceInsideBlockBraces:
Enabled: false
Layout/SpaceBeforeBlockBraces:
Enabled: false
Style/WordArray:
Enabled: false
Style/Documentation:
Enabled: false
Style/StringLiterals:
Enabled: false
Style/AsciiComments:
Enabled: false
Metrics/MethodLength:
Enabled: false
Metrics/LineLength:
Enabled: false
Metrics/BlockLength:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/SymbolArray:
Enabled: false
Style/BlockDelimiters:
Enabled: false
Naming/VariableNumber:
Enabled: false
Rails/SkipsModelValidations:
Enabled: false
Style/EmptyMethod:
Enabled: false
Layout/LeadingCommentSpace:
Enabled: false
Metrics/AbcSize:
Enabled: false
Layout/ArgumentAlignment:
Enabled: false
Layout/HashAlignment:
Enabled: false
Style/IfUnlessModifier:
Enabled: false
Style/PercentLiteralDelimiters:
Enabled: false
Style/SoleNestedConditional:
Enabled: false
Rails/ActiveRecordCallbacksOrder: # new in 2.7
Enabled: true
Rails/WhereNot: # new in 2.8
Enabled: true
Rails/RedundantPresenceValidationOnBelongsTo: # new in 2.13
Enabled: true
Style/GuardClause:
Enabled: false
Layout/EmptyLinesAroundAccessModifier:
Enabled: false
# Overwrite or add rules to create your own house style
#
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
# Layout/SpaceInsideArrayLiteralBrackets:
# Enabled: false
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ gem "image_processing", "~> 1.2"
group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[ mri windows ]

# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
gem "rubocop-rails-omakase", require: false
end

group :development do
Expand Down
39 changes: 39 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ GEM
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
ast (2.4.2)
awesome_nested_set (3.8.0)
activerecord (>= 4.0.0, < 8.1)
base64 (0.2.0)
Expand Down Expand Up @@ -245,6 +246,7 @@ GEM
marcel (~> 1.0.1)
mime-types
terrapin (>= 0.6.0, < 2.0)
language_server-protocol (3.17.0.3)
library_stdnums (1.6.0)
link_header (0.0.8)
lisbn (0.3.2)
Expand Down Expand Up @@ -306,6 +308,9 @@ GEM
parallel (1.26.3)
parallel_tests (4.9.0)
parallel
parser (3.3.7.0)
ast (~> 2.4.1)
racc
pg (1.5.9)
pr_geohash (1.0.0)
pretender (0.5.0)
Expand Down Expand Up @@ -373,6 +378,7 @@ GEM
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.2.1)
rdf (3.3.2)
bcp47_spec (~> 0.2)
Expand Down Expand Up @@ -429,6 +435,35 @@ GEM
rspec-core (>= 2, < 4, != 2.12.0)
rss (0.3.1)
rexml
rubocop (1.70.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-minitest (0.36.0)
rubocop (>= 1.61, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.23.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.29.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails-omakase (1.0.0)
rubocop
rubocop-minitest
rubocop-performance
rubocop-rails
ruby-progressbar (1.13.0)
ruby-vips (2.2.2)
ffi (~> 1.12)
logger
Expand Down Expand Up @@ -499,6 +534,9 @@ GEM
typesafe_enum (0.3.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicode-types (1.10.0)
uri (1.0.2)
vcr (6.3.1)
Expand Down Expand Up @@ -588,6 +626,7 @@ DEPENDENCIES
rspec-rails
rspec_junit_formatter
rss
rubocop-rails-omakase
sassc-rails
selenium-webdriver
simplecov
Expand Down
110 changes: 108 additions & 2 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,109 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
load Gem.bin_path('bundler', 'bundle')
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../Gemfile", __dir__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, ".locked")
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_requirement
@bundler_requirement ||=
env_var_version ||
cli_arg_version ||
bundler_requirement_for(lockfile_version)
end

def bundler_requirement_for(version)
return "#{Gem::Requirement.default}.a" unless version

bundler_gem_version = Gem::Version.new(version)

bundler_gem_version.approximate_recommendation
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end
8 changes: 8 additions & 0 deletions bin/rubocop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"

# explicit rubocop config increases performance slightly while avoiding config confusion.
ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__))

load Gem.bin_path("rubocop", "rubocop")

0 comments on commit 08407c5

Please sign in to comment.