Skip to content

Commit cd81338

Browse files
authored
Rubocop todo fixes (#2004)
* Fix Style/HashTransformValues * Fix Lint/RedundantRequireStatement * Fix Lint/RedundantRequireStatement * Fix Style/MutableConstant * Fix Lint/DisjunctiveAssignmentInConstructor
1 parent fbeedb6 commit cd81338

File tree

11 files changed

+12
-48
lines changed

11 files changed

+12
-48
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@ Lint/AmbiguousBlockAssociation:
4747
Exclude:
4848
- 'spec/grape/dsl/routing_spec.rb'
4949

50-
# Offense count: 4
51-
Lint/DisjunctiveAssignmentInConstructor:
52-
Exclude:
53-
- 'lib/grape/namespace.rb'
54-
- 'lib/grape/path.rb'
55-
- 'lib/grape/router.rb'
56-
- 'lib/grape/router/pattern.rb'
57-
5850
# Offense count: 1
5951
# Cop supports --auto-correct.
6052
Lint/NonDeterministicRequireOrder:
@@ -67,12 +59,6 @@ Lint/RedundantCopDisableDirective:
6759
Exclude:
6860
- 'lib/grape/router/attribute_translator.rb'
6961

70-
# Offense count: 1
71-
# Cop supports --auto-correct.
72-
Lint/RedundantRequireStatement:
73-
Exclude:
74-
- 'lib/grape.rb'
75-
7662
# Offense count: 2
7763
# Cop supports --auto-correct.
7864
Lint/ToJSON:
@@ -144,12 +130,6 @@ Performance/InefficientHashSearch:
144130
Exclude:
145131
- 'spec/grape/validations/validators/values_spec.rb'
146132

147-
# Offense count: 1
148-
# Cop supports --auto-correct.
149-
Performance/RegexpMatch:
150-
Exclude:
151-
- 'lib/grape/middleware/versioner/path.rb'
152-
153133
# Offense count: 5
154134
# Cop supports --auto-correct.
155135
Style/EmptyLambdaParameter:
@@ -174,12 +154,6 @@ Style/ExpandPathArguments:
174154
Style/FormatStringToken:
175155
EnforcedStyle: template
176156

177-
# Offense count: 1
178-
# Cop supports --auto-correct.
179-
Style/HashTransformValues:
180-
Exclude:
181-
- 'lib/grape/api.rb'
182-
183157
# Offense count: 23
184158
# Cop supports --auto-correct.
185159
Style/IfUnlessModifier:
@@ -205,15 +179,6 @@ Style/MethodMissingSuper:
205179
Exclude:
206180
- 'lib/grape/router/attribute_translator.rb'
207181

208-
# Offense count: 5
209-
# Cop supports --auto-correct.
210-
# Configuration parameters: EnforcedStyle.
211-
# SupportedStyles: literals, strict
212-
Style/MutableConstant:
213-
Exclude:
214-
- 'lib/grape/middleware/versioner/header.rb'
215-
- 'lib/grape/router/route.rb'
216-
217182
# Offense count: 1
218183
# Cop supports --auto-correct.
219184
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* [#2002](https://github.com/ruby-grape/grape/pull/2002): Objects allocation optimization (lazy_lookup) - [@ericproulx](https://github.com/ericproulx).
99

1010
#### Fixes
11-
11+
* [#2004](https://github.com/ruby-grape/grape/pull/2004): Rubocop fixes - [@ericproulx](https://github.com/ericproulx).
1212
* [#1995](https://github.com/ruby-grape/grape/pull/1995): Fix: "undefined instance variables" and "method redefined" warnings - [@nbeyer](https://github.com/nbeyer).
1313
* [#1994](https://github.com/ruby-grape/grape/pull/1993): Fix typos in README - [@bellmyer](https://github.com/bellmyer).
1414
* [#1993](https://github.com/ruby-grape/grape/pull/1993): Lazy join allow header - [@ericproulx](https://github.com/ericproulx).

lib/grape.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
require 'active_support/dependencies/autoload'
2121
require 'active_support/notifications'
2222
require 'i18n'
23-
require 'thread'
2423

2524
I18n.load_path << File.expand_path('../grape/locale/en.yml', __FILE__)
2625

lib/grape/api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def evaluate_arguments(configuration, *args)
175175
if argument.respond_to?(:lazy?) && argument.lazy?
176176
argument.evaluate_from(configuration)
177177
elsif argument.is_a?(Hash)
178-
argument.map { |key, value| [key, evaluate_arguments(configuration, value).first] }.to_h
178+
argument.transform_values { |value| evaluate_arguments(configuration, value).first }
179179
elsif argument.is_a?(Array)
180180
evaluate_arguments(configuration, *argument)
181181
else

lib/grape/middleware/versioner/header.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ module Versioner
2626
# route.
2727
class Header < Base
2828
VENDOR_VERSION_HEADER_REGEX =
29-
/\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))?(?:\+([a-z0-9*\-.]+))?\z/
29+
/\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))?(?:\+([a-z0-9*\-.]+))?\z/.freeze
3030

31-
HAS_VENDOR_REGEX = /\Avnd\.[a-z0-9.\-_!#\$&\^]+/
32-
HAS_VERSION_REGEX = /\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))+/
31+
HAS_VENDOR_REGEX = /\Avnd\.[a-z0-9.\-_!#\$&\^]+/.freeze
32+
HAS_VERSION_REGEX = /\Avnd\.([a-z0-9.\-_!#\$&\^]+?)(?:-([a-z0-9*.]+))+/.freeze
3333

3434
def before
3535
strict_header_checks if strict?

lib/grape/middleware/versioner/path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def before
3636

3737
pieces = path.split('/')
3838
potential_version = pieces[1]
39-
return unless potential_version =~ options[:pattern]
39+
return unless potential_version&.match?(options[:pattern])
4040
throw :error, status: 404, message: '404 API Version Not Found' if options[:versions] && !options[:versions].find { |v| v.to_s == potential_version }
4141
env[Grape::Env::API_VERSION] = potential_version
4242
end

lib/grape/namespace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def self.joined_space_path(settings)
3838

3939
class JoinedSpaceCache < Grape::Util::Cache
4040
def initialize
41-
@cache ||= Hash.new do |h, joined_space|
41+
@cache = Hash.new do |h, joined_space|
4242
h[joined_space] = -joined_space.join('/')
4343
end
4444
end

lib/grape/path.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def to_s
7575

7676
class PartsCache < Grape::Util::Cache
7777
def initialize
78-
@cache ||= Hash.new do |h, parts|
78+
@cache = Hash.new do |h, parts|
7979
h[parts] = -parts.join('/')
8080
end
8181
end

lib/grape/router.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(pattern, regexp, index, **attributes)
1919

2020
class NormalizePathCache < Grape::Util::Cache
2121
def initialize
22-
@cache ||= Hash.new do |h, path|
22+
@cache = Hash.new do |h, path|
2323
normalized_path = +"/#{path}"
2424
normalized_path.squeeze!('/')
2525
normalized_path.sub!(%r{/+\Z}, '')

lib/grape/router/pattern.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def extract_capture(requirements: {}, **options)
5757

5858
class PatternCache < Grape::Util::Cache
5959
def initialize
60-
@cache ||= Hash.new do |h, (pattern, suffix)|
60+
@cache = Hash.new do |h, (pattern, suffix)|
6161
h[[pattern, suffix]] = -"#{pattern}#{suffix}"
6262
end
6363
end

0 commit comments

Comments
 (0)