Skip to content

Commit bf4d55c

Browse files
committed
Upgraded RuboCop.
1 parent f949bd6 commit bf4d55c

File tree

12 files changed

+140
-60
lines changed

12 files changed

+140
-60
lines changed

.github/workflows/danger.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ jobs:
99
uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.0
1010
secrets: inherit
1111
with:
12-
ruby-version: '2.7'
12+
ruby-version: '3.4'
1313
bundler-cache: true

.github/workflows/rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ jobs:
88
- name: Set up Ruby
99
uses: ruby/setup-ruby@v1
1010
with:
11-
ruby-version: 2.7
11+
ruby-version: 3.4
1212
bundler-cache: true
1313
- run: bundle exec rubocop

.github/workflows/test.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@ jobs:
99
fail-fast: false
1010
matrix:
1111
entry:
12-
- { ruby: '2.7.1', mongo: 'mongo:4.4', mongoid: '5' }
12+
- { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '5' }
1313
# - { ruby: 'jruby-9.1.17.0', mongo: 'mongo:4.4', mongoid: '5' }
1414
- { ruby: 'jruby-9.4.13.0', mongo: 'mongo:4.4', mongoid: '5' }
15-
- { ruby: '2.7.1', mongo: 'mongo:4.4', mongoid: '6' }
1615
- { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '6' }
1716
- { ruby: '3.1.3', mongo: 'mongo:4.4', mongoid: '6' }
1817
- { ruby: 'jruby-9.4.13.0', mongo: 'mongo:4.4', mongoid: '6' }
19-
- { ruby: '2.7.1', mongo: 'mongo:4.4', mongoid: '7', coverage: 'true' }
20-
- { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '7' }
18+
- { ruby: '3.0.5', mongo: 'mongo:4.4', mongoid: '7', coverage: 'true' }
2119
- { ruby: '3.1.3', mongo: 'mongo:4.4', mongoid: '7' }
2220
# - { ruby: 'jruby-9.4.13.0', mongo: 'mongo:4.4', mongoid: '7' }
23-
- { ruby: '2.7.1', mongo: 'mongo:6.0', mongoid: '8' }
24-
- { ruby: '2.7.1', mongo: 'mongo:7.0', mongoid: '8' }
2521
- { ruby: '3.0.5', mongo: 'mongo:6.0', mongoid: '8' }
2622
- { ruby: '3.1.3', mongo: 'mongo:7.0', mongoid: '8' }
2723
- { ruby: '3.1.3', mongo: 'mongo:8.0', mongoid: '9' }

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
--require spec_helper
2+
--format documentation

.rubocop.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
AllCops:
2+
SuggestExtensions: true
3+
NewCops: enable
4+
15
Lint/RaiseException:
26
Enabled: true
37

@@ -21,4 +25,6 @@ RSpec/LeakyConstantDeclaration:
2125

2226
inherit_from: .rubocop_todo.yml
2327

24-
require: rubocop-rspec
28+
plugins:
29+
- rubocop-rspec
30+
- rubocop-rake

.rubocop_todo.yml

Lines changed: 107 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,182 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-04-07 15:05:45 -0400 using RuboCop version 0.81.0.
3+
# on 2025-12-31 23:55:39 UTC using RuboCop version 1.81.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 3
10-
# Configuration parameters: Include.
11-
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
12-
Bundler/DuplicatedGem:
9+
# Offense count: 1
10+
# Configuration parameters: Severity.
11+
Gemspec/RequiredRubyVersion:
1312
Exclude:
14-
- 'Gemfile'
13+
- 'mongoid-locker.gemspec'
1514

16-
# Offense count: 4
17-
# Configuration parameters: IgnoredMethods.
18-
Metrics/AbcSize:
19-
Max: 24
15+
# Offense count: 6
16+
# Configuration parameters: AllowedMethods.
17+
# AllowedMethods: enums
18+
Lint/ConstantDefinitionInBlock:
19+
Exclude:
20+
- 'spec/support/configurations_shared_context.rb'
21+
- 'spec/test_examples_spec.rb'
2022

21-
# Offense count: 11
22-
# Configuration parameters: CountComments, ExcludedMethods.
23-
# ExcludedMethods: refine
24-
Metrics/BlockLength:
25-
Max: 290
23+
# Offense count: 8
24+
# Configuration parameters: AllowComments, AllowEmptyLambdas.
25+
Lint/EmptyBlock:
26+
Exclude:
27+
- 'spec/support/locker_is_included_shared_examples.rb'
2628

27-
# Offense count: 5
28-
# Configuration parameters: CountComments, ExcludedMethods.
29+
# Offense count: 3
30+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
31+
Metrics/AbcSize:
32+
Max: 27
33+
34+
# Offense count: 6
35+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
2936
Metrics/MethodLength:
3037
Max: 31
3138

3239
# Offense count: 1
33-
# Configuration parameters: CountComments.
40+
# Configuration parameters: CountComments, CountAsOne.
3441
Metrics/ModuleLength:
35-
Max: 105
42+
Max: 109
3643

3744
# Offense count: 2
38-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
45+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
46+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
3947
# 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
4048
Naming/FileName:
4149
Exclude:
50+
- 'Rakefile.rb'
4251
- 'lib/mongoid-locker.rb'
4352
- 'spec/mongoid-locker_spec.rb'
4453

4554
# Offense count: 1
46-
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
47-
# NamePrefix: is_, has_, have_
48-
# ForbiddenPrefixes: is_, has_, have_
55+
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
56+
# AllowedMethods: call
57+
# WaywardPredicates: nonzero?
58+
Naming/PredicateMethod:
59+
Exclude:
60+
- 'lib/mongoid/locker/wrapper.rb'
61+
62+
# Offense count: 1
63+
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs.
64+
# NamePrefix: is_, has_, have_, does_
65+
# ForbiddenPrefixes: is_, has_, have_, does_
4966
# AllowedMethods: is_a?
5067
# MethodDefinitionMacros: define_method, define_singleton_method
51-
Naming/PredicateName:
68+
Naming/PredicatePrefix:
5269
Exclude:
5370
- 'spec/**/*'
5471
- 'lib/mongoid/locker.rb'
5572

5673
# Offense count: 2
5774
RSpec/BeforeAfterAll:
5875
Exclude:
59-
- 'spec/spec_helper.rb'
60-
- 'spec/rails_helper.rb'
61-
- 'spec/support/**/*.rb'
76+
- '**/spec/spec_helper.rb'
77+
- '**/spec/rails_helper.rb'
78+
- '**/spec/support/**/*.rb'
6279
- 'spec/test_examples_spec.rb'
6380

6481
# Offense count: 1
82+
# Configuration parameters: IgnoredMetadata.
6583
RSpec/DescribeClass:
6684
Exclude:
85+
- '**/spec/features/**/*'
86+
- '**/spec/requests/**/*'
87+
- '**/spec/routing/**/*'
88+
- '**/spec/system/**/*'
89+
- '**/spec/views/**/*'
6790
- 'spec/test_examples_spec.rb'
6891

69-
# Offense count: 8
70-
# Configuration parameters: Max.
92+
# Offense count: 9
93+
# Configuration parameters: CountAsOne.
7194
RSpec/ExampleLength:
95+
Max: 11
96+
97+
# Offense count: 5
98+
# This cop supports unsafe autocorrection (--autocorrect-all).
99+
RSpec/IncludeExamples:
72100
Exclude:
101+
- 'spec/mongoid-locker_spec.rb'
73102
- 'spec/support/locker_is_included_shared_examples.rb'
74-
- 'spec/test_examples_spec.rb'
103+
- 'spec/support/locker_methods_shared_examples.rb'
75104

76-
# Offense count: 1
77-
# Configuration parameters: CustomTransform, IgnoreMethods.
78-
RSpec/FilePath:
105+
# Offense count: 2
106+
RSpec/LetSetup:
79107
Exclude:
80-
- 'spec/mongoid-locker_spec.rb'
108+
- 'spec/support/populate_database_shared_context.rb'
81109

82110
# Offense count: 12
83111
# Configuration parameters: .
84112
# SupportedStyles: have_received, receive
85113
RSpec/MessageSpies:
86114
EnforcedStyle: receive
87115

116+
# Offense count: 12
117+
# Configuration parameters: AllowSubject.
118+
RSpec/MultipleMemoizedHelpers:
119+
Max: 10
120+
121+
# Offense count: 2
122+
# Configuration parameters: AllowedPatterns.
123+
# AllowedPatterns: ^expect_, ^assert_
124+
RSpec/NoExpectationExample:
125+
Exclude:
126+
- 'spec/support/locker_is_included_shared_examples.rb'
127+
128+
# Offense count: 1
129+
RSpec/RemoveConst:
130+
Exclude:
131+
- 'spec/support/locker_helpers.rb'
132+
133+
# Offense count: 1
134+
# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata, InflectorPath, EnforcedInflector.
135+
# SupportedInflectors: default, active_support
136+
RSpec/SpecFilePathFormat:
137+
Exclude:
138+
- '**/spec/routing/**/*'
139+
- 'spec/mongoid-locker_spec.rb'
140+
88141
# Offense count: 1
89142
RSpec/SubjectStub:
90143
Exclude:
91144
- 'spec/support/delegated_methods_shared_examples.rb'
92145

146+
# Offense count: 1
147+
# This cop supports unsafe autocorrection (--autocorrect-all).
148+
Style/CollectionQuerying:
149+
Exclude:
150+
- 'lib/mongoid/locker.rb'
151+
93152
# Offense count: 2
153+
# Configuration parameters: AllowedConstants.
94154
Style/Documentation:
95155
Exclude:
96156
- 'spec/**/*'
97157
- 'test/**/*'
98158
- 'lib/mongoid/locker.rb'
99159

160+
# Offense count: 4
161+
# This cop supports unsafe autocorrection (--autocorrect-all).
162+
# Configuration parameters: AllowSplatArgument.
163+
Style/HashConversion:
164+
Exclude:
165+
- 'spec/support/locker_is_included_shared_examples.rb'
166+
- 'spec/support/locker_methods_shared_examples.rb'
167+
100168
# Offense count: 2
101-
# Cop supports --auto-correct.
102-
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
169+
# This cop supports unsafe autocorrection (--autocorrect-all).
170+
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.
103171
# SupportedStyles: predicate, comparison
104172
Style/NumericPredicate:
105173
Exclude:
106174
- 'spec/**/*'
107175
- 'lib/mongoid/locker.rb'
108176

109-
# Offense count: 35
110-
# Cop supports --auto-correct.
111-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
177+
# Offense count: 7
178+
# This cop supports safe autocorrection (--autocorrect).
179+
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
112180
# URISchemes: http, https
113181
Layout/LineLength:
114182
Max: 250

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
## Changelog
22

3-
### 2.2.1 (Next)
3+
### 2.3.0 (Next)
44

55
* [#109](https://github.com/mongoid/mongoid-locker/pull/109): Migrate Danger to use danger-pr-comment workflow - [@dblock](https://github.com/dblock).
6+
* [#109](https://github.com/mongoid/mongoid-locker/pull/109): Remove support for Ruby 2.x - [@dblock](https://github.com/dblock).
67
* Your contribution here.
78

89
### 2.2.0 (2025-06-22)

Gemfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
source 'https://rubygems.org'
44
gemspec
55

6-
case ENV['MONGOID_VERSION']
6+
case ENV.fetch('MONGOID_VERSION', nil)
77
when /^9/
88
gem 'mongoid', '~> 9.0'
99
when /^8/
@@ -34,7 +34,8 @@ group :development, :test do
3434
gem 'mongoid-compatibility'
3535
gem 'mongoid-history'
3636
gem 'rspec', '~> 3.9'
37-
gem 'rubocop', '0.81.0'
38-
gem 'rubocop-rspec', '1.38.1'
37+
gem 'rubocop', '1.81.1'
38+
gem 'rubocop-rake'
39+
gem 'rubocop-rspec'
3940
gem 'simplecov', require: false
4041
end

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Document-level optimistic locking for MongoDB via Mongoid. Mongoid-Locker is an
1212
**NOTE:** Please refer to [1-x-stable](https://github.com/mongoid/mongoid-locker/tree/1-x-stable) branch for `1.x.x` documentation. See the [UPGRADING](UPGRADING.md) guide and [CHANGELOG](CHANGELOG.md) for an overview of the changes.
1313

1414
[Tested](https://github.com/mongoid/mongoid-locker/actions) against:
15-
- MRI: `2.3.8`, `2.4.7`, `2.5.7`, `2.6.6`, `2.7.1`, `3.0.5`, `3.1.3`
15+
- MRI: `3.0.5`, `3.1.3`
1616
- JRuby `9.1.17.0`, `9.2.11.1`
1717
- Mongoid: `5`, `6`, `7`, `8`, `9`
1818

lib/mongoid/locker.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def secure_locking_name(_doc, opts)
4545
# @param opts [Hash] (see #with_lock)
4646
# @return [Float]
4747
def exponential_backoff(_doc, opts)
48-
2**opts[:attempt] + rand
48+
(2**opts[:attempt]) + rand
4949
end
5050

5151
# Returns time in seconds remaining to complete the lock of the provided document. Makes requests to the database.
@@ -115,7 +115,9 @@ def included(klass)
115115
klass.locking_name_generator = locking_name_generator
116116

117117
klass.delegate(*MODULE_METHODS, to: :class)
118-
klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map { |method| [method, "#{method}=".to_sym] } - %i[included reset! configure]), to: self)
118+
klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map do |method|
119+
[method, :"#{method}="]
120+
end - %i[included reset! configure]), to: self)
119121
end
120122
end
121123

@@ -202,7 +204,10 @@ def unlock_all
202204
# @param locking_name_generator [Symbol]
203205
def locker(**params)
204206
invalid_parameters = params.keys - Mongoid::Locker.singleton_class.const_get('MODULE_METHODS')
205-
raise Mongoid::Locker::Errors::InvalidParameter.new(self.class, invalid_parameters.first) unless invalid_parameters.empty?
207+
unless invalid_parameters.empty?
208+
raise Mongoid::Locker::Errors::InvalidParameter.new(self.class,
209+
invalid_parameters.first)
210+
end
206211

207212
params.each_pair do |key, value|
208213
send("#{key}=", value)
@@ -271,7 +276,10 @@ def acquire_lock(opts)
271276
opts[:attempt] += 1
272277
delay = self.class.send(backoff_algorithm, self, opts)
273278

274-
raise Errors::DocumentCouldNotGetLock.new(self.class, id) if delay >= maximum_backoff || opts[:attempt] >= opts[:retries]
279+
if delay >= maximum_backoff || opts[:attempt] >= opts[:retries]
280+
raise Errors::DocumentCouldNotGetLock.new(self.class,
281+
id)
282+
end
275283

276284
sleep delay
277285
end

0 commit comments

Comments
 (0)