re: RuboCop: Bulk minor style corrections

This commit is contained in:
Alexey Dubovskoy 2016-06-20 20:55:44 +01:00
parent 32a3b53892
commit f15f6850de
15 changed files with 41 additions and 143 deletions

View File

@ -11,21 +11,6 @@ Lint/HandleExceptions:
Exclude:
- 'Rakefile'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'test/lint_test.rb'
# Offense count: 4
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: strict, flexible
Rails/TimeZone:
Exclude:
- 'test/action_controller/serialization_test.rb'
- 'test/serializers/cache_test.rb'
# Offense count: 16
# Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
@ -58,22 +43,7 @@ Style/BracesAroundHashParameters:
Style/ClassAndModuleChildren:
Enabled: false
# Offense count: 6
# Cop supports --auto-correct.
Style/CommentIndentation:
Exclude:
- 'active_model_serializers.gemspec'
# Offense count: 1
Style/DoubleNegation:
Exclude:
- 'lib/active_model/serializable_resource.rb'
# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/active_model/serializer.rb'
# Offense count: 58
# Cop supports --auto-correct.
@ -82,51 +52,6 @@ Style/GuardClause:
Style/HashSyntax:
Enabled: false
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
Enabled: false
# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Style/IndentHash:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/Lambda:
Exclude:
- 'lib/active_model/serializer.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
Style/MethodDefParentheses:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
Style/NegatedIf:
Exclude:
- 'lib/action_controller/serialization.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/PerlBackrefs:
Exclude:
- 'test/fixtures/poro.rb'
# Offense count: 3
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
@ -138,30 +63,4 @@ Style/PredicateName:
- 'lib/active_model/serializer/associations.rb'
- 'test/action_controller/json_api/linked_test.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'test/fixtures/poro.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Exclude:
- 'test/serializers/serializer_for_test.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: final_newline, final_blank_line
Style/TrailingBlankLines:
Exclude:
- 'test/adapter/null_test.rb'

View File

@ -23,31 +23,31 @@ Gem::Specification.new do |spec|
rails_versions = ['>= 4.1', '< 6']
spec.add_runtime_dependency 'activemodel', rails_versions
# 'activesupport', rails_versions
# 'builder'
# 'activesupport', rails_versions
# 'builder'
spec.add_runtime_dependency 'actionpack', rails_versions
# 'activesupport', rails_versions
# 'rack'
# 'rack-test', '~> 0.6.2'
# 'activesupport', rails_versions
# 'rack'
# 'rack-test', '~> 0.6.2'
spec.add_runtime_dependency 'railties', rails_versions
# 'activesupport', rails_versions
# 'actionpack', rails_versions
# 'rake', '>= 0.8.7'
# 'activesupport', rails_versions
# 'actionpack', rails_versions
# 'rake', '>= 0.8.7'
# 'activesupport', rails_versions
# 'i18n,
# 'tzinfo'
# 'minitest'
# 'thread_safe'
# 'i18n,
# 'tzinfo'
# 'minitest'
# 'thread_safe'
spec.add_runtime_dependency 'jsonapi', '~> 0.1.1.beta2'
spec.add_development_dependency 'activerecord', rails_versions
# arel
# activesupport
# activemodel
# arel
# activesupport
# activemodel
# Soft dependency for pagination
spec.add_development_dependency 'kaminari', ' ~> 0.16.3'

View File

@ -19,12 +19,13 @@ module ActionController
end
def serialization_scope
send(_serialization_scope) if _serialization_scope &&
respond_to?(_serialization_scope, true)
return unless _serialization_scope && respond_to?(_serialization_scope, true)
send(_serialization_scope)
end
def get_serializer(resource, options = {})
if !use_adapter?
unless use_adapter?
warn 'ActionController::Serialization#use_adapter? has been removed. '\
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
options[:adapter] = false

View File

@ -125,10 +125,9 @@ module ActiveModel
self.root = instance_options[:root]
self.scope = instance_options[:scope]
scope_name = instance_options[:scope_name]
if scope_name && !respond_to?(scope_name)
define_singleton_method scope_name, lambda { scope }
end
return if !(scope_name = instance_options[:scope_name]) || respond_to?(scope_name)
define_singleton_method scope_name, -> { scope }
end
def success?

View File

@ -36,7 +36,7 @@ module ActiveModelSerializers
target = is_a?(Module) ? "#{self}." : "#{self.class}#"
msg = ["NOTE: #{target}#{name} is deprecated",
replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"]
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(':')}"]
warn "#{msg.join}."
send old, *args, &block
end

View File

@ -21,7 +21,7 @@ module ActiveModelSerializers
# Defaults to the downcased model name and updated_at
def cache_key
attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime("%Y%m%d%H%M%S%9N")}" }
attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}" }
end
# Defaults to the time the serializer file was modified.

View File

@ -74,7 +74,7 @@ module ActionController
end
def update_and_render_object_with_cache_enabled
@post.updated_at = Time.now
@post.updated_at = Time.zone.now
generate_cached_serializer(@post)
render json: @post

View File

@ -22,10 +22,8 @@ module ActiveModelSerializers
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
assert_equal({
reviews: { data: [
{ type: 'comments', id: '1' },
{ type: 'comments', id: '2' }
] },
reviews: { data: [{ type: 'comments', id: '1' },
{ type: 'comments', id: '2' }] },
writer: { data: { type: 'authors', id: '1' } },
site: { data: { type: 'blogs', id: '1' } }
}, adapter.serializable_hash[:data][:relationships])

View File

@ -47,7 +47,7 @@ module ActiveModel
assert_equal(expected_type, hash.fetch(:data).fetch(:type))
end
def with_jsonapi_resource_type inflection
def with_jsonapi_resource_type(inflection)
old_inflection = ActiveModelSerializers.config.jsonapi_resource_type
ActiveModelSerializers.config.jsonapi_resource_type = inflection
yield

View File

@ -20,4 +20,3 @@ module ActiveModelSerializers
end
end
end

View File

@ -101,7 +101,7 @@ module ActiveModelSerializers
uncached_author_serializer = AuthorSerializer.new(uncached_author)
render_object_with_cache(uncached_author)
key = "#{uncached_author_serializer.class._cache_key}/#{uncached_author_serializer.object.id}-#{uncached_author_serializer.object.updated_at.strftime("%Y%m%d%H%M%S%9N")}"
key = "#{uncached_author_serializer.class._cache_key}/#{uncached_author_serializer.object.id}-#{uncached_author_serializer.object.updated_at.strftime('%Y%m%d%H%M%S%9N')}"
key = "#{key}/#{adapter.cache_key}"
assert_equal(uncached_author_serializer.attributes.to_json, cache_store.fetch(key).to_json)
end

View File

@ -8,7 +8,7 @@ class Model < ActiveModelSerializers::Model
# Convenience when not adding @attributes readers and writers
def method_missing(meth, *args)
if meth.to_s =~ /^(.*)=$/
attributes[$1.to_sym] = args[0]
attributes[Regexp.last_match(1).to_sym] = args[0]
elsif attributes.key?(meth)
attributes[meth]
else
@ -64,7 +64,7 @@ VirtualValue = Class.new(Model)
Comment = Class.new(Model) do
# Uses a custom non-time-based cache key
def cache_key
"#{self.class.name.downcase}/#{self.id}"
"#{self.class.name.downcase}/#{id}"
end
end

View File

@ -39,12 +39,12 @@ class ActiveModelSerializers::GrapeTest < ActiveSupport::TestCase
begin
Kaminari.paginate_array(
[
Profile.new(id: 1, name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
Profile.new(id: 2, name: 'Name 2', description: 'Description 2', comments: 'Comments 2'),
Profile.new(id: 3, name: 'Name 3', description: 'Description 3', comments: 'Comments 3'),
Profile.new(id: 4, name: 'Name 4', description: 'Description 4', comments: 'Comments 4'),
Profile.new(id: 5, name: 'Name 5', description: 'Description 5', comments: 'Comments 5')
]
Profile.new(id: 1, name: 'Name 1', description: 'Description 1', comments: 'Comments 1'),
Profile.new(id: 2, name: 'Name 2', description: 'Description 2', comments: 'Comments 2'),
Profile.new(id: 3, name: 'Name 3', description: 'Description 3', comments: 'Comments 3'),
Profile.new(id: 4, name: 'Name 4', description: 'Description 4', comments: 'Comments 4'),
Profile.new(id: 5, name: 'Name 5', description: 'Description 5', comments: 'Comments 5')
]
).page(1).per(collection_per)
end
end

View File

@ -30,7 +30,7 @@ module ActiveModel
def errors
end
def self.human_attribute_name(attr, options = {})
def self.human_attribute_name(_, _ = {})
end
def self.lookup_ancestors

View File

@ -41,7 +41,9 @@ module ActiveModel
end
class CustomProfile
def serializer_class; ProfileSerializer; end
def serializer_class
ProfileSerializer
end
end
Tweet = Class.new(::Model)