Skip to content

Commit

Permalink
Merge pull request #1560 from groyoh/update_rubocop
Browse files Browse the repository at this point in the history
Update rubocop
  • Loading branch information
NullVoxPopuli committed Mar 8, 2016
2 parents c97a80d + 666dae8 commit f8d2aab
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 150 deletions.
19 changes: 18 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ AllCops:
Exclude:
- config/initializers/forbidden_yaml.rb
- !ruby/regexp /(vendor|bundle|bin|db|tmp)\/.*/
RunRailsCops: true
DisplayCopNames: true
DisplayStyleGuide: true

Rails:
Enabled: true

Lint/NestedMethodDefinition:
Enabled: false
Exclude:
- test/action_controller/serialization_test.rb

Style/Alias:
EnforcedStyle: prefer_alias

Style/StringLiterals:
EnforcedStyle: single_quotes

Expand Down Expand Up @@ -59,6 +64,18 @@ Style/BlockDelimiters:
Enabled: true
EnforcedStyle: line_count_based

Style/SignalException:
EnforcedStyle: semantic

Style/TrailingCommaInLiteral:
EnforcedStyleForMultiline: no_comma

Style/ConditionalAssignment:
Enabled: false

Style/DotPosition:
EnforcedStyle: leading

########## test_helper.rb sanity
Style/EndBlock:
Exclude:
Expand Down
132 changes: 30 additions & 102 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-09-20 17:56:22 -0500 using RuboCop version 0.34.0.
# on 2016-03-08 22:29:52 +0100 using RuboCop version 0.37.2.
# 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
Expand All @@ -13,49 +13,31 @@ Lint/HandleExceptions:

# Offense count: 2
# Cop supports --auto-correct.
Lint/UnusedBlockArgument:
Exclude:
- 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'

# Offense count: 7
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/active_model/serializer/adapter/null.rb'
- 'lib/active_model/serializer/pass_through_serializer.rb'
- 'test/fixtures/poro.rb'
- 'test/lint_test.rb'

# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'bench/perf.rb'
- 'lib/active_model/serializer/adapter/json_api/fragment_cache.rb'

# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
Rails/Date:
Exclude:
- 'test/fixtures/poro.rb'

# Offense count: 4
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: strict, flexible
Rails/TimeZone:
Exclude:
- 'test/action_controller/serialization_test.rb'
- 'test/fixtures/poro.rb'
- 'test/serializers/cache_test.rb'

# Offense count: 16
# Cop supports --auto-correct.
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
Style/AlignHash:
Exclude:
- 'test/action_controller/json_api/pagination_test.rb'

# Offense count: 25
# Offense count: 27
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: braces, no_braces, context_dependent
Style/BracesAroundHashParameters:
Exclude:
- 'test/action_controller/adapter_selector_test.rb'
Expand All @@ -67,17 +49,16 @@ Style/BracesAroundHashParameters:
- 'test/collection_serializer_test.rb'
- 'test/serializable_resource_test.rb'
- 'test/serializers/associations_test.rb'
- 'test/serializers/attribute_test.rb'
- 'test/serializers/attributes_test.rb'
- 'test/serializers/fieldset_test.rb'
- 'test/serializers/root_test.rb'

# Offense count: 174
# Offense count: 271
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Enabled: false

# Offense count: 5
# Offense count: 6
# Cop supports --auto-correct.
Style/CommentIndentation:
Exclude:
Expand All @@ -89,34 +70,29 @@ Style/DoubleNegation:
- 'lib/active_model/serializable_resource.rb'

# Offense count: 1
Style/EachWithObject:
Exclude:
- 'lib/active_model/serializer/fieldset.rb'

# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'lib/active_model/serializer.rb'

# Offense count: 12
# Offense count: 58
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
# SupportedStyles: ruby19, ruby19_no_mixed_keys, hash_rockets
Style/HashSyntax:
Enabled: false

# Offense count: 9
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
Exclude:
- 'test/adapter/json/has_many_test.rb'
- 'test/adapter/json_api/json_api_test.rb'
- 'test/adapter/json_api/pagination_links_test.rb'
- 'test/adapter/json_test.rb'
Enabled: false

# Offense count: 8
# Offense count: 10
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_braces
Style/IndentHash:
Enabled: false

Expand All @@ -129,12 +105,14 @@ Style/Lambda:
# 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: 3
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation:
Enabled: false

Expand All @@ -146,94 +124,44 @@ Style/NegatedIf:

# Offense count: 1
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 7

# Offense count: 2
# Cop supports --auto-correct.
Style/PerlBackrefs:
Exclude:
- 'test/fixtures/poro.rb'
- 'test/serializers/associations_test.rb'

# Offense count: 3
# Configuration parameters: NamePrefix, NamePrefixBlacklist.
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
# NamePrefix: is_, has_, have_
# NamePrefixBlacklist: is_, has_, have_
# NameWhitelist: is_a?
Style/PredicateName:
Exclude:
- 'lib/active_model/serializer/associations.rb'
- 'test/action_controller/json_api/linked_test.rb'

# Offense count: 5
# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'lib/active_model/serializer/associations.rb'
- 'test/fixtures/poro.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Exclude:
- 'lib/active_model/serializer/fieldset.rb'

# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/SignalException:
Exclude:
- 'lib/active_model/serializer/fieldset.rb'
- 'lib/active_model/serializer/pass_through_serializer.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Exclude:
- 'test/serializers/serializer_for_test.rb'

# Offense count: 2
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Enabled: false

# Offense count: 1
Style/StructInheritance:
Exclude:
- 'bench/perf.rb'

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
Style/SymbolProc:
Exclude:
- 'lib/generators/serializer/serializer_generator.rb'

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: final_newline, final_blank_line
Style/TrailingBlankLines:
Exclude:
- 'lib/active_model/serializer/pass_through_serializer.rb'
- 'lib/generators/serializer/serializer_generator.rb'
- 'test/adapter/fragment_cache_test.rb'
- 'test/adapter/json_api/json_api_test.rb'
- 'test/adapter/null_test.rb'
- 'test/serializers/cache_test.rb'
- 'test/serializers/fieldset_test.rb'

# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
Style/TrailingComma:
Exclude:
- 'test/action_controller/adapter_selector_test.rb'
- 'test/action_controller/serialization_test.rb'
- 'test/adapter/json_api/belongs_to_test.rb'
- 'test/adapter/json_api/linked_test.rb'

# Offense count: 1
Style/UnlessElse:
Exclude:
- 'lib/active_model/serializer.rb'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Fixes:
- [#1488](https://github.com/rails-api/active_model_serializers/pull/1488) Require ActiveSupport's string inflections (@nate00)

Misc:
- [#1560](https://github.com/rails-api/active_model_serializers/pull/1560) Update rubocop and address its warnings. (@bf4 @groyoh)
- [#1545](https://github.com/rails-api/active_model_serializers/pull/1545) Document how to pass arbitrary options to the
serializer (@CodedBeardedSignedTaylor)
- [#1496](https://github.com/rails-api/active_model_serializers/pull/1496) Run all branches against JRuby on CI (@nadavshatz)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ group :test do
end

group :development, :test do
gem 'rubocop', '~> 0.34.0', require: false
gem 'rubocop', '~> 0.36', require: false
end
6 changes: 3 additions & 3 deletions lib/active_model/serializable_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def serialization_scope_name=(scope_name)
def adapter
@adapter ||= ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts)
end
alias_method :adapter_instance, :adapter
alias adapter_instance adapter

def serializer_instance
@serializer_instance ||= serializer.new(resource, serializer_opts)
Expand All @@ -54,7 +54,7 @@ def serializer
@serializer
end
end
alias_method :serializer_class, :serializer
alias serializer_class serializer

# True when no explicit adapter given, or explicit appear is truthy (non-nil)
# False when explicit adapter is falsy (nil or false)
Expand All @@ -63,7 +63,7 @@ def use_adapter?
end

def serializer?
use_adapter? && !!(serializer)
use_adapter? && !!serializer
end

protected
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/caching.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def cache(options = {})
self._cache_key = options.delete(:key)
self._cache_only = options.delete(:only)
self._cache_except = options.delete(:except)
self._cache_options = (options.empty?) ? nil : options
self._cache_options = options.empty? ? nil : options
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/collection_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(resources, options = {})
serializer_context_class = options.fetch(:serializer_context_class, ActiveModel::Serializer)
serializer_class = options.fetch(:serializer) { serializer_context_class.serializer_for(resource) }

if serializer_class.nil?
if serializer_class.nil? # rubocop:disable Style/GuardClause
fail NoSerializerError, "No serializer found for resource: #{resource.inspect}"
else
serializer_class.new(resource, options.except(:serializer))
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model/serializer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ActiveModel
class Serializer
VERSION = '0.10.0.rc4'
VERSION = '0.10.0.rc4'.freeze
end
end
4 changes: 2 additions & 2 deletions lib/active_model_serializers/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ActiveModelSerializers
module Adapter
UnknownAdapterError = Class.new(ArgumentError)
ADAPTER_MAP = {}
ADAPTER_MAP = {} # rubocop:disable Style/MutableConstant
private_constant :ADAPTER_MAP if defined?(private_constant)
require 'active_model_serializers/adapter/fragment_cache'
require 'active_model_serializers/adapter/cached_serializer'
Expand Down Expand Up @@ -49,7 +49,7 @@ def adapters
# 'Json' will both register as 'json'.
def register(name, klass = name)
name = name.to_s.gsub(/\AActiveModelSerializers::Adapter::/, ''.freeze)
adapter_map.update(name.underscore => klass)
adapter_map[name.underscore] = klass
self
end

Expand Down
2 changes: 1 addition & 1 deletion lib/active_model_serializers/adapter/cached_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def cache_key
def object_cache_key
object_time_safe = @cached_serializer.object.updated_at
object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
(@klass._cache_key) ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key
@klass._cache_key ? "#{@klass._cache_key}/#{@cached_serializer.object.id}-#{object_time_safe}" : @cached_serializer.object.cache_key
end

# find all cache_key for the collection_serializer
Expand Down
2 changes: 1 addition & 1 deletion lib/active_model_serializers/adapter/fragment_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def fetch
# 3. Add non-cached attributes to non-cached Serializer
def cached_attributes(klass, serializers)
attributes = serializer.class._attributes
cached_attributes = (klass._cache_only) ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) }
cached_attributes = klass._cache_only ? klass._cache_only : attributes.reject { |attr| klass._cache_except.include?(attr) }
non_cached_attributes = attributes - cached_attributes

cached_attributes.each do |attribute|
Expand Down
Loading

0 comments on commit f8d2aab

Please sign in to comment.