Skip to content

Commit b775ea2

Browse files
committed
Update rubocop config
1 parent 795ac9a commit b775ea2

File tree

5 files changed

+127
-55
lines changed

5 files changed

+127
-55
lines changed

.rubocop.yml

Lines changed: 110 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AllCops:
2-
TargetRubyVersion: 2.2
2+
TargetRubyVersion: 2.4
33
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
44
# to ignore them, so only the ones explicitly set in this file are enabled.
55
DisabledByDefault: true
@@ -8,80 +8,117 @@ AllCops:
88
Style/AndOr:
99
Enabled: true
1010

11-
# Do not use braces for hash literals when they are the last argument of a
12-
# method call.
13-
Style/BracesAroundHashParameters:
11+
# Align `when` with `case`.
12+
Layout/CaseIndentation:
1413
Enabled: true
1514

16-
# Align `when` with `case`.
17-
Style/CaseIndentation:
15+
Layout/ClosingHeredocIndentation:
1816
Enabled: true
1917

2018
# Align comments with method definitions.
21-
Style/CommentIndentation:
19+
Layout/CommentIndentation:
20+
Enabled: true
21+
22+
Layout/ElseAlignment:
23+
Enabled: true
24+
25+
# Align `end` with the matching keyword or starting expression except for
26+
# assignments, where it should be aligned with the LHS.
27+
Layout/EndAlignment:
28+
Enabled: true
29+
EnforcedStyleAlignWith: variable
30+
AutoCorrect: true
31+
32+
Layout/EmptyLineAfterMagicComment:
2233
Enabled: true
2334

24-
# No extra empty lines.
25-
Style/EmptyLines:
35+
Layout/EmptyLinesAroundAccessModifier:
36+
Enabled: true
37+
EnforcedStyle: only_before
38+
39+
Layout/EmptyLinesAroundBlockBody:
2640
Enabled: true
2741

2842
# In a regular class definition, no empty lines around the body.
29-
Style/EmptyLinesAroundClassBody:
43+
Layout/EmptyLinesAroundClassBody:
44+
Enabled: true
45+
46+
# In a regular method definition, no empty lines around the body.
47+
Layout/EmptyLinesAroundMethodBody:
3048
Enabled: true
3149

3250
# In a regular module definition, no empty lines around the body.
33-
Style/EmptyLinesAroundModuleBody:
51+
Layout/EmptyLinesAroundModuleBody:
3452
Enabled: true
3553

3654
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
3755
Style/HashSyntax:
3856
Enabled: true
3957

58+
Layout/FirstArgumentIndentation:
59+
Enabled: true
60+
4061
# Method definitions after `private` or `protected` isolated calls need one
4162
# extra level of indentation.
42-
Style/IndentationConsistency:
63+
Layout/IndentationConsistency:
4364
Enabled: true
44-
EnforcedStyle: rails
65+
EnforcedStyle: indented_internal_methods
4566

4667
# Two spaces, no tabs (for indentation).
47-
Style/IndentationWidth:
68+
Layout/IndentationWidth:
69+
Enabled: true
70+
71+
Layout/LeadingCommentSpace:
72+
Enabled: true
73+
74+
Layout/SpaceAfterColon:
75+
Enabled: true
76+
77+
Layout/SpaceAfterComma:
78+
Enabled: true
79+
80+
Layout/SpaceAfterSemicolon:
4881
Enabled: true
4982

50-
Style/SpaceAfterColon:
83+
Layout/SpaceAroundEqualsInParameterDefault:
5184
Enabled: true
5285

53-
Style/SpaceAfterComma:
86+
Layout/SpaceAroundKeyword:
5487
Enabled: true
5588

56-
Style/SpaceAroundEqualsInParameterDefault:
89+
Layout/SpaceBeforeComma:
5790
Enabled: true
5891

59-
Style/SpaceAroundKeyword:
92+
Layout/SpaceBeforeComment:
6093
Enabled: true
6194

62-
Style/SpaceAroundOperators:
95+
Layout/SpaceBeforeFirstArg:
6396
Enabled: true
6497

65-
Style/SpaceBeforeFirstArg:
66-
Enabled: true
98+
Style/DefWithParentheses:
99+
Enabled: true
67100

68101
# Defining a method with parameters needs parentheses.
69102
Style/MethodDefParentheses:
70103
Enabled: true
71104

105+
Style/RedundantFreeze:
106+
Enabled: true
107+
72108
# Use `foo {}` not `foo{}`.
73-
Style/SpaceBeforeBlockBraces:
109+
Layout/SpaceBeforeBlockBraces:
74110
Enabled: true
75111

76112
# Use `foo { bar }` not `foo {bar}`.
77-
Style/SpaceInsideBlockBraces:
113+
Layout/SpaceInsideBlockBraces:
78114
Enabled: true
115+
EnforcedStyleForEmptyBraces: space
79116

80117
# Use `{ a: 1 }` not `{a:1}`.
81-
Style/SpaceInsideHashLiteralBraces:
118+
Layout/SpaceInsideHashLiteralBraces:
82119
Enabled: true
83120

84-
Style/SpaceInsideParens:
121+
Layout/SpaceInsideParens:
85122
Enabled: true
86123

87124
# Check quotes usage according to lint rule below.
@@ -90,27 +127,66 @@ Style/StringLiterals:
90127
EnforcedStyle: double_quotes
91128

92129
# Detect hard tabs, no hard tabs.
93-
Style/Tab:
130+
Layout/Tab:
94131
Enabled: true
95132

96-
# Blank lines should not have any spaces.
97-
Style/TrailingBlankLines:
133+
# Empty lines should not have any spaces.
134+
Layout/TrailingEmptyLines:
98135
Enabled: true
99136

100137
# No trailing whitespace.
101-
Style/TrailingWhitespace:
138+
Layout/TrailingWhitespace:
102139
Enabled: true
103140

104141
# Use quotes for string literals when they are enough.
105-
Style/UnneededPercentQ:
142+
Style/RedundantPercentQ:
106143
Enabled: true
107144

108-
# Align `end` with the matching keyword or starting expression except for
109-
# assignments, where it should be aligned with the LHS.
110-
Lint/EndAlignment:
145+
Lint/AmbiguousOperator:
146+
Enabled: true
147+
148+
Lint/AmbiguousRegexpLiteral:
149+
Enabled: true
150+
151+
Lint/ErbNewArguments:
111152
Enabled: true
112-
AlignWith: variable
113153

114154
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
115155
Lint/RequireParentheses:
116156
Enabled: true
157+
158+
Lint/ShadowingOuterLocalVariable:
159+
Enabled: true
160+
161+
Lint/RedundantStringCoercion:
162+
Enabled: true
163+
164+
Lint/UriEscapeUnescape:
165+
Enabled: true
166+
167+
Lint/UselessAssignment:
168+
Enabled: true
169+
170+
Lint/DeprecatedClassMethods:
171+
Enabled: true
172+
173+
Style/ParenthesesAroundCondition:
174+
Enabled: true
175+
176+
Style/RedundantBegin:
177+
Enabled: true
178+
179+
Style/RedundantReturn:
180+
Enabled: true
181+
AllowMultipleReturnValues: true
182+
183+
Style/Semicolon:
184+
Enabled: true
185+
AllowAsExpressionSeparator: true
186+
187+
# Prefer Foo.method over Foo::method
188+
Style/ColonMethodCall:
189+
Enabled: true
190+
191+
Style/TrivialAccessors:
192+
Enabled: true

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ source "https://rubygems.org"
33
gemspec
44

55
gem "rails"
6+
gem "rubocop", ">= 0.77.0", require: false

actionpack-page_caching.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ Gem::Specification.new do |gem|
88
gem.homepage = "https://github.com/rails/actionpack-page_caching"
99
gem.license = "MIT"
1010

11-
gem.required_ruby_version = '>= 2.4.6'
11+
gem.required_ruby_version = ">= 2.4.6"
1212
gem.files = `git ls-files`.split($/)
1313
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
1414
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
1515
gem.require_paths = ["lib"]
16-
gem.license = 'MIT'
16+
gem.license = "MIT"
1717

1818
gem.add_dependency "actionpack", ">= 5.0.0"
1919

lib/action_controller/caching/pages.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ def raise_runtime_error
136136
MSG
137137
end
138138

139-
def default_extension
140-
@default_extension
141-
end
139+
attr_reader :default_extension
142140

143141
def cache_file(path, extension)
144142
if path.empty? || path =~ %r{\A/+\z}
@@ -276,10 +274,10 @@ def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
276274
end
277275

278276
type = if self.respond_to?(:media_type)
279-
Mime::LOOKUP[self.media_type]
280-
else
281-
Mime::LOOKUP[self.content_type]
282-
end
277+
Mime::LOOKUP[self.media_type]
278+
else
279+
Mime::LOOKUP[self.content_type]
280+
end
283281

284282
if type && (type_symbol = type.symbol).present?
285283
extension = ".#{type_symbol}"

test/caching_test.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def teardown
2424
end
2525

2626
private
27-
2827
def assert_page_cached(action, options = {})
2928
expected = options[:content] || action.to_s
3029
path = cache_file(action, options)
@@ -330,19 +329,17 @@ def test_page_caching_conditional_options
330329
end
331330

332331
def test_page_caching_directory_set_as_pathname
333-
begin
334-
ActionController::Base.page_cache_directory = Pathname.new(FILE_STORE_PATH)
335-
336-
draw do
337-
get "/page_caching_test/ok", to: "page_caching_test#ok"
338-
end
332+
ActionController::Base.page_cache_directory = Pathname.new(FILE_STORE_PATH)
339333

340-
get :ok
341-
assert_response :ok
342-
assert_page_cached :ok
343-
ensure
344-
ActionController::Base.page_cache_directory = FILE_STORE_PATH
334+
draw do
335+
get "/page_caching_test/ok", to: "page_caching_test#ok"
345336
end
337+
338+
get :ok
339+
assert_response :ok
340+
assert_page_cached :ok
341+
ensure
342+
ActionController::Base.page_cache_directory = FILE_STORE_PATH
346343
end
347344

348345
def test_page_caching_directory_set_on_controller_instance

0 commit comments

Comments
 (0)