From 7548c3054ade4b2527635c6fe75d6494f44116d2 Mon Sep 17 00:00:00 2001 From: LeFnord Date: Tue, 30 Jun 2020 00:00:29 +0200 Subject: [PATCH] Fixes descriminator behaviour. - updates rubocop and makes it happy - updates travis, align it with other gems --- .rubocop.yml | 33 +++++++++++++- .rubocop_todo.yml | 45 +++++++++---------- .travis.yml | 14 +++--- Dangerfile | 2 + Gemfile | 6 ++- Rakefile | 2 + bin/pry | 1 + grape-swagger-entity.gemspec | 6 ++- lib/grape-swagger-entity.rb | 2 + lib/grape-swagger/entity.rb | 2 + lib/grape-swagger/entity/attribute_parser.rb | 7 +-- lib/grape-swagger/entity/helper.rb | 4 +- lib/grape-swagger/entity/parser.rb | 3 ++ lib/grape-swagger/entity/version.rb | 4 +- .../entities/response_model_spec.rb | 2 + .../entity/attribute_parser_spec.rb | 2 + spec/grape-swagger/entity/parser_spec.rb | 2 + spec/grape-swagger/entity_spec.rb | 2 + spec/spec_helper.rb | 2 + .../shared_contexts/inheritance_api.rb | 2 + spec/support/shared_contexts/this_api.rb | 2 + 21 files changed, 103 insertions(+), 42 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index dbb2633..a591d19 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ AllCops: Exclude: - vendor/**/* TargetRubyVersion: - 2.2 + 2.7 inherit_from: .rubocop_todo.yml @@ -21,5 +21,34 @@ Metrics/MethodLength: Naming/FileName: Enabled: false -Layout/IndentFirstHashElement: +Layout/FirstHashElementIndentation: EnforcedStyle: consistent + +Layout/EmptyLinesAroundAttributeAccessor: + Enabled: true +Layout/SpaceAroundMethodCallOperator: + Enabled: true +Lint/DeprecatedOpenSSLConstant: + Enabled: true +Lint/MixedRegexpCaptureTypes: + Enabled: true +Lint/RaiseException: + Enabled: true +Lint/StructNewOverride: + Enabled: true +Style/ExponentialNotation: + Enabled: true +Style/HashEachMethods: + Enabled: true +Style/HashTransformKeys: + Enabled: true +Style/HashTransformValues: + Enabled: true +Style/RedundantFetchBlock: + Enabled: true +Style/RedundantRegexpCharacterClass: + Enabled: true +Style/RedundantRegexpEscape: + Enabled: true +Style/SlicingWithRange: + Enabled: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 77a4dfb..ebc16b8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,49 +1,48 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-07-03 22:59:40 +0300 using RuboCop version 0.49.1. +# on 2020-06-29 22:12:50 UTC using RuboCop version 0.86.0. # 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: 2 -Metrics/AbcSize: - Max: 40 - # Offense count: 1 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/BlockLength: - Max: 27 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'grape-swagger-entity.gemspec' + +# Offense count: 4 +# Configuration parameters: IgnoredMethods. +Metrics/AbcSize: + Max: 30 # Offense count: 1 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 124 + Max: 111 -# Offense count: 1 +# Offense count: 2 +# Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: - Max: 15 - -# Offense count: 14 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 120 + Max: 11 -# Offense count: 3 -# Configuration parameters: CountComments. +# Offense count: 5 +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: - Max: 30 + Max: 25 # Offense count: 2 +# Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Max: 16 + Max: 12 -# Offense count: 2 +# Offense count: 4 Style/Documentation: Exclude: - 'spec/**/*' - 'test/**/*' - 'lib/grape-swagger/entity.rb' - - 'lib/grape-swagger/entity/parser.rb' - 'lib/grape-swagger/entity/attribute_parser.rb' + - 'lib/grape-swagger/entity/parser.rb' diff --git a/.travis.yml b/.travis.yml index 025b8d5..96906a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,29 +10,27 @@ after_success: - bundle exec danger rvm: - - 2.4.5 - - 2.5.3 - - 2.6.0 + - 2.5.8 + - 2.6.6 + - 2.7.1 env: - GRAPE_ENTITY=0.6.1 - GRAPE_ENTITY=0.7.1 + - GRAPE_ENTITY=0.8.0 matrix: fast_finish: true include: - - rvm: 2.3.8 + - rvm: 2.4.10 env: - rvm: ruby-head env: - rvm: jruby-head env: - - rvm: rbx-2 - env: allow_failures: - - rvm: 2.3.8 + - rvm: 2.4.10 - rvm: ruby-head - rvm: jruby-head - - rvm: rbx-2 diff --git a/Dangerfile b/Dangerfile index f05fedd..8288190 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1 +1,3 @@ +# frozen_string_literal: true + danger.import_dangerfile(gem: 'ruby-grape-danger') diff --git a/Gemfile b/Gemfile index 37a91e2..7101d1e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' # Specify your gem's dependencies in grape-swagger-entity.gemspec @@ -12,8 +14,8 @@ group :development, :test do gem 'rack-test' gem 'rake' gem 'rdoc' - gem 'rspec', '~> 3.0' - gem 'rubocop', '~> 0.68.1' + gem 'rspec', '~> 3.9' + gem 'rubocop', '~> 0.85' end gem 'grape-swagger', git: 'https://github.com/ruby-grape/grape-swagger.git' diff --git a/Rakefile b/Rakefile index 1e05236..02c318e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubygems' require 'bundler' diff --git a/bin/pry b/bin/pry index 17b86aa..5cbf5bc 100755 --- a/bin/pry +++ b/bin/pry @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'grape-swagger/entity' diff --git a/grape-swagger-entity.gemspec b/grape-swagger-entity.gemspec index 90f5df3..1031cf2 100644 --- a/grape-swagger-entity.gemspec +++ b/grape-swagger-entity.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'grape-swagger/entity/version' @@ -17,7 +19,7 @@ Gem::Specification.new do |s| s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) } s.require_paths = ['lib'] - s.required_ruby_version = '>= 2.2.6' - s.add_runtime_dependency 'grape-entity', '>= 0.5.0' + s.required_ruby_version = '>= 2.4' + s.add_runtime_dependency 'grape-entity', '>= 0.6.0' s.add_runtime_dependency 'grape-swagger', '>= 1.0.0' end diff --git a/lib/grape-swagger-entity.rb b/lib/grape-swagger-entity.rb index d5655c7..7912b13 100644 --- a/lib/grape-swagger-entity.rb +++ b/lib/grape-swagger-entity.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'grape-swagger/entity' diff --git a/lib/grape-swagger/entity.rb b/lib/grape-swagger/entity.rb index 23d5ace..9133ce3 100644 --- a/lib/grape-swagger/entity.rb +++ b/lib/grape-swagger/entity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'grape-swagger' require 'grape-entity' diff --git a/lib/grape-swagger/entity/attribute_parser.rb b/lib/grape-swagger/entity/attribute_parser.rb index 86de296..e643caf 100644 --- a/lib/grape-swagger/entity/attribute_parser.rb +++ b/lib/grape-swagger/entity/attribute_parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module GrapeSwagger module Entity class AttributeParser @@ -65,8 +67,7 @@ def direct_model_type?(type) end def ambiguous_model_type?(type) - type && - type.is_a?(Class) && + type&.is_a?(Class) && !GrapeSwagger::DocMethods::DataType.primitive?(type.name.downcase) && !type == Array end @@ -87,7 +88,7 @@ def document_data_type(documentation, data_type) else { type: data_type } end - type[:format] = documentation[:format] if documentation && documentation.key?(:format) + type[:format] = documentation[:format] if documentation&.key?(:format) type end diff --git a/lib/grape-swagger/entity/helper.rb b/lib/grape-swagger/entity/helper.rb index f88ece0..330b8f9 100644 --- a/lib/grape-swagger/entity/helper.rb +++ b/lib/grape-swagger/entity/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module GrapeSwagger module Entity # Helper methods for DRY @@ -13,7 +15,7 @@ def model_name(entity_model, endpoint) def discriminator(entity_model) entity_model.superclass.root_exposures.detect do |value| - value.documentation.dig(:is_discriminator) + value.documentation&.dig(:is_discriminator) end end diff --git a/lib/grape-swagger/entity/parser.rb b/lib/grape-swagger/entity/parser.rb index 41cc169..17fa987 100644 --- a/lib/grape-swagger/entity/parser.rb +++ b/lib/grape-swagger/entity/parser.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module GrapeSwagger module Entity class Parser @@ -19,6 +21,7 @@ def call class Alias attr_reader :original, :renamed + def initialize(original, renamed) @original = original @renamed = renamed diff --git a/lib/grape-swagger/entity/version.rb b/lib/grape-swagger/entity/version.rb index 02423ce..33c56e4 100644 --- a/lib/grape-swagger/entity/version.rb +++ b/lib/grape-swagger/entity/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module GrapeSwagger module Entity - VERSION = '0.4.0'.freeze + VERSION = '0.4.0' end end diff --git a/spec/grape-swagger/entities/response_model_spec.rb b/spec/grape-swagger/entities/response_model_spec.rb index 88534a0..9a6308b 100644 --- a/spec/grape-swagger/entities/response_model_spec.rb +++ b/spec/grape-swagger/entities/response_model_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'responseModel' do diff --git a/spec/grape-swagger/entity/attribute_parser_spec.rb b/spec/grape-swagger/entity/attribute_parser_spec.rb index e4421cd..fd63e3c 100644 --- a/spec/grape-swagger/entity/attribute_parser_spec.rb +++ b/spec/grape-swagger/entity/attribute_parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require_relative '../../../spec/support/shared_contexts/this_api' diff --git a/spec/grape-swagger/entity/parser_spec.rb b/spec/grape-swagger/entity/parser_spec.rb index f781f3a..6ac581f 100644 --- a/spec/grape-swagger/entity/parser_spec.rb +++ b/spec/grape-swagger/entity/parser_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require_relative '../../../spec/support/shared_contexts/this_api' diff --git a/spec/grape-swagger/entity_spec.rb b/spec/grape-swagger/entity_spec.rb index df5e94f..04b1c7a 100644 --- a/spec/grape-swagger/entity_spec.rb +++ b/spec/grape-swagger/entity_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe GrapeSwagger::Entity do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f8d6b10..acf13eb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + $LOAD_PATH.unshift File.expand_path('lib', __dir__) require 'grape-swagger/entity' diff --git a/spec/support/shared_contexts/inheritance_api.rb b/spec/support/shared_contexts/inheritance_api.rb index bc40812..b7218da 100644 --- a/spec/support/shared_contexts/inheritance_api.rb +++ b/spec/support/shared_contexts/inheritance_api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_context 'inheritance api' do before :all do module InheritanceApi diff --git a/spec/support/shared_contexts/this_api.rb b/spec/support/shared_contexts/this_api.rb index dd89e0c..57af4e1 100644 --- a/spec/support/shared_contexts/this_api.rb +++ b/spec/support/shared_contexts/this_api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + shared_context 'this api' do before :all do module ThisApi