Skip to content

Commit

Permalink
updated rubocop and fixed offending lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Mar 8, 2021
1 parent f075337 commit b826f61
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
8 changes: 6 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
require: rubocop-performance
require:
- rubocop-performance
- rubocop-rake
- rubocop-minitest

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
NewCops: enable

Layout:
Enabled: false
Expand Down
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ gem 'oj', require: false # false is for testing with or without it
gem 'puma'

group :test do
gem 'rubocop', '~> 0.82.0'
gem 'rubocop-performance', '~> 1.5.0'
gem 'rubocop', '~> 1.11', require: false
gem 'rubocop-performance', require: false
gem 'rubocop-rake', require: false
gem 'rubocop-minitest', require: false
gem 'simplecov', require: false
gem 'codecov', require: false
gem 'minitest'
Expand Down
30 changes: 20 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ GEM
docile (1.3.5)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
minitest (5.14.4)
minitest-reporters (1.4.3)
ansi
Expand All @@ -37,17 +36,26 @@ GEM
rack
rainbow (3.0.0)
rake (13.0.3)
regexp_parser (2.1.1)
rexml (3.2.4)
rubocop (0.82.0)
jaro_winkler (~> 1.5.1)
rubocop (1.11.0)
parallel (~> 1.10)
parser (>= 2.7.0.1)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-performance (1.5.2)
rubocop (>= 0.71.0)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.1)
parser (>= 2.7.1.5)
rubocop-minitest (0.10.3)
rubocop (>= 0.87, < 2.0)
rubocop-performance (1.10.1)
rubocop (>= 0.90.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rake (0.5.1)
rubocop
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
simplecov (0.21.2)
Expand All @@ -68,7 +76,7 @@ GEM
sinatra (= 2.1.0)
tilt (~> 2.0)
tilt (2.0.10)
unicode-display_width (1.7.0)
unicode-display_width (2.0.0)

PLATFORMS
x86_64-linux
Expand All @@ -83,8 +91,10 @@ DEPENDENCIES
puma
rack
rake
rubocop (~> 0.82.0)
rubocop-performance (~> 1.5.0)
rubocop (~> 1.11)
rubocop-minitest
rubocop-performance
rubocop-rake
simplecov
sinatra
sinatra-contrib
Expand Down
13 changes: 6 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Rake::TestTask.new(:test_main) do |t|
'test/**/shared_combo_test.rb')
end

Rake::TestTask.new(:test_extra_items) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/items_test.rb']
end

Rake::TestTask.new(:test_extra_headers) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/headers_test.rb']
Expand All @@ -34,11 +39,6 @@ Rake::TestTask.new(:test_extra_i18n) do |t|
t.test_files = FileList['test/**/i18n_test.rb']
end

Rake::TestTask.new(:test_extra_items) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/items_test.rb']
end

Rake::TestTask.new(:test_extra_overflow) do |t|
t.libs += %w[test lib]
t.test_files = FileList['test/**/overflow_test.rb']
Expand Down Expand Up @@ -84,8 +84,7 @@ task :test => [ :test_main,
if ENV['RUN_RUBOCOP'] == 'true'
require "rubocop/rake_task"
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = `git ls-files -z`.split("\x0") # limit rubocop to the files in the repo
t.requires << 'rubocop-performance'
t.options = `git ls-files | grep -E '\\.rb$'`.split("\n") # limit rubocop to the files in the repo
end
task :default => [:test, :rubocop]
else
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def series(size=@vars[:size])
(series = []) and size.empty? and return series
4.times{|i| (size[i]>=0 rescue nil) or raise(VariableError.new(self), "expected 4 items >= 0 in :size; got #{size.inspect}")}
[*0..size[0], *@page-size[1]..@page+size[2], *@last-size[3]+1..@last+1].sort!.each_cons(2) do |a, b|
if a<0 || a==b || a>@last # skip out of range and duplicates
if a<0 || a==b || a>@last; next # skip out of range and duplicates
elsif a+1 == b; series.push(a) # no gap -> no additions
elsif a+2 == b; series.push(a, a+1) # 1 page gap -> fill with missing page
else series.push(a, :gap) # n page gap -> add gap
Expand Down
2 changes: 1 addition & 1 deletion lib/pagy/countless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Pagy
class Countless < Pagy

# Merge and validate the options, do some simple arithmetic and set a few instance variables
def initialize(vars={})
def initialize(vars={}) # rubocop:disable Lint/MissingSuper
@vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) # default vars + cleaned vars (can be overridden)
{ items:1, outset:0, page:1 }.each do |k,min| # validate instance variables
(@vars[k] && instance_variable_set(:"@#{k}", @vars[k].to_i) >= min) \
Expand Down
1 change: 1 addition & 0 deletions lib/pagy/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class VariableError < ArgumentError
attr_reader :pagy

def initialize(pagy)
super
@pagy = pagy
end

Expand Down
10 changes: 5 additions & 5 deletions test/pagy/frontend_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@

it 'switches :locale according to @pagy_locale' do
Pagy::I18n.load({locale: 'de'}, {locale: 'en'}, {locale: 'nl'})
view.instance_variable_set(:'@pagy_locale', 'nl')
view.instance_variable_set(:@pagy_locale, 'nl')
_(view.pagy_t('pagy.item_name', count: 1)).must_equal "stuk"
view.instance_variable_set(:'@pagy_locale', 'en')
view.instance_variable_set(:@pagy_locale, 'en')
_(view.pagy_t('pagy.item_name', count: 1)).must_equal "item"
view.instance_variable_set(:'@pagy_locale', nil)
view.instance_variable_set(:@pagy_locale, nil)
_(view.pagy_t('pagy.item_name', count: 1)).must_equal "Eintrag"
view.instance_variable_set(:'@pagy_locale', 'unknown')
view.instance_variable_set(:@pagy_locale, 'unknown')
_(view.pagy_t('pagy.item_name', count: 1)).must_equal "Eintrag" # silently serves the first loaded locale
Pagy::I18n.load(locale: 'en') # reset for other tests
view.instance_variable_set(:'@pagy_locale', nil) # reset for other tests
view.instance_variable_set(:@pagy_locale, nil) # reset for other tests
end

end
Expand Down

0 comments on commit b826f61

Please sign in to comment.