rails_best_practices 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -0
- data/lib/rails_best_practices/lexicals/remove_tab_check.rb +26 -0
- data/lib/rails_best_practices/lexicals.rb +1 -0
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +7 -2
- data/lib/rails_best_practices/version.rb +1 -1
- data/lib/rails_best_practices.rb +24 -13
- data/rails_best_practices.yml +6 -5
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +39 -0
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +13 -1
- metadata +6 -3
data/README.md
CHANGED
@@ -111,6 +111,7 @@ Now you can customize this configuration file, the default configuration is as f
|
|
111
111
|
SimplifyRenderInViewsCheck: {}
|
112
112
|
SimplifyRenderInControllersCheck: {}
|
113
113
|
RemoveEmptyHelpersCheck: {}
|
114
|
+
RemoveTabCheck: {}
|
114
115
|
|
115
116
|
You can remove or comment one review to disable it, and you can change the options.
|
116
117
|
|
@@ -173,6 +174,7 @@ Deployment
|
|
173
174
|
Other
|
174
175
|
|
175
176
|
1. Remove Trailing Whitespace
|
177
|
+
2. Remove Tab
|
176
178
|
|
177
179
|
Write Your Own Check List
|
178
180
|
-------------------------
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails_best_practices/core/check'
|
3
|
+
|
4
|
+
module RailsBestPractices
|
5
|
+
module Lexicals
|
6
|
+
# Make sure there are no tabs in files.
|
7
|
+
#
|
8
|
+
# See the best practice details here http://rails-bestpractices.com/posts/81-remove-tab
|
9
|
+
class RemoveTabCheck < Core::Check
|
10
|
+
def url
|
11
|
+
"http://rails-bestpractices.com/posts/81-remove-tab"
|
12
|
+
end
|
13
|
+
|
14
|
+
# check if the content of file contains a tab.
|
15
|
+
#
|
16
|
+
# @param [String] filename name of the file
|
17
|
+
# @param [String] content content of the file
|
18
|
+
def check(filename, content)
|
19
|
+
if content =~ /\t/m
|
20
|
+
line_no = $`.count("\n") + 1
|
21
|
+
add_error("remove tab, use spaces instead", filename, line_no)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb
CHANGED
@@ -54,8 +54,8 @@ module RailsBestPractices
|
|
54
54
|
#
|
55
55
|
# @param [String] name method name in action_mailer
|
56
56
|
def rails3_canonical_mailer_views?(name)
|
57
|
-
(exist?("#{name}.html.erb") && !
|
58
|
-
(exist?("#{name}.html.haml") && !
|
57
|
+
(exist?("#{name}.html.erb") && !haml_or_erb_exists?("#{name}.text")) ||
|
58
|
+
(exist?("#{name}.html.haml") && !haml_or_erb_exists?("#{name}.text") )
|
59
59
|
end
|
60
60
|
|
61
61
|
# check if the filename existed in the mailer directory.
|
@@ -63,6 +63,11 @@ module RailsBestPractices
|
|
63
63
|
File.exist? File.join(mailer_directory, filename)
|
64
64
|
end
|
65
65
|
|
66
|
+
# check if haml or erb exists
|
67
|
+
def haml_or_erb_exists?(filename)
|
68
|
+
exist?("#{filename}.erb") || exist?("#{filename}.haml")
|
69
|
+
end
|
70
|
+
|
66
71
|
# check if the method is a deliver_method.
|
67
72
|
#
|
68
73
|
# @param [String] name the name of the method
|
data/lib/rails_best_practices.rb
CHANGED
@@ -166,19 +166,30 @@ module RailsBestPractices
|
|
166
166
|
# @param [Array] files
|
167
167
|
# @return [Array] sorted files
|
168
168
|
def file_sort files
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
169
|
+
models = []
|
170
|
+
mailers = []
|
171
|
+
files.each do |a|
|
172
|
+
if a =~ Core::Check::MODEL_FILES
|
173
|
+
models << a
|
174
|
+
end
|
175
|
+
end
|
176
|
+
files.each do |a|
|
177
|
+
if a =~ Core::Check::MAILER_FILES
|
178
|
+
mailers << a
|
179
|
+
end
|
180
|
+
end
|
181
|
+
files.collect! do |a|
|
182
|
+
if a =~ Core::Check::MAILER_FILES || a =~ Core::Check::MODEL_FILES
|
183
|
+
#nil
|
184
|
+
else
|
185
|
+
a
|
186
|
+
end
|
187
|
+
end
|
188
|
+
files.compact!
|
189
|
+
models.sort
|
190
|
+
mailers.sort
|
191
|
+
files.sort
|
192
|
+
return models + mailers + files
|
182
193
|
end
|
183
194
|
|
184
195
|
# ignore specific files.
|
data/rails_best_practices.yml
CHANGED
@@ -6,7 +6,7 @@ ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
|
|
6
6
|
MoveModelLogicIntoModelCheck: { use_count: 4 }
|
7
7
|
OveruseRouteCustomizationsCheck: { customize_count: 3 }
|
8
8
|
NeedlessDeepNestingCheck: { nested_count: 2 }
|
9
|
-
NotUseDefaultRouteCheck: {
|
9
|
+
NotUseDefaultRouteCheck: { }
|
10
10
|
KeepFindersOnTheirOwnModelCheck: { }
|
11
11
|
LawOfDemeterCheck: { }
|
12
12
|
UseObserverCheck: { }
|
@@ -21,7 +21,8 @@ DryBundlerInCapistranoCheck: { }
|
|
21
21
|
UseSayWithTimeInMigrationsCheck: { }
|
22
22
|
UseQueryAttributeCheck: { }
|
23
23
|
RemoveTrailingWhitespaceCheck: { }
|
24
|
-
UseMultipartAlternativeAsContentTypeOfEmailCheck: {}
|
25
|
-
SimplifyRenderInViewsCheck: {}
|
26
|
-
SimplifyRenderInControllersCheck: {}
|
27
|
-
RemoveEmptyHelpersCheck: {}
|
24
|
+
UseMultipartAlternativeAsContentTypeOfEmailCheck: { }
|
25
|
+
SimplifyRenderInViewsCheck: { }
|
26
|
+
SimplifyRenderInControllersCheck: { }
|
27
|
+
RemoveEmptyHelpersCheck: { }
|
28
|
+
RemoveTabCheck: { }
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsBestPractices::Lexicals::RemoveTabCheck do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:lexicals => RailsBestPractices::Lexicals::RemoveTabCheck.new) }
|
5
|
+
|
6
|
+
it "should remove tab" do
|
7
|
+
content =<<-EOF
|
8
|
+
class User < ActiveRecord::Base
|
9
|
+
has_many :projects
|
10
|
+
end
|
11
|
+
EOF
|
12
|
+
content.gsub!("\n", "\t\n")
|
13
|
+
runner.lexical('app/models/user.rb', content)
|
14
|
+
runner.should have(1).errors
|
15
|
+
runner.errors[0].to_s.should == "app/models/user.rb:1 - remove tab, use spaces instead"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should remove tab with third line" do
|
19
|
+
content =<<-EOF
|
20
|
+
class User < ActiveRecord::Base
|
21
|
+
has_many :projects
|
22
|
+
\t
|
23
|
+
end
|
24
|
+
EOF
|
25
|
+
runner.lexical('app/models/user.rb', content)
|
26
|
+
runner.should have(1).errors
|
27
|
+
runner.errors[0].to_s.should == "app/models/user.rb:3 - remove tab, use spaces instead"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not remove trailing whitespace" do
|
31
|
+
content =<<-EOF
|
32
|
+
class User < ActiveRecord::Base
|
33
|
+
has_many :projects
|
34
|
+
end
|
35
|
+
EOF
|
36
|
+
runner.lexical('app/models/user.rb', content)
|
37
|
+
runner.should have(0).errors
|
38
|
+
end
|
39
|
+
end
|
@@ -160,7 +160,7 @@ describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmai
|
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should not use multipart/alternative as content_type of email" do
|
163
|
-
mock_email_files(["send_email.html.haml"
|
163
|
+
mock_email_files(["send_email.html.haml", "send_email.text.haml"], "html.haml" => true, "text.haml" => true)
|
164
164
|
runner.review('app/mailers/project_mailer.rb', content)
|
165
165
|
runner.should have(0).errors
|
166
166
|
end
|
@@ -171,6 +171,18 @@ describe RailsBestPractices::Reviews::UseMultipartAlternativeAsContentTypeOfEmai
|
|
171
171
|
runner.should have(0).errors
|
172
172
|
end
|
173
173
|
end
|
174
|
+
|
175
|
+
context "haml/erb mix" do
|
176
|
+
it "should not suggest using multipart/alternative when mixing html.haml and text.erb" do
|
177
|
+
mock_email_files(["send_email.html.haml", "send_email.text.erb"], "html.haml" => true, "text.erb" => true)
|
178
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
179
|
+
runner.should have(0).errors
|
180
|
+
|
181
|
+
mock_email_files(["send_email.html.erb", "send_email.text.haml"], "html.erb" => true, "text.haml" => true)
|
182
|
+
runner.review('app/mailers/project_mailer.rb', content)
|
183
|
+
runner.should have(0).errors
|
184
|
+
end
|
185
|
+
end
|
174
186
|
end
|
175
187
|
end
|
176
188
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.10.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Richard Huang
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-04 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/rails_best_practices/core/visitable_sexp.rb
|
174
174
|
- lib/rails_best_practices/core_ext/enumerable.rb
|
175
175
|
- lib/rails_best_practices/lexicals.rb
|
176
|
+
- lib/rails_best_practices/lexicals/remove_tab_check.rb
|
176
177
|
- lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb
|
177
178
|
- lib/rails_best_practices/prepares.rb
|
178
179
|
- lib/rails_best_practices/prepares/mailer_prepare.rb
|
@@ -219,6 +220,7 @@ files:
|
|
219
220
|
- spec/rails_best_practices/core/nil_spec.rb
|
220
221
|
- spec/rails_best_practices/core/visitable_sexp_spec.rb
|
221
222
|
- spec/rails_best_practices/core_ext/enumerable_spec.rb
|
223
|
+
- spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
|
222
224
|
- spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
|
223
225
|
- spec/rails_best_practices/prepares/mailer_prepare_spec.rb
|
224
226
|
- spec/rails_best_practices/prepares/model_prepare_spec.rb
|
@@ -280,7 +282,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
280
282
|
requirements:
|
281
283
|
- - ">="
|
282
284
|
- !ruby/object:Gem::Version
|
283
|
-
hash:
|
285
|
+
hash: 25522351918325657
|
284
286
|
segments:
|
285
287
|
- 0
|
286
288
|
version: "0"
|
@@ -307,6 +309,7 @@ test_files:
|
|
307
309
|
- spec/rails_best_practices/core/nil_spec.rb
|
308
310
|
- spec/rails_best_practices/core/visitable_sexp_spec.rb
|
309
311
|
- spec/rails_best_practices/core_ext/enumerable_spec.rb
|
312
|
+
- spec/rails_best_practices/lexicals/remove_tab_check_spec.rb
|
310
313
|
- spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb
|
311
314
|
- spec/rails_best_practices/prepares/mailer_prepare_spec.rb
|
312
315
|
- spec/rails_best_practices/prepares/model_prepare_spec.rb
|