Skip to content

Commit

Permalink
Add additional Rubocops and lint (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed Jul 16, 2020
1 parent 778816d commit 00a29eb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
8 changes: 8 additions & 0 deletions .rubocop.yml
@@ -1,6 +1,8 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-performance
- rubocop-rails
- rubocop-rspec

inherit_mode:
Expand Down Expand Up @@ -41,6 +43,12 @@ Metrics:
Naming/MemoizedInstanceVariableName:
EnforcedStyleForLeadingUnderscores: required

Rails/RakeEnvironment:
Enabled: false

Rails/ApplicationRecord:
Enabled: false

RSpec/AnyInstance:
Enabled: false

Expand Down
24 changes: 1 addition & 23 deletions .rubocop_todo.yml
@@ -1,29 +1,7 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-07-13 18:57:43 UTC using RuboCop version 0.88.0.
# on 2020-07-16 00:15:42 UTC using RuboCop version 0.88.0.
# 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: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
# AllowedMethods: alias_method, public, protected, private
Layout/EmptyLinesAroundAttributeAccessor:
Exclude:
- 'lib/good_job/lockable.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment:
Exclude:
- 'bin/lint'

# Offense count: 2
# Cop supports --auto-correct.
Style/RedundantRegexpEscape:
Exclude:
- 'spec/support/sql_helper.rb'
8 changes: 8 additions & 0 deletions Gemfile.lock
Expand Up @@ -187,6 +187,12 @@ GEM
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.1.0)
parser (>= 2.7.0.1)
rubocop-performance (1.7.0)
rubocop (>= 0.82.0)
rubocop-rails (2.6.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 0.82.0)
rubocop-rspec (1.42.0)
rubocop (>= 0.87.0)
ruby-progressbar (1.10.1)
Expand Down Expand Up @@ -223,6 +229,8 @@ DEPENDENCIES
pry
rspec-rails
rubocop
rubocop-performance
rubocop-rails
rubocop-rspec

BUNDLED WITH
Expand Down
2 changes: 2 additions & 0 deletions good_job.gemspec
Expand Up @@ -50,5 +50,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "pry"
spec.add_development_dependency "rspec-rails"
spec.add_development_dependency "rubocop"
spec.add_development_dependency "rubocop-performance"
spec.add_development_dependency "rubocop-rails"
spec.add_development_dependency "rubocop-rspec"
end
2 changes: 1 addition & 1 deletion lib/good_job/adapter.rb
Expand Up @@ -11,7 +11,7 @@ def enqueue(active_job)
def enqueue_at(active_job, timestamp)
good_job = GoodJob::Job.enqueue(
active_job,
scheduled_at: timestamp ? Time.at(timestamp) : nil,
scheduled_at: timestamp ? Time.zone.at(timestamp) : nil,
create_with_advisory_lock: inline?
)

Expand Down
9 changes: 7 additions & 2 deletions lib/good_job/lockable.rb
Expand Up @@ -37,14 +37,17 @@ module Lockable
scope :owns_advisory_locked, -> { joins_advisory_locks.where('"pg_locks"."pid" = pg_backend_pid()') }

attr_accessor :create_with_advisory_lock

after_create -> { advisory_lock }, if: :create_with_advisory_lock
end

class_methods do
def with_advisory_lock(&block)
def with_advisory_lock
raise ArgumentError, "Must provide a block" unless block_given?

records = advisory_lock.to_a
begin
block.call(records)
yield(records)
ensure
records.each(&:advisory_unlock)
end
Expand Down Expand Up @@ -73,6 +76,8 @@ def advisory_lock!
end

def with_advisory_lock
raise ArgumentError, "Must provide a block" unless block_given?

advisory_lock!
yield
ensure
Expand Down
2 changes: 1 addition & 1 deletion spec/support/sql_helper.rb
@@ -1,6 +1,6 @@
module SqlHelper
def normalize_sql(sql)
sql.gsub(/\s/, ' ').gsub(/([\(\)])/, ' \1 ').squish
sql.gsub(/\s/, ' ').gsub(/([()])/, ' \1 ').squish
end
end

Expand Down

0 comments on commit 00a29eb

Please sign in to comment.