Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require:
plugins:
- rubocop-rails
- rubocop-performance
- rubocop-rspec
- rubocop-factory_bot
require:
- ./lib/rubocop/cop/root_cops/avoid_ruby_prof.rb
- ./lib/rubocop/cop/root_cops/eq_be_eql.rb
- ./lib/rubocop/cop/root_cops/factories/factory_file_name.rb
Expand Down Expand Up @@ -93,6 +95,9 @@ Rails/FilePath:
RSpec:
Enabled: true

RSpec/BeEq:
Enabled: false

RSpec/ContextWording:
Enabled: false

Expand Down Expand Up @@ -193,7 +198,7 @@ RootCops/MustInherit:
RootCops/MustInclude:
Enabled: false

RSpec/FactoryBot/CreateList:
FactoryBot/CreateList:
Enabled: false

Lint/ConstantDefinitionInBlock:
Expand Down
59 changes: 34 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
PATH
remote: .
specs:
root-ruby-style (0.0.17)
root-ruby-style (0.0.18)
activesupport (>= 5.0, < 8)
rubocop (> 1.60)
rubocop-performance (= 1.5.2)
rubocop-rails (~> 2.12.0)
rubocop-rspec (~> 1.38.1)
rubocop (~> 1.75)
rubocop-factory_bot (~> 2.27.1)
rubocop-performance (~> 1.25.0)
rubocop-rails (~> 2.31.0)
rubocop-rspec (~> 3.6.0)

GEM
remote: https://rubygems.org/
Expand All @@ -27,11 +28,11 @@ GEM
base64 (0.2.0)
benchmark (0.4.0)
bigdecimal (3.1.9)
byebug (11.1.3)
byebug (12.0.0)
coderay (1.1.3)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
diff-lcs (1.5.1)
connection_pool (2.5.1)
diff-lcs (1.6.1)
drb (2.2.1)
i18n (1.14.7)
concurrent-ruby (~> 1.0)
Expand All @@ -41,26 +42,26 @@ GEM
logger (1.7.0)
method_source (1.1.0)
minitest (5.25.5)
parallel (1.26.3)
parser (3.3.7.4)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
prism (1.4.0)
pry (0.14.2)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
pry-byebug (3.11.0)
byebug (~> 12.0)
pry (>= 0.13, < 0.16)
racc (1.8.1)
rack (3.1.12)
rack (3.1.13)
rainbow (3.1.1)
regexp_parser (2.10.0)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.2)
rspec-core (3.13.3)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
diff-lcs (>= 1.2.0, < 2.0)
Expand All @@ -80,17 +81,25 @@ GEM
rubocop-ast (>= 1.44.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.44.0)
rubocop-ast (1.44.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-performance (1.5.2)
rubocop (>= 0.71.0)
rubocop-rails (2.12.4)
rubocop-factory_bot (2.27.1)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
rubocop-performance (1.25.0)
lint_roller (~> 1.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rails (2.31.0)
activesupport (>= 4.2.0)
lint_roller (~> 1.1)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rspec (1.38.1)
rubocop (>= 0.68.1)
rubocop (>= 1.75.0, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rspec (3.6.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
ruby-progressbar (1.13.0)
securerandom (0.4.1)
tzinfo (2.0.6)
Expand All @@ -106,7 +115,7 @@ PLATFORMS
DEPENDENCIES
pry-byebug
root-ruby-style!
rspec (~> 3.8)
rspec (~> 3.13)

BUNDLED WITH
2.2.22
2.6.8
6 changes: 3 additions & 3 deletions lib/rubocop/cop/root_cops/avoid_ruby_prof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
module RuboCop
module Cop
module RootCops
class AvoidRubyProf < Cop
class AvoidRubyProf < RuboCop::Cop::Base
ERROR = ":ruby_prof is for local use only and should not be committed."
FILE_NAME_MATCHER = /_spec\.rb\z/

def_node_matcher :spec_block?, <<~PATTERN
(send nil? {:describe :context :it} ...)
PATTERN

def investigate(processed_source)
def on_new_investigation
@in_spec_file = processed_source.file_path =~ FILE_NAME_MATCHER
end

def on_sym(node)
return unless @in_spec_file && node.value == :ruby_prof && spec_block?(node.parent)

add_offense(node, location: :expression, message: ERROR)
add_offense(node.loc.expression, message: ERROR)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/root_cops/envvar_assignment.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module RuboCop
module Cop
module RootCops
class EnvvarAssignment < Cop
class EnvvarAssignment < RuboCop::Cop::Base
MSG = "Do not assign an ENVVAR to a constant. Assigning an ENVVAR to a constant has unexpected behavior when used with set_environment_variable. Instead, return the ENVVAR from a method".freeze

def_node_search :envvar_assignment?, "(send (const _ :ENVVARS) :[] (:str _))"

def investigate(processed_source)
def on_new_investigation
file_path = processed_source.file_path
@is_initializer_file = file_path.include?("/initializers/")
end
Expand All @@ -17,7 +17,7 @@ def on_casgn(node)
return if value.nil?
return if @is_initializer_file

add_offense(node, location: :expression, message: MSG) if envvar_assignment?(value)
add_offense(node.loc.expression, message: MSG) if envvar_assignment?(value)
end

def on_or_asgn(node)
Expand All @@ -26,7 +26,7 @@ def on_or_asgn(node)
return unless lhs&.casgn_type?
return if @is_initializer_file

add_offense(node, location: :expression, message: MSG) if envvar_assignment?(value)
add_offense(node.loc.expression, message: MSG) if envvar_assignment?(value)
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/root_cops/eq_be_eql.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module RootCops
class EqBeEql < ::RuboCop::Cop::Cop
class EqBeEql < ::RuboCop::Cop::Base
MSG = "Prefer `eq` over `be` and `eql` when checking booleans, numbers, symbols, strings and nil".freeze

def_node_matcher :be_or_eql, <<-PATTERN
Expand All @@ -19,11 +19,11 @@ class EqBeEql < ::RuboCop::Cop::Cop

def on_send(node)
be_or_eql(node) do |offending_node|
add_offense(offending_node, location: :selector)
add_offense(offending_node.loc.selector)
end

be_true_false_nil(node) do |offending_node|
add_offense(offending_node, location: :selector)
add_offense(offending_node.loc.selector)
end
end
end
Expand Down
7 changes: 3 additions & 4 deletions lib/rubocop/cop/root_cops/factories/factory_file_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ module RuboCop
module Cop
module RootCops
module Factories
class FactoryFileName < Cop
def investigate(processed_source)
class FactoryFileName < RuboCop::Cop::Base
def on_new_investigation
file_path = processed_source.buffer.name
@base_file_name = File.basename(file_path, ".rb")
@base_file_name_last_word = @base_file_name.split("_").last
Expand All @@ -18,8 +18,7 @@ def on_send(node)

if receiver_name == :FactoryBot && method_name == :define && Helpers::Factories.file_name_has_error?(@base_file_name)
add_offense(
node,
location: :expression,
node.loc.expression,
severity: :fatal,
message: "Factory file name should be plural (#{@base_file_name.pluralize})."
)
Expand Down
10 changes: 4 additions & 6 deletions lib/rubocop/cop/root_cops/factories/factory_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module RuboCop
module Cop
module RootCops
module Factories
class FactoryName < Cop
class FactoryName < RuboCop::Cop::Base
SYSTEM_IN_PATH = %r{systems/([^/]+)/}

def investigate(processed_source)
def on_new_investigation
file_path = processed_source.buffer.name
system_name_match = file_path.match(SYSTEM_IN_PATH)

Expand Down Expand Up @@ -36,16 +36,14 @@ def on_send(node)
if factory_name_array.size > 1
if factory_name_array[0] != @base_file_name
add_offense(
node,
location: :expression,
node.loc.expression,
message: "Factory name uses incorrect prefix, should be '#{@base_file_name}__#{factory_name_array[1]}'."
)
end

elsif (factory_name_body != @base_file_name_body) || (factory_name_last_word.pluralize != @base_file_name_last_word)
add_offense(
node,
location: :expression,
node.loc.expression,
message: "Factory should be in own file or be named the singular form of the file name. OR group closely related factories in the same file and prefix their names with '#{@base_file_name}__'."
)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/root_cops/job_has_queue.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RuboCop
module Cop
module RootCops
class JobHasQueue < Cop
class JobHasQueue < RuboCop::Cop::Base
MESSAGE = "Configure the job to run in a specific queue using queue_as, sharded_queue_as or a whitelisted mixin.".freeze
MIXIN_ALLOW_LIST = %i[LookupQueueConcern NewBusinessQuoteCreationQueueConcern PricingBackfillQueueConcern RatesQueueConcern MonitoringConcern].freeze
QUEUEING_OPTIONS = %i[queue_as sharded_queue_as].freeze
Expand All @@ -12,7 +12,7 @@ def on_class(node)

send_descendants = node.descendants.select(&:send_type?)
unless send_descendants.any? { |d| QUEUEING_OPTIONS.include?(d.to_a[1]) || _whitelisted_mixin?(d) }
add_offense(node, location: :expression, message: MESSAGE)
add_offense(node.loc.expression, message: MESSAGE)
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/rubocop/cop/root_cops/must_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ module RootCops
# include ClaimsJobConcern
# end

class MustInclude < Cop
class MustInclude < RuboCop::Cop::Base
# entirely so i can stub this in the tests
def self.expand_path(filename)
File.expand_path(filename)
end

def investigate(processed_source)
def on_new_investigation
@source_file_path = self.class.expand_path(processed_source.buffer.name)
@module_to_include = module_to_include_for_current_file
@proper_module_is_included = false
@class_node = nil
end

def investigate_post_walk(_processed_source)
def on_investigation_end
if search_for_inclusion? && !@proper_module_is_included
add_offense(@class_node, location: :expression, message: "Classes in this directory must include #{@module_to_include} module")
add_offense(@class_node.loc.expression, message: "Classes in this directory must include #{@module_to_include} module")
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/root_cops/must_inherit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module RootCops
# - ResqueJob
# - ShoryukenJob

class MustInherit < Cop
class MustInherit < RuboCop::Cop::Base
# entirely so i can stub this in the tests
def self.expand_path(filename)
File.expand_path(filename)
end

def investigate(processed_source)
def on_new_investigation
@source_file_path = self.class.expand_path(processed_source.buffer.name)
end

Expand All @@ -41,7 +41,7 @@ def on_class(node)
class_name = node.identifier.const_name
superclass_name = node.parent_class&.const_name
unless class_name_match?(class_name, superclass_name, class_options)
add_offense(node, location: :expression, message: "Classes in this directory must inherit from #{class_options_to_s(class_options)}")
add_offense(node.loc.expression, message: "Classes in this directory must inherit from #{class_options_to_s(class_options)}")
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/root_cops/no_backfills_in_data_migration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RuboCop
module Cop
module RootCops
class NoBackfillsInDataMigration < Cop
class NoBackfillsInDataMigration < RuboCop::Cop::Base
ACTIVE_RECORD_REGEX = /ActiveRecord::Migration\[\d\.\d\]/
COLLAPSED_MIGRATION_CLASSNAME = "CollapsedMigrations".freeze
MESSAGE = "Backfills should happen outside of database migrations".freeze
Expand Down Expand Up @@ -43,7 +43,7 @@ def on_send(node)
return if @is_collapsed_migration_class && method_name.to_s == "execute"

if FORBIDDEN_METHODS.include?(method_name)
add_offense(node, location: :expression, message: MESSAGE)
add_offense(node.loc.expression, message: MESSAGE)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/root_cops/no_index_on_add_column.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module RuboCop
module Cop
module RootCops
class NoIndexOnAddColumn < Cop
class NoIndexOnAddColumn < RuboCop::Cop::Base
ACTIVE_RECORD_REGEX = /ActiveRecord::Migration\[\d\.\d\]/
COLLAPSED_MIGRATION_CLASSNAME = "CollapsedMigrations".freeze
MESSAGE = "Do not use :index option on add_column".freeze
Expand All @@ -23,7 +23,7 @@ def on_send(node)

keys = last.keys.collect(&:value)

add_offense(node, location: :expression, message: MESSAGE) if keys.include?(:index)
add_offense(node.loc.expression, message: MESSAGE) if keys.include?(:index)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/root_cops/no_tracers.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module RootCops
class NoTracers < ::RuboCop::Cop::Cop
class NoTracers < ::RuboCop::Cop::Base
MSG = "Remove all `Tracer` occurrences".freeze

def_node_matcher :tracer, <<-PATTERN
(send (const _ :Tracer) _)
PATTERN

def on_send(node)
add_offense(node, location: :selector) if tracer(node)
add_offense(node.loc.selector) if tracer(node)
end
end
end
Loading