Skip to content

Commit

Permalink
Cleanup rubocop violations
Browse files Browse the repository at this point in the history
Some important notes for this:

BlockLength cop was disabled completely because of a large amount of
violations in the specs.

DuplicatedGem cop was disabled completely because we are using
conditionals to determine Gem versions and it was being triggered. I
don't see any other options for this cop so it looks like the only
option is to ignore.

YAMLLoad wants to use safe_load over load.  Not sure that's supported on
older versions

A few cops were disabled in specific code locations because I did not
know enough about the code to update and be sure that there was no risk.
  • Loading branch information
atomaka committed Mar 15, 2017
1 parent 758d17f commit 740bbca
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 25 deletions.
14 changes: 12 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ AllCops:
RedundantBlockCall:
Enabled: false

BlockLength:
Enabled: false

# Avoid more than `Max` levels of nesting.
BlockNesting:
Max: 2

# Indentation of when/else
CaseIndentation:
IndentWhenRelativeTo: end
EnforcedStyle: end
IndentOneStep: false

ClassLength:
Expand All @@ -49,6 +52,10 @@ DotPosition:
DoubleNegation:
Enabled: false

# Detects any duplication as issue including our conditional requires
DuplicatedGem:
Enabled: false

EmptyLinesAroundAccessModifier:
Enabled: true

Expand All @@ -58,7 +65,7 @@ Encoding:

# Align ends correctly
EndAlignment:
AlignWith: variable
EnforcedStyleAlignWith: variable

# Enforce Ruby 1.8-compatible hash syntax
HashSyntax:
Expand Down Expand Up @@ -119,5 +126,8 @@ TrailingCommaInLiteral:
TrailingCommaInArguments:
Enabled: false

YAMLLoad:
Enabled: false

ZeroLengthPredicate:
Enabled: false
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ group :test do

gem 'coveralls', :require => false
gem 'rspec', '>= 3'
gem 'rubocop', '0.25'
gem 'rubocop', '>= 0.25'
gem 'simplecov', '>= 0.9'
end

Expand Down
11 changes: 4 additions & 7 deletions lib/delayed/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ def reserve(worker, max_run_time = Worker.max_run_time)
end

# Allow the backend to attempt recovery from reserve errors
def recover_from(_error)
end
def recover_from(_error); end

# Hook method that is called before a new worker is forked
def before_fork
end
def before_fork; end

# Hook method that is called after a new worker is forked
def after_fork
end
def after_fork; end

def work_off(num = 100)
warn '[DEPRECATION] `Delayed::Job.work_off` is deprecated. Use `Delayed::Worker.new.work_off instead.'
Expand Down Expand Up @@ -101,7 +98,7 @@ def unlock
def hook(name, *args)
if payload_object.respond_to?(name)
method = payload_object.method(name)
method.arity == 0 ? method.call : method.call(self, *args)
method.arity.zero? ? method.call : method.call(self, *args)
end
rescue DeserializationError # rubocop:disable HandleExceptions
end
Expand Down
2 changes: 2 additions & 0 deletions lib/delayed/backend/job_preparer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ def handle_deprecation
options[:run_at] = args[1]
end

# rubocop:disable GuardClause
unless options[:payload_object].respond_to?(:perform)
raise ArgumentError, 'Cannot enqueue items which do not respond to perform'
end
# rubocop:enabled GuardClause
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/delayed/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ def daemonize # rubocop:disable PerceivedComplexity
if worker_pools
setup_pools
elsif @options[:identifier]
# rubocop:disable GuardClause
if worker_count > 1
raise ArgumentError, 'Cannot specify both --number-of-workers and --identifier'
else
run_process("delayed_job.#{@options[:identifier]}", @options)
end
# rubocop:enable GuardClause
else
worker_count.times do |worker_index|
process_name = worker_count == 1 ? 'delayed_job' : "delayed_job.#{worker_index}"
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def message
end
end

class FatalBackendError < Exception; end
class FatalBackendError < RuntimeError; end
end
2 changes: 1 addition & 1 deletion lib/delayed/lifecycle.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Delayed
class InvalidCallback < Exception; end
class InvalidCallback < RuntimeError; end

class Lifecycle
EVENTS = {
Expand Down
2 changes: 2 additions & 0 deletions lib/delayed/message_sending.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ def initialize(payload_class, target, options)
@options = options
end

# rubocop:disable MethodMissing
def method_missing(method, *args)
Job.enqueue({:payload_object => @payload_class.new(@target, method.to_sym, args)}.merge(@options))
end
# rubocop:enable MethodMissing
end

module MessageSending
Expand Down
2 changes: 2 additions & 0 deletions lib/delayed/performable_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def method(sym)
object.method(sym)
end

# rubocop:disable MethodMissing
def method_missing(symbol, *args)
object.send(symbol, *args)
end
# rubocop:enable MethodMissing

def respond_to?(symbol, include_private = false)
super || object.respond_to?(symbol, include_private)
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/delayed_job/delayed_job_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ class DelayedJobGenerator < Rails::Generators::Base

def create_executable_file
template 'script', "#{Delayed::Compatibility.executable_prefix}/delayed_job"
chmod "#{Delayed::Compatibility.executable_prefix}/delayed_job", 0755
chmod "#{Delayed::Compatibility.executable_prefix}/delayed_job", 0o755
end
end
3 changes: 1 addition & 2 deletions spec/autoloaded/clazz.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Make sure this file does not get required manually
module Autoloaded
class Clazz
def perform
end
def perform; end
end
end
3 changes: 1 addition & 2 deletions spec/autoloaded/instance_clazz.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Autoloaded
class InstanceClazz
def perform
end
def perform; end
end
end
3 changes: 1 addition & 2 deletions spec/autoloaded/instance_struct.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Autoloaded
InstanceStruct = ::Struct.new(nil)
class InstanceStruct
def perform
end
def perform; end
end
end
3 changes: 1 addition & 2 deletions spec/autoloaded/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
module Autoloaded
Struct = ::Struct.new(nil)
class Struct
def perform
end
def perform; end
end
end
3 changes: 1 addition & 2 deletions spec/message_sending_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def tell; end
describe 'using a proc with parameters' do
class Yarn
attr_accessor :importance
def spin
end
def spin; end
handle_asynchronously :spin, :priority => proc { |y| y.importance }
end

Expand Down
3 changes: 1 addition & 2 deletions spec/performable_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

it 'does not raise NoMethodError if target method is private' do
clazz = Class.new do
def private_method
end
def private_method; end
private :private_method
end
expect { Delayed::PerformableMethod.new(clazz.new, :private_method, []) }.not_to raise_error
Expand Down

0 comments on commit 740bbca

Please sign in to comment.