Skip to content

Commit

Permalink
Upgraded rubocop to 1.66.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Sep 7, 2024
1 parent d660cd3 commit 1876d50
Show file tree
Hide file tree
Showing 19 changed files with 465 additions and 222 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: enable
Exclude:
- vendor/**/*
- gemfiles/vendor/**/*
185 changes: 152 additions & 33 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,58 +1,159 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-03-09 01:14:57 +0100 using RuboCop version 0.49.1.
# on 2024-09-07 13:11:15 UTC using RuboCop version 1.66.1.
# 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: 5
# Configuration parameters: Include.
# Include: **/Gemfile, **/gems.rb
Bundler/DuplicatedGem:
# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- 'Gemfile'
- 'mongoid-scroll.gemspec'

# Offense count: 8
Metrics/AbcSize:
Max: 38
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Lint/NonDeterministicRequireOrder:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 18
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 274
# Offense count: 7
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 28

# Offense count: 1
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 103
Max: 108

# Offense count: 5
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 13

# Offense count: 153
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 252

# Offense count: 7
# Configuration parameters: CountComments.
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 23
Max: 24

# Offense count: 4
# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 12
Max: 13

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Naming/FileName:
Exclude:
- 'Rakefile.rb'
- 'lib/mongoid-scroll.rb'

# Offense count: 3
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 34
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
- 'spec/mongoid/criteria_spec.rb'
- 'spec/mongoid/cursor_spec.rb'

# Offense count: 34
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
# SupportedStyles: described_class, explicit
RSpec/DescribedClass:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
- 'spec/mongoid/cursor_spec.rb'

# Offense count: 17
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 18

# Offense count: 3
# Configuration parameters: Max, AllowedIdentifiers, AllowedPatterns.
RSpec/IndexedLet:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 2
# Configuration parameters: AssignmentOnly.
RSpec/InstanceVariable:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 11
RSpec/MultipleExpectations:
Max: 4

# Offense count: 4
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
# SupportedStyles: always, named_only
RSpec/NamedSubject:
Exclude:
- 'spec/mongoid/criteria_spec.rb'

# Offense count: 3
# Configuration parameters: AllowedGroups.
RSpec/NestedGroups:
Max: 4

# Offense count: 3
# Configuration parameters: AllowedPatterns.
# AllowedPatterns: ^expect_, ^assert_
RSpec/NoExpectationExample:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'

# Offense count: 4
RSpec/RepeatedDescription:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'

# Offense count: 4
RSpec/RepeatedExample:
Exclude:
- 'spec/mongoid/base64_encoded_cursor_spec.rb'

# Offense count: 3
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
# Include: **/*_spec.rb
RSpec/SpecFilePathFormat:
Exclude:
- '**/spec/routing/**/*'
- 'spec/mongoid/base64_encoded_cursor_spec.rb'
- 'spec/mongoid/cursor_spec.rb'
- 'spec/mongoid/scroll_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Rake/Desc:
Exclude:
- 'Rakefile'

# Offense count: 12
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
- 'spec/**/*'
- 'test/**/*'
- 'examples/feed.rb'
- 'lib/mongoid/criteria/scrollable.rb'
- 'lib/mongoid/criteria/scrollable/iterator.rb'
- 'lib/mongoid/scroll/base_cursor.rb'
- 'lib/mongoid/scroll/cursor.rb'
- 'lib/mongoid/scroll/errors/base.rb'
Expand All @@ -61,22 +162,40 @@ Style/Documentation:
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'
- 'lib/mongoid/scroll/errors/no_such_field_error.rb'
- 'lib/mongoid/scroll/errors/unsupported_field_type_error.rb'
- 'lib/mongoid/scroll/errors/unsupported_type_error.rb'

# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Style/FileName:
Exclude:
- 'lib/mongoid-scroll.rb'
# Offense count: 34
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
Style/MultilineTernaryOperator:
Exclude:
- 'lib/mongoid/scroll/cursor.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedCompactTypes.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
EnforcedStyle: compact

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- 'lib/mongoid/scroll/errors/mismatched_sort_fields_error.rb'
- 'lib/mongoid/scroll/errors/multiple_sort_fields_error.rb'

# Offense count: 36
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 252
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#43](https://github.com/mongoid/mongoid-scroll/pull/43): Add `current_cursor` - [@GCorbel](https://github.com/GCorbel).
* [#44](https://github.com/mongoid/mongoid-scroll/pull/44): Drop support for Mogoid 5 and Mongo Ruby Driver - [@dblock](https://github.com/dblock).
* [#45](https://github.com/mongoid/mongoid-scroll/pull/45): Add support for Mogoid 9 - [@dblock](https://github.com/dblock).
* [#46](https://github.com/mongoid/mongoid-scroll/pull/46): Upgrade RuboCop to 1.66.1 - [@dblock](https://github.com/dblock).
* Your contribution here.

### 1.0.1 (2023/03/15)
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ group :development, :test do
gem 'rake'
gem 'rspec', '~> 3.0'
gem 'rspec-its'
gem 'rubocop', '0.49.1'
gem 'rubocop', '1.66.1'
gem 'rubocop-rake'
gem 'rubocop-rspec'
end
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'rubygems'
require 'bundler/gem_tasks'

require File.expand_path('../lib/mongoid/scroll/version', __FILE__)
require File.expand_path('lib/mongoid/scroll/version', __dir__)

begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts 'Run `bundle install` to install missing gems'
warn e.message
warn 'Run `bundle install` to install missing gems'
exit e.status_code
end

Expand Down
3 changes: 2 additions & 1 deletion examples/feed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Item
scroll_by = 7

# insert items with a position out-of-order
rands = (0..total_items).to_a.sort { rand }[0..total_items]
rands = (0..total_items).to_a.sort { |_l, _r| rand }[0..total_items]
total_items.times do |_i|
Feed::Item.create! title: Faker::Lorem.sentence, position: rands.pop
end
Expand All @@ -42,6 +42,7 @@ class Item
total_shown += 1
end
break unless next_cursor

# destroy an item just for the heck of it, scroll is not affected
Feed::Item.asc(:position).first.destroy
end
Expand Down
4 changes: 2 additions & 2 deletions lib/mongoid/criteria/scrollable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def scroll(cursor_or_type = nil, &_block)
criteria = dup
criteria.merge!(default_sort) if no_sort_option?
cursor_options = build_cursor_options(criteria)
cursor = cursor.is_a?(cursor_type) ? cursor : new_cursor(cursor_type, cursor, cursor_options)
cursor = new_cursor(cursor_type, cursor, cursor_options) unless cursor.is_a?(cursor_type)
raise_mismatched_sort_fields_error!(cursor, cursor_options) if different_sort_fields?(cursor, cursor_options)
records = find_records(criteria, cursor)
if block_given?
Expand Down Expand Up @@ -99,4 +99,4 @@ def scroll_field_type(criteria)
end
end

Mongoid::Criteria.send(:include, Mongoid::Criteria::Scrollable)
Mongoid::Criteria.include Mongoid::Criteria::Scrollable
8 changes: 4 additions & 4 deletions lib/mongoid/scroll/base64_encoded_cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ def initialize(value, options = {})
if value
begin
parsed = ::JSON.parse(::Base64.strict_decode64(value))
rescue
rescue StandardError
raise Mongoid::Scroll::Errors::InvalidBase64CursorError.new(cursor: value)
end
super parse_field_value(parsed['field_type'], parsed['field_name'], parsed['value']), {
super(parse_field_value(parsed['field_type'], parsed['field_name'], parsed['value']), {
field_type: parsed['field_type'],
field_name: parsed['field_name'],
direction: parsed['direction'],
include_current: parsed['include_current'],
tiebreak_id: parsed['tiebreak_id'] && !parsed['tiebreak_id'].empty? ? BSON::ObjectId.from_string(parsed['tiebreak_id']) : nil,
type: parsed['type'].try(:to_sym)
}
})
else
super nil, options
super(nil, options)
end
end

Expand Down
5 changes: 2 additions & 3 deletions lib/mongoid/scroll/base_cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(value, options = {})
@include_current = options[:include_current] || false
@type = options[:type] || :next

raise Mongoid::Scroll::Errors::UnsupportedTypeError.new(type: @type) if ![:previous, :next].include?(@type)
raise Mongoid::Scroll::Errors::UnsupportedTypeError.new(type: @type) unless %i[previous next].include?(@type)
end

def criteria
Expand Down Expand Up @@ -72,8 +72,7 @@ def transform_field_value(field_type, field_name, value)
return nil unless value

case field_type.to_s
when 'BSON::ObjectId' then value.to_s
when 'String' then value.to_s
when 'BSON::ObjectId', 'String' then value.to_s
when 'Date' then Time.utc(value.year, value.month, value.day).to_i
when 'DateTime', 'Time' then value.utc.to_f.round(3)
when 'Float' then value.to_f
Expand Down
10 changes: 5 additions & 5 deletions lib/mongoid/scroll/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ class Cursor < BaseCursor
def initialize(value = nil, options = {})
options = extract_field_options(options)
raise ArgumentError.new 'Missing options[:field_name] and/or options[:field_type].' unless options

if value
parts = value.split(':') if value
unless parts && parts.length >= 2
raise Mongoid::Scroll::Errors::InvalidCursorError.new(cursor: value)
end
raise Mongoid::Scroll::Errors::InvalidCursorError.new(cursor: value) unless parts && parts.length >= 2

value = parse_field_value(
options[:field_type],
options[:field_name],
parts[0...-1].join(':')
)
options[:tiebreak_id] = BSON::ObjectId.from_string(parts[-1])
super value, options
super
else
super nil, options
super(nil, options)
end
end

Expand Down
Loading

0 comments on commit 1876d50

Please sign in to comment.