Skip to content

Commit 8b679b1

Browse files
committed
Add rubocop and fix offenses
1 parent 54bd795 commit 8b679b1

File tree

12 files changed

+298
-176
lines changed

12 files changed

+298
-176
lines changed

.codeclimate.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
engines:
2+
rubocop:
3+
enabled: true
4+
5+
ratings:
6+
paths:
7+
- "**.rb"

.rubocop.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
AllCops:
2+
TargetRubyVersion: 2.2
3+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4+
# to ignore them, so only the ones explicitly set in this file are enabled.
5+
DisabledByDefault: true
6+
7+
# Prefer &&/|| over and/or.
8+
Style/AndOr:
9+
Enabled: true
10+
11+
# Do not use braces for hash literals when they are the last argument of a
12+
# method call.
13+
Style/BracesAroundHashParameters:
14+
Enabled: true
15+
16+
# Align `when` with `case`.
17+
Style/CaseIndentation:
18+
Enabled: true
19+
20+
# Align comments with method definitions.
21+
Style/CommentIndentation:
22+
Enabled: true
23+
24+
# No extra empty lines.
25+
Style/EmptyLines:
26+
Enabled: true
27+
28+
# In a regular class definition, no empty lines around the body.
29+
Style/EmptyLinesAroundClassBody:
30+
Enabled: true
31+
32+
# In a regular module definition, no empty lines around the body.
33+
Style/EmptyLinesAroundModuleBody:
34+
Enabled: true
35+
36+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
37+
Style/HashSyntax:
38+
Enabled: true
39+
40+
# Method definitions after `private` or `protected` isolated calls need one
41+
# extra level of indentation.
42+
Style/IndentationConsistency:
43+
Enabled: true
44+
EnforcedStyle: rails
45+
46+
# Two spaces, no tabs (for indentation).
47+
Style/IndentationWidth:
48+
Enabled: true
49+
50+
Style/SpaceAfterColon:
51+
Enabled: true
52+
53+
Style/SpaceAfterComma:
54+
Enabled: true
55+
56+
Style/SpaceAroundEqualsInParameterDefault:
57+
Enabled: true
58+
59+
Style/SpaceAroundKeyword:
60+
Enabled: true
61+
62+
Style/SpaceAroundOperators:
63+
Enabled: true
64+
65+
Style/SpaceBeforeFirstArg:
66+
Enabled: true
67+
68+
# Defining a method with parameters needs parentheses.
69+
Style/MethodDefParentheses:
70+
Enabled: true
71+
72+
# Use `foo {}` not `foo{}`.
73+
Style/SpaceBeforeBlockBraces:
74+
Enabled: true
75+
76+
# Use `foo { bar }` not `foo {bar}`.
77+
Style/SpaceInsideBlockBraces:
78+
Enabled: true
79+
80+
# Use `{ a: 1 }` not `{a:1}`.
81+
Style/SpaceInsideHashLiteralBraces:
82+
Enabled: true
83+
84+
Style/SpaceInsideParens:
85+
Enabled: true
86+
87+
# Check quotes usage according to lint rule below.
88+
Style/StringLiterals:
89+
Enabled: true
90+
EnforcedStyle: double_quotes
91+
92+
# Detect hard tabs, no hard tabs.
93+
Style/Tab:
94+
Enabled: true
95+
96+
# Blank lines should not have any spaces.
97+
Style/TrailingBlankLines:
98+
Enabled: true
99+
100+
# No trailing whitespace.
101+
Style/TrailingWhitespace:
102+
Enabled: true
103+
104+
# Use quotes for string literals when they are enough.
105+
Style/UnneededPercentQ:
106+
Enabled: true
107+
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:
111+
Enabled: true
112+
AlignWith: variable
113+
114+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
115+
Lint/RequireParentheses:
116+
Enabled: true

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
source 'https://rubygems.org'
1+
source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rails'
5+
gem "rails"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Installation
88

99
Add this line to your application's Gemfile:
1010

11-
gem 'actionpack-action_caching'
11+
gem "actionpack-action_caching"
1212

1313
And then execute:
1414

@@ -54,8 +54,8 @@ Different representations of the same resource, e.g.
5454
`http://david.example.com/lists.xml`
5555
are treated like separate requests and so are cached separately.
5656
Keep in mind when expiring an action cache that
57-
`action: 'lists'` is not the same as
58-
`action: 'list', format: :xml`.
57+
`action: "lists"` is not the same as
58+
`action: "list", format: :xml`.
5959

6060
You can modify the default action cache path by passing a
6161
`:cache_path` option. This will be passed directly to

Rakefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env rake
2-
require 'bundler/gem_tasks'
3-
require 'rake/testtask'
2+
require "bundler/gem_tasks"
3+
require "rake/testtask"
44

55
Rake::TestTask.new do |t|
6-
t.libs = ['test']
7-
t.pattern = 'test/**/*_test.rb'
8-
t.ruby_opts = ['-w']
6+
t.libs = ["test"]
7+
t.pattern = "test/**/*_test.rb"
8+
t.ruby_opts = ["-w"]
99
end
1010

1111
task default: :test

actionpack-action_caching.gemspec

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
Gem::Specification.new do |gem|
2-
gem.name = 'actionpack-action_caching'
3-
gem.version = '1.1.1'
4-
gem.author = 'David Heinemeier Hansson'
5-
gem.email = '[email protected]'
6-
gem.description = 'Action caching for Action Pack (removed from core in Rails 4.0)'
7-
gem.summary = 'Action caching for Action Pack (removed from core in Rails 4.0)'
8-
gem.homepage = 'https://github.com/rails/actionpack-action_caching'
2+
gem.name = "actionpack-action_caching"
3+
gem.version = "1.1.1"
4+
gem.author = "David Heinemeier Hansson"
5+
gem.email = "[email protected]"
6+
gem.description = "Action caching for Action Pack (removed from core in Rails 4.0)"
7+
gem.summary = "Action caching for Action Pack (removed from core in Rails 4.0)"
8+
gem.homepage = "https://github.com/rails/actionpack-action_caching"
99

10-
gem.required_ruby_version = '>= 1.9.3'
10+
gem.required_ruby_version = ">= 1.9.3"
1111
gem.files = `git ls-files`.split($/)
12-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
1313
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14-
gem.require_paths = ['lib']
15-
gem.license = 'MIT'
14+
gem.require_paths = ["lib"]
15+
gem.license = "MIT"
1616

1717
gem.add_dependency "actionpack", ">= 4.0.0", "< 6"
1818

lib/action_controller/action_caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'action_controller/caching/actions'
1+
require "action_controller/caching/actions"
22

33
module ActionController
44
module Caching

lib/action_controller/caching/actions.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'set'
1+
require "set"
22

33
module ActionController
44
module Caching
@@ -35,8 +35,8 @@ module Caching
3535
# <tt>http://david.example.com/lists.xml</tt>
3636
# are treated like separate requests and so are cached separately.
3737
# Keep in mind when expiring an action cache that
38-
# <tt>action: 'lists'</tt> is not the same as
39-
# <tt>action: 'lists', format: :xml</tt>.
38+
# <tt>action: "lists"</tt> is not the same as
39+
# <tt>action: "lists", format: :xml</tt>.
4040
#
4141
# You can modify the default action cache path by passing a
4242
# <tt>:cache_path</tt> option. This will be passed directly to
@@ -85,7 +85,7 @@ module Caching
8585
# end
8686
# end
8787
#
88-
# caches_action :posts, cache_path: CachePathCreator.new('posts')
88+
# caches_action :posts, cache_path: CachePathCreator.new("posts")
8989
# end
9090
#
9191
# If you pass <tt>layout: false</tt>, it will only cache your action
@@ -118,7 +118,7 @@ def caches_action(*actions)
118118
end
119119

120120
def _save_fragment(name, options)
121-
content = ''
121+
content = ""
122122
response_body.each do |parts|
123123
content << parts
124124
end
@@ -179,7 +179,7 @@ def around(controller)
179179
controller.content_type = Mime[cache_path.extension || :html]
180180
end
181181

182-
if ActionPack::VERSION::STRING < '4.1'
182+
if ActionPack::VERSION::STRING < "4.1"
183183
def render_to_string(controller, body)
184184
controller.render_to_string(text: body, layout: true)
185185
end
@@ -203,15 +203,15 @@ def initialize(controller, options = {}, infer_extension = true)
203203
options.reverse_merge!(format: @extension) if options.is_a?(Hash)
204204
end
205205

206-
path = controller.url_for(options).split('://', 2).last
206+
path = controller.url_for(options).split("://", 2).last
207207
@path = normalize!(path)
208208
end
209209

210210
private
211211
def normalize!(path)
212212
ext = URI.parser.escape(extension.to_s) if extension
213-
path << 'index' if path[-1] == ?/
214-
path << ".#{ext}" if extension and !path.split('?', 2).first.ends_with?(".#{ext}")
213+
path << "index" if path[-1] == ?/
214+
path << ".#{ext}" if extension && !path.split("?", 2).first.ends_with?(".#{ext}")
215215
URI.parser.unescape(path)
216216
end
217217
end

lib/actionpack/action_caching.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
require 'actionpack/action_caching/railtie'
1+
require "actionpack/action_caching/railtie"

lib/actionpack/action_caching/railtie.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
require 'rails/railtie'
1+
require "rails/railtie"
22

33
module ActionPack
44
module ActionCaching
55
class Railtie < Rails::Railtie
6-
initializer 'action_pack.action_caching' do
6+
initializer "action_pack.action_caching" do
77
ActiveSupport.on_load(:action_controller) do
8-
require 'action_controller/action_caching'
8+
require "action_controller/action_caching"
99
end
1010
end
1111
end

0 commit comments

Comments
 (0)