Skip to content

Commit f1ec684

Browse files
committed
Upgraded to RuboCop 0.39.0.
1 parent e9c6885 commit f1ec684

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+215
-217
lines changed

.rubocop_todo.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2016-03-14 21:22:57 +0300 using RuboCop version 0.35.1.
3+
# on 2016-04-26 16:12:14 -0400 using RuboCop version 0.39.0.
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

99
# Offense count: 1
10-
Lint/NestedMethodDefinition:
10+
Lint/IneffectiveAccessModifier:
1111
Exclude:
12-
- 'lib/grape/util/strict_hash_configuration.rb'
12+
- 'lib/grape/router.rb'
1313

1414
# Offense count: 39
1515
Metrics/AbcSize:
@@ -19,29 +19,30 @@ Metrics/AbcSize:
1919
Metrics/BlockNesting:
2020
Max: 4
2121

22-
# Offense count: 6
22+
# Offense count: 7
2323
# Configuration parameters: CountComments.
2424
Metrics/ClassLength:
25-
Max: 281
25+
Max: 267
2626

2727
# Offense count: 24
2828
Metrics/CyclomaticComplexity:
2929
Max: 14
3030

31-
# Offense count: 853
32-
# Configuration parameters: AllowURI, URISchemes.
31+
# Offense count: 871
32+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
33+
# URISchemes: http, https
3334
Metrics/LineLength:
3435
Max: 215
3536

36-
# Offense count: 48
37+
# Offense count: 49
3738
# Configuration parameters: CountComments.
3839
Metrics/MethodLength:
39-
Max: 36
40+
Max: 34
4041

41-
# Offense count: 8
42+
# Offense count: 7
4243
# Configuration parameters: CountComments.
4344
Metrics/ModuleLength:
44-
Max: 277
45+
Max: 212
4546

4647
# Offense count: 15
4748
Metrics/PerceivedComplexity:
@@ -50,6 +51,10 @@ Metrics/PerceivedComplexity:
5051
# Offense count: 44
5152
# Cop supports --auto-correct.
5253
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
54+
# SupportedStyles: line_count_based, semantic, braces_for_chaining
55+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
56+
# FunctionalMethods: let, let!, subject, watch
57+
# IgnoredMethods: lambda, proc, it
5358
Style/BlockDelimiters:
5459
Exclude:
5560
- 'spec/grape/api_spec.rb'
@@ -58,7 +63,6 @@ Style/BlockDelimiters:
5863
- 'spec/grape/request_spec.rb'
5964

6065
# Offense count: 111
61-
# Configuration parameters: Exclude.
6266
Style/Documentation:
6367
Enabled: false
6468

@@ -70,7 +74,14 @@ Style/DoubleNegation:
7074
- 'lib/grape/middleware/versioner/header.rb'
7175
- 'lib/grape/path.rb'
7276

77+
# Offense count: 1
78+
# Configuration parameters: MinBodyLength.
79+
Style/GuardClause:
80+
Exclude:
81+
- 'lib/grape/endpoint.rb'
82+
7383
# Offense count: 14
7484
# Configuration parameters: EnforcedStyle, SupportedStyles.
85+
# SupportedStyles: compact, exploded
7586
Style/RaiseArgs:
7687
Enabled: false

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ gemspec
77
group :development, :test do
88
gem 'bundler'
99
gem 'rake'
10-
gem 'rubocop', '0.35.1'
10+
gem 'rubocop', '0.39.0'
1111
end
1212

1313
group :development do

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ task default: [:rubocop, :spec]
2525

2626
begin
2727
require 'yard'
28-
DOC_FILES = ['lib/**/*.rb', 'README.md']
28+
DOC_FILES = ['lib/**/*.rb', 'README.md'].freeze
2929

3030
YARD::Rake::YardocTask.new(:doc) do |t|
3131
t.files = DOC_FILES

lib/grape/dsl/headers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def header(key = nil, val = nil)
1010
@header ||= {}
1111
end
1212
end
13-
alias_method :headers, :header
13+
alias headers header
1414
end
1515
end
1616
end

lib/grape/dsl/inside_route.rb

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def declared(params, options = {}, declared_params = nil)
3131

3232
declared_params ||= (!options[:include_parent_namespaces] ? route_setting(:declared_params) : (route_setting(:saved_declared_params) || [])).flatten(1) || []
3333

34-
fail ArgumentError, 'Tried to filter for declared parameters but none exist.' unless declared_params
34+
raise ArgumentError, 'Tried to filter for declared parameters but none exist.' unless declared_params
3535

3636
if params.is_a? Array
3737
params.map do |param|
@@ -70,7 +70,7 @@ def declared(params, options = {}, declared_params = nil)
7070
# options. `:include_parent_namespaces` defaults to true, hence must be set to false if
7171
# you want only to return params declared against the current/target endpoint.
7272
def declared(*)
73-
fail MethodNotYetAvailable, '#declared is not available prior to parameter validation.'
73+
raise MethodNotYetAvailable, '#declared is not available prior to parameter validation.'
7474
end
7575

7676
# The API version as specified in the URL.
@@ -100,14 +100,12 @@ def redirect(url, options = {})
100100
if permanent
101101
status 301
102102
body_message ||= "This resource has been moved permanently to #{url}."
103+
elsif env[Grape::Http::Headers::HTTP_VERSION] == 'HTTP/1.1' && request.request_method.to_s.upcase != Grape::Http::Headers::GET
104+
status 303
105+
body_message ||= "An alternate resource is located at #{url}."
103106
else
104-
if env[Grape::Http::Headers::HTTP_VERSION] == 'HTTP/1.1' && request.request_method.to_s.upcase != Grape::Http::Headers::GET
105-
status 303
106-
body_message ||= "An alternate resource is located at #{url}."
107-
else
108-
status 302
109-
body_message ||= "This resource has been moved temporarily to #{url}."
110-
end
107+
status 302
108+
body_message ||= "This resource has been moved temporarily to #{url}."
111109
end
112110
header 'Location', url
113111
content_type 'text/plain'
@@ -120,11 +118,8 @@ def redirect(url, options = {})
120118
def status(status = nil)
121119
case status
122120
when Symbol
123-
if Rack::Utils::SYMBOL_TO_STATUS_CODE.keys.include?(status)
124-
@status = Rack::Utils.status_code(status)
125-
else
126-
fail ArgumentError, "Status code :#{status} is invalid."
127-
end
121+
raise ArgumentError, "Status code :#{status} is invalid." unless Rack::Utils::SYMBOL_TO_STATUS_CODE.keys.include?(status)
122+
@status = Rack::Utils.status_code(status)
128123
when Fixnum
129124
@status = status
130125
when nil
@@ -136,7 +131,7 @@ def status(status = nil)
136131
200
137132
end
138133
else
139-
fail ArgumentError, 'Status code must be Fixnum or Symbol.'
134+
raise ArgumentError, 'Status code must be Fixnum or Symbol.'
140135
end
141136
end
142137

@@ -260,7 +255,7 @@ def present(*args)
260255
if key
261256
representation = (@body || {}).merge(key => representation)
262257
elsif entity_class.present? && @body
263-
fail ArgumentError, "Representation of type #{representation.class} cannot be merged." unless representation.respond_to?(:merge)
258+
raise ArgumentError, "Representation of type #{representation.class} cannot be merged." unless representation.respond_to?(:merge)
264259
representation = @body.merge(representation)
265260
end
266261

lib/grape/dsl/parameters.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def use(*names)
3434
options = names.extract_options!
3535
names.each do |name|
3636
params_block = named_params.fetch(name) do
37-
fail "Params :#{name} not found!"
37+
raise "Params :#{name} not found!"
3838
end
3939
instance_exec(options, &params_block)
4040
end
4141
end
42-
alias_method :use_scope, :use
43-
alias_method :includes, :use
42+
alias use_scope use
43+
alias includes use
4444

4545
# Require one or more parameters for the current endpoint.
4646
#
@@ -121,8 +121,8 @@ def optional(*attrs, &block)
121121

122122
# check type for optional parameter group
123123
if attrs && block_given?
124-
fail Grape::Exceptions::MissingGroupTypeError.new if type.nil?
125-
fail Grape::Exceptions::UnsupportedGroupTypeError.new unless Grape::Validations::Types.group?(type)
124+
raise Grape::Exceptions::MissingGroupTypeError.new if type.nil?
125+
raise Grape::Exceptions::UnsupportedGroupTypeError.new unless Grape::Validations::Types.group?(type)
126126
end
127127

128128
if opts[:using]
@@ -167,7 +167,7 @@ def all_or_none_of(*attrs)
167167
# @yield a parameter definition DSL
168168
def given(*attrs, &block)
169169
attrs.each do |attr|
170-
fail Grape::Exceptions::UnknownParameter.new(attr) unless declared_param?(attr)
170+
raise Grape::Exceptions::UnknownParameter.new(attr) unless declared_param?(attr)
171171
end
172172
new_lateral_scope(dependent_on: attrs, &block)
173173
end
@@ -181,21 +181,21 @@ def declared_param?(param)
181181
@declared_params.flatten.include?(param)
182182
end
183183

184-
alias_method :group, :requires
184+
alias group requires
185185

186186
# @param params [Hash] initial hash of parameters
187187
# @return hash of parameters relevant for the current scope
188188
# @api private
189189
def params(params)
190190
params = @parent.params(params) if @parent
191191
if @element
192-
if params.is_a?(Array)
193-
params = params.flat_map { |el| el[@element] || {} }
194-
elsif params.is_a?(Hash)
195-
params = params[@element] || {}
196-
else
197-
params = {}
198-
end
192+
params = if params.is_a?(Array)
193+
params.flat_map { |el| el[@element] || {} }
194+
elsif params.is_a?(Hash)
195+
params[@element] || {}
196+
else
197+
{}
198+
end
199199
end
200200
params
201201
end

lib/grape/dsl/request_response.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def format(new_format = nil)
2323
namespace_inheritable(:default_error_formatter, Grape::ErrorFormatter.formatter_for(new_format, {}))
2424
# define a single mime type
2525
mime_type = content_types[new_format.to_sym]
26-
fail Grape::Exceptions::MissingMimeType.new(new_format) unless mime_type
26+
raise Grape::Exceptions::MissingMimeType.new(new_format) unless mime_type
2727
namespace_stackable(:content_types, new_format.to_sym => mime_type)
2828
else
2929
namespace_inheritable(:format)
@@ -51,11 +51,11 @@ def default_error_formatter(new_formatter_name = nil)
5151
end
5252

5353
def error_formatter(format, options)
54-
if options.is_a?(Hash) && options.key?(:with)
55-
formatter = options[:with]
56-
else
57-
formatter = options
58-
end
54+
formatter = if options.is_a?(Hash) && options.key?(:with)
55+
options[:with]
56+
else
57+
options
58+
end
5959

6060
namespace_stackable(:error_formatters, format.to_sym => formatter)
6161
end
@@ -106,7 +106,7 @@ def rescue_from(*args, &block)
106106

107107
options = args.extract_options!
108108
if block_given? && options.key?(:with)
109-
fail ArgumentError, 'both :with option and block cannot be passed'
109+
raise ArgumentError, 'both :with option and block cannot be passed'
110110
end
111111
handler ||= extract_with(options)
112112

@@ -115,12 +115,12 @@ def rescue_from(*args, &block)
115115
namespace_inheritable :all_rescue_handler, handler
116116
else
117117
handler_type =
118-
case options[:rescue_subclasses]
119-
when nil, true
120-
:rescue_handlers
121-
else
122-
:base_only_rescue_handlers
123-
end
118+
case options[:rescue_subclasses]
119+
when nil, true
120+
:rescue_handlers
121+
else
122+
:base_only_rescue_handlers
123+
end
124124

125125
namespace_stackable handler_type, Hash[args.map { |arg| [arg, handler] }]
126126
end
@@ -149,7 +149,7 @@ def rescue_from(*args, &block)
149149
# @param model_class [Class] The model class that will be represented.
150150
# @option options [Class] :with The entity class that will represent the model.
151151
def represent(model_class, options)
152-
fail Grape::Exceptions::InvalidWithOptionForRepresent.new unless options[:with] && options[:with].is_a?(Class)
152+
raise Grape::Exceptions::InvalidWithOptionForRepresent.new unless options[:with] && options[:with].is_a?(Class)
153153
namespace_stackable(:representations, model_class => options[:with])
154154
end
155155

@@ -160,7 +160,7 @@ def extract_with(options)
160160
with_option = options.delete(:with)
161161
return with_option if with_option.instance_of?(Proc)
162162
return with_option.to_sym if with_option.instance_of?(Symbol) || with_option.instance_of?(String)
163-
fail ArgumentError, "with: #{with_option.class}, expected Symbol, String or Proc"
163+
raise ArgumentError, "with: #{with_option.class}, expected Symbol, String or Proc"
164164
end
165165
end
166166
end

lib/grape/dsl/routing.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def version(*args, &block)
3131
options = args.extract_options!
3232
options = options.reverse_merge(using: :path)
3333

34-
fail Grape::Exceptions::MissingVendorOption.new if options[:using] == :header && !options.key?(:vendor)
34+
raise Grape::Exceptions::MissingVendorOption.new if options[:using] == :header && !options.key?(:vendor)
3535

3636
@versions = versions | args
3737

@@ -121,9 +121,9 @@ def route(methods, paths = ['/'], route_options = {}, &block)
121121
method: methods,
122122
path: paths,
123123
for: self,
124-
route_options: ({
124+
route_options: {
125125
params: namespace_stackable_with_hash(:params) || {}
126-
}).deep_merge(route_setting(:description) || {}).deep_merge(route_options || {})
126+
}.deep_merge(route_setting(:description) || {}).deep_merge(route_options || {})
127127
}
128128

129129
new_endpoint = Grape::Endpoint.new(inheritable_setting, endpoint_options, &block)
@@ -170,10 +170,10 @@ def namespace(space = nil, options = {}, &block)
170170
end
171171
end
172172

173-
alias_method :group, :namespace
174-
alias_method :resource, :namespace
175-
alias_method :resources, :namespace
176-
alias_method :segment, :namespace
173+
alias group namespace
174+
alias resource namespace
175+
alias resources namespace
176+
alias segment namespace
177177

178178
# An array of API routes.
179179
def routes

lib/grape/endpoint.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_before_each(endpoint)
5454
# @raise [NameError] an instance method with the same name already exists
5555
def generate_api_method(method_name, &block)
5656
if instance_methods.include?(method_name.to_sym) || instance_methods.include?(method_name.to_s)
57-
fail NameError.new("method #{method_name.inspect} already exists and cannot be used as an unbound method name")
57+
raise NameError.new("method #{method_name.inspect} already exists and cannot be used as an unbound method name")
5858
end
5959

6060
define_method(method_name, &block)
@@ -98,7 +98,7 @@ def initialize(new_settings, options = {}, &block)
9898
end
9999

100100
def require_option(options, key)
101-
fail Grape::Exceptions::MissingOption.new(key) unless options.key?(key)
101+
raise Grape::Exceptions::MissingOption.new(key) unless options.key?(key)
102102
end
103103

104104
def method_name
@@ -171,7 +171,7 @@ def prepare_default_route_attributes
171171

172172
def prepare_version
173173
version = namespace_inheritable(:version) || []
174-
return if version.length == 0
174+
return if version.empty?
175175
version.length == 1 ? version.first.to_s : version
176176
end
177177

@@ -326,7 +326,7 @@ def run_validators(validators, request)
326326
end
327327
end
328328

329-
validation_errors.any? && fail(Grape::Exceptions::ValidationErrors, errors: validation_errors, headers: header)
329+
validation_errors.any? && raise(Grape::Exceptions::ValidationErrors, errors: validation_errors, headers: header)
330330
end
331331

332332
def run_filters(filters, type = :other)

0 commit comments

Comments
 (0)