Skip to content

Commit

Permalink
configure Layout/MultilineMethodCallIndentation to ensure short indent
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieujobin committed May 30, 2024
1 parent 77b075e commit 6db90f8
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ AllCops:
NewCops: enable
TargetRubyVersion: 2.6

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/LineLength:
Max: 140
Exclude:
Expand Down
10 changes: 0 additions & 10 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,6 @@ Layout/MultilineMethodCallBraceLayout:
Exclude:
- 'lib/tasks/apipie.rake'

# Offense count: 14
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation:
Exclude:
- 'lib/apipie/generator/swagger/param_description/builder.rb'
- 'lib/apipie/generator/swagger/param_description/composite.rb'
- 'lib/apipie/generator/swagger/param_description/type.rb'

# Offense count: 4
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, IndentationWidth.
Expand Down
12 changes: 6 additions & 6 deletions lib/apipie/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ def to_swagger_json(version, resource_id, method_name, language, clear_warnings

resources =
Apipie::Generator::Swagger::ResourceDescriptionsCollection
.new(resource_descriptions)
.filter(
resource_id: resource_id,
method_name: method_name,
version: version
)
.new(resource_descriptions)
.filter(
resource_id: resource_id,
method_name: method_name,
version: version
)

Apipie::SwaggerGenerator.generate_from_resources(
resources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def call
end

parameters = Apipie::Generator::Swagger::MethodDescription::ParametersService
.new(@method_description, path: path, http_method: api.normalized_http_method)
.call
.new(@method_description, path: path, http_method: api.normalized_http_method)
.call

paths[path.swagger_path(@method_description)] ||= {}
paths[path.swagger_path(@method_description)][api.normalized_http_method] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def body_params_schema

if Apipie.configuration.generator.swagger.json_input_uses_refs?
composite = composite
.referenced("#{@method_description.operation_id}_input")
.referenced("#{@method_description.operation_id}_input")
end

swagger_schema_for_body = composite.to_swagger
Expand Down Expand Up @@ -80,7 +80,7 @@ def all_params
warn_path_parameter_not_described(name, @path)

result[name.to_sym] = Apipie::Generator::Swagger::ParamDescription
.create_for_missing_param(@method_description, name)
.create_for_missing_param(@method_description, name)
end

result
Expand All @@ -89,15 +89,15 @@ def all_params

def body_param_descriptions
@body_param_descriptions ||= all_params
.reject { |k, _| @path.param?(k) }
.values
.reject { |k, _| @path.param?(k) }
.values
end

def path_param_descriptions
@path_param_descriptions ||= all_params
.select { |k, _| @path.param?(k) }
.each_value { |desc| desc.required = true }
.values
.select { |k, _| @path.param?(k) }
.each_value { |desc| desc.required = true }
.values
end

# @return [Array]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ def to_swagger
context.add_to_prefix!(desc.name)

out = Apipie::Generator::Swagger::ParamDescription::PathParamsComposite
.new(desc.validator.params_ordered, context)
.to_swagger
.new(desc.validator.params_ordered, context)
.to_swagger

@result.concat(out)
else
param_entry =
Apipie::Generator::Swagger::ParamDescription::Builder
.new(desc, in_schema: false, controller_method: context.controller_method)
.with_description(language: context.language)
.with_name(prefix: context.prefix)
.with_type(with_null: context.allow_null?)
.with_in(
http_method: context.http_method,
default_in_value: context.default_in_value
).to_swagger
.new(desc, in_schema: false, controller_method: context.controller_method)
.with_description(language: context.language)
.with_name(prefix: context.prefix)
.with_type(with_null: context.allow_null?)
.with_in(
http_method: context.http_method,
default_in_value: context.default_in_value
).to_swagger

@result << param_entry
end
Expand Down
10 changes: 5 additions & 5 deletions lib/apipie/generator/swagger/resource_description_composite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def paths
next unless method_description.show

result = Apipie::Generator::Swagger::MethodDescription::ApiSchemaService
.new(
Apipie::Generator::Swagger::MethodDescription::Decorator.new(method_description),
language: @language
)
.call
.new(
Apipie::Generator::Swagger::MethodDescription::Decorator.new(method_description),
language: @language
)
.call

results.deep_merge!(result)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/apipie/static_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def initialize(root)
def match?(path)
# Replace all null bytes
path = ::Rack::Utils.unescape(path || '')
.encode(Encoding::UTF_8, invalid: :replace, replace: '')
.gsub("\x0", '')
.encode(Encoding::UTF_8, invalid: :replace, replace: '')
.gsub("\x0", '')

full_path = path.empty? ? @root : File.join(@root, path)
paths = "#{full_path}#{ext}"
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/swagger/swagger_dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def have_field?(field, expected_name, breadcrumb)
expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'})
expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false}) # rubocop:disable Capybara/NegationMatcher
expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false})
end

it "creates a swagger definition with all input parameters" do
Expand Down

0 comments on commit 6db90f8

Please sign in to comment.