Skip to content

Commit f15f685

Browse files
committed
re: RuboCop: Bulk minor style corrections
1 parent 32a3b53 commit f15f685

File tree

15 files changed

+41
-143
lines changed

15 files changed

+41
-143
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@ Lint/HandleExceptions:
1111
Exclude:
1212
- 'Rakefile'
1313

14-
# Offense count: 2
15-
# Cop supports --auto-correct.
16-
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
17-
Lint/UnusedMethodArgument:
18-
Exclude:
19-
- 'test/lint_test.rb'
20-
21-
# Offense count: 4
22-
# Configuration parameters: EnforcedStyle, SupportedStyles.
23-
# SupportedStyles: strict, flexible
24-
Rails/TimeZone:
25-
Exclude:
26-
- 'test/action_controller/serialization_test.rb'
27-
- 'test/serializers/cache_test.rb'
28-
2914
# Offense count: 16
3015
# Cop supports --auto-correct.
3116
# Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
@@ -58,22 +43,7 @@ Style/BracesAroundHashParameters:
5843
Style/ClassAndModuleChildren:
5944
Enabled: false
6045

61-
# Offense count: 6
62-
# Cop supports --auto-correct.
63-
Style/CommentIndentation:
64-
Exclude:
65-
- 'active_model_serializers.gemspec'
66-
67-
# Offense count: 1
68-
Style/DoubleNegation:
69-
Exclude:
70-
- 'lib/active_model/serializable_resource.rb'
7146

72-
# Offense count: 1
73-
# Configuration parameters: MinBodyLength.
74-
Style/GuardClause:
75-
Exclude:
76-
- 'lib/active_model/serializer.rb'
7747

7848
# Offense count: 58
7949
# Cop supports --auto-correct.
@@ -82,51 +52,6 @@ Style/GuardClause:
8252
Style/HashSyntax:
8353
Enabled: false
8454

85-
# Offense count: 4
86-
# Cop supports --auto-correct.
87-
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
88-
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
89-
Style/IndentArray:
90-
Enabled: false
91-
92-
# Offense count: 10
93-
# Cop supports --auto-correct.
94-
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
95-
# SupportedStyles: special_inside_parentheses, consistent, align_braces
96-
Style/IndentHash:
97-
Enabled: false
98-
99-
# Offense count: 1
100-
# Cop supports --auto-correct.
101-
Style/Lambda:
102-
Exclude:
103-
- 'lib/active_model/serializer.rb'
104-
105-
# Offense count: 1
106-
# Cop supports --auto-correct.
107-
# Configuration parameters: EnforcedStyle, SupportedStyles.
108-
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
109-
Style/MethodDefParentheses:
110-
Enabled: false
111-
112-
# Offense count: 1
113-
# Cop supports --auto-correct.
114-
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
115-
# SupportedStyles: aligned, indented
116-
Style/MultilineOperationIndentation:
117-
Enabled: false
118-
119-
# Offense count: 1
120-
# Cop supports --auto-correct.
121-
Style/NegatedIf:
122-
Exclude:
123-
- 'lib/action_controller/serialization.rb'
124-
125-
# Offense count: 1
126-
# Cop supports --auto-correct.
127-
Style/PerlBackrefs:
128-
Exclude:
129-
- 'test/fixtures/poro.rb'
13055

13156
# Offense count: 3
13257
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
@@ -138,30 +63,4 @@ Style/PredicateName:
13863
- 'lib/active_model/serializer/associations.rb'
13964
- 'test/action_controller/json_api/linked_test.rb'
14065

141-
# Offense count: 1
142-
# Cop supports --auto-correct.
143-
Style/RedundantSelf:
144-
Exclude:
145-
- 'test/fixtures/poro.rb'
14666

147-
# Offense count: 1
148-
# Cop supports --auto-correct.
149-
# Configuration parameters: AllowIfMethodIsEmpty.
150-
Style/SingleLineMethods:
151-
Exclude:
152-
- 'test/serializers/serializer_for_test.rb'
153-
154-
# Offense count: 4
155-
# Cop supports --auto-correct.
156-
# Configuration parameters: EnforcedStyle, SupportedStyles.
157-
# SupportedStyles: single_quotes, double_quotes
158-
Style/StringLiteralsInInterpolation:
159-
Enabled: false
160-
161-
# Offense count: 1
162-
# Cop supports --auto-correct.
163-
# Configuration parameters: EnforcedStyle, SupportedStyles.
164-
# SupportedStyles: final_newline, final_blank_line
165-
Style/TrailingBlankLines:
166-
Exclude:
167-
- 'test/adapter/null_test.rb'

active_model_serializers.gemspec

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ Gem::Specification.new do |spec|
2323

2424
rails_versions = ['>= 4.1', '< 6']
2525
spec.add_runtime_dependency 'activemodel', rails_versions
26-
# 'activesupport', rails_versions
27-
# 'builder'
26+
# 'activesupport', rails_versions
27+
# 'builder'
2828

2929
spec.add_runtime_dependency 'actionpack', rails_versions
30-
# 'activesupport', rails_versions
31-
# 'rack'
32-
# 'rack-test', '~> 0.6.2'
30+
# 'activesupport', rails_versions
31+
# 'rack'
32+
# 'rack-test', '~> 0.6.2'
3333

3434
spec.add_runtime_dependency 'railties', rails_versions
35-
# 'activesupport', rails_versions
36-
# 'actionpack', rails_versions
37-
# 'rake', '>= 0.8.7'
35+
# 'activesupport', rails_versions
36+
# 'actionpack', rails_versions
37+
# 'rake', '>= 0.8.7'
3838

3939
# 'activesupport', rails_versions
40-
# 'i18n,
41-
# 'tzinfo'
42-
# 'minitest'
43-
# 'thread_safe'
40+
# 'i18n,
41+
# 'tzinfo'
42+
# 'minitest'
43+
# 'thread_safe'
4444

4545
spec.add_runtime_dependency 'jsonapi', '~> 0.1.1.beta2'
4646

4747
spec.add_development_dependency 'activerecord', rails_versions
48-
# arel
49-
# activesupport
50-
# activemodel
48+
# arel
49+
# activesupport
50+
# activemodel
5151

5252
# Soft dependency for pagination
5353
spec.add_development_dependency 'kaminari', ' ~> 0.16.3'

lib/action_controller/serialization.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ def serialization_scope(scope)
1919
end
2020

2121
def serialization_scope
22-
send(_serialization_scope) if _serialization_scope &&
23-
respond_to?(_serialization_scope, true)
22+
return unless _serialization_scope && respond_to?(_serialization_scope, true)
23+
24+
send(_serialization_scope)
2425
end
2526

2627
def get_serializer(resource, options = {})
27-
if !use_adapter?
28+
unless use_adapter?
2829
warn 'ActionController::Serialization#use_adapter? has been removed. '\
2930
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
3031
options[:adapter] = false

lib/active_model/serializer.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ def initialize(object, options = {})
125125
self.root = instance_options[:root]
126126
self.scope = instance_options[:scope]
127127

128-
scope_name = instance_options[:scope_name]
129-
if scope_name && !respond_to?(scope_name)
130-
define_singleton_method scope_name, lambda { scope }
131-
end
128+
return if !(scope_name = instance_options[:scope_name]) || respond_to?(scope_name)
129+
130+
define_singleton_method scope_name, -> { scope }
132131
end
133132

134133
def success?

lib/active_model_serializers/deprecate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def deprecate(name, replacement)
3636
target = is_a?(Module) ? "#{self}." : "#{self.class}#"
3737
msg = ["NOTE: #{target}#{name} is deprecated",
3838
replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
39-
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"]
39+
"\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(':')}"]
4040
warn "#{msg.join}."
4141
send old, *args, &block
4242
end

lib/active_model_serializers/model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def id
2121

2222
# Defaults to the downcased model name and updated_at
2323
def cache_key
24-
attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime("%Y%m%d%H%M%S%9N")}" }
24+
attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime('%Y%m%d%H%M%S%9N')}" }
2525
end
2626

2727
# Defaults to the time the serializer file was modified.

test/action_controller/serialization_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def render_json_array_object_without_serializer
7474
end
7575

7676
def update_and_render_object_with_cache_enabled
77-
@post.updated_at = Time.now
77+
@post.updated_at = Time.zone.now
7878

7979
generate_cached_serializer(@post)
8080
render json: @post

test/adapter/json_api/json_api_test.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ def test_custom_keys
2222
adapter = ActiveModelSerializers::Adapter::JsonApi.new(serializer)
2323

2424
assert_equal({
25-
reviews: { data: [
26-
{ type: 'comments', id: '1' },
27-
{ type: 'comments', id: '2' }
28-
] },
25+
reviews: { data: [{ type: 'comments', id: '1' },
26+
{ type: 'comments', id: '2' }] },
2927
writer: { data: { type: 'authors', id: '1' } },
3028
site: { data: { type: 'blogs', id: '1' } }
3129
}, adapter.serializable_hash[:data][:relationships])

test/adapter/json_api/type_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def assert_type(resource, expected_type, opts = {})
4747
assert_equal(expected_type, hash.fetch(:data).fetch(:type))
4848
end
4949

50-
def with_jsonapi_resource_type inflection
50+
def with_jsonapi_resource_type(inflection)
5151
old_inflection = ActiveModelSerializers.config.jsonapi_resource_type
5252
ActiveModelSerializers.config.jsonapi_resource_type = inflection
5353
yield

test/adapter/null_test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ def test_it_returns_empty_json
2020
end
2121
end
2222
end
23-

0 commit comments

Comments
 (0)