rails_best_practices 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/lib/rails_best_practices/core/check.rb +3 -2
- data/lib/rails_best_practices/core/visitable_sexp.rb +2 -0
- data/lib/rails_best_practices/reviews.rb +1 -0
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +33 -0
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.yml +1 -0
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +27 -0
- metadata +6 -3
data/README.md
CHANGED
@@ -110,6 +110,7 @@ Now you can customize this configuration file, the default configuration is as f
|
|
110
110
|
UseMultipartAlternativeAsContentTypeOfEmailCheck: {}
|
111
111
|
SimplifyRenderInViewsCheck: {}
|
112
112
|
SimplifyRenderInControllersCheck: {}
|
113
|
+
RemoveEmptyHelpersCheck: {}
|
113
114
|
|
114
115
|
You can remove or comment one review to disable it, and you can change the options.
|
115
116
|
|
@@ -151,6 +152,11 @@ Migration
|
|
151
152
|
Controller
|
152
153
|
|
153
154
|
1. Use before_filter
|
155
|
+
2. Simplify render in controllers
|
156
|
+
|
157
|
+
Helper
|
158
|
+
|
159
|
+
1. Remove empty helpers
|
154
160
|
|
155
161
|
View
|
156
162
|
|
@@ -4,9 +4,9 @@ module RailsBestPractices
|
|
4
4
|
# A Check class that takes charge of checking the sexp.
|
5
5
|
class Check
|
6
6
|
# only nodes whose node_type is in NODE_TYPE will be reviewed.
|
7
|
-
NODE_TYPES = [:call, :defn, :defs, :if, :class, :lasgn, :iasgn, :ivar, :lvar, :block, :iter, :const]
|
7
|
+
NODE_TYPES = [:call, :defn, :defs, :if, :class, :module, :lasgn, :iasgn, :ivar, :lvar, :block, :iter, :const]
|
8
8
|
|
9
|
-
CONTROLLER_FILES = /
|
9
|
+
CONTROLLER_FILES = /controllers\/.*\.rb$/
|
10
10
|
MIGRATION_FILES = /db\/migrate\/.*\.rb$/
|
11
11
|
MODEL_FILES = /models\/.*\.rb$/
|
12
12
|
MAILER_FILES = /models\/.*mailer\.rb$|mailers\/.*mailer\.rb/
|
@@ -14,6 +14,7 @@ module RailsBestPractices
|
|
14
14
|
PARTIAL_VIEW_FILES = /views\/.*\/_.*\.(erb|haml)$/
|
15
15
|
ROUTE_FILE = /config\/routes\.rb/
|
16
16
|
SCHEMA_FILE = /db\/schema\.rb/
|
17
|
+
HELPER_FILES = /helpers.*\.rb$/
|
17
18
|
|
18
19
|
attr_reader :errors
|
19
20
|
|
@@ -24,3 +24,4 @@ require 'rails_best_practices/reviews/use_query_attribute_review'
|
|
24
24
|
require 'rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review'
|
25
25
|
require 'rails_best_practices/reviews/simplify_render_in_views_review'
|
26
26
|
require 'rails_best_practices/reviews/simplify_render_in_controllers_review'
|
27
|
+
require 'rails_best_practices/reviews/remove_empty_helpers_review'
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails_best_practices/reviews/review'
|
3
|
+
|
4
|
+
module RailsBestPractices
|
5
|
+
module Reviews
|
6
|
+
# Review a helper file to make sure it is not an empty moduel.
|
7
|
+
#
|
8
|
+
# See the best practice details here http://rails-bestpractices.com/posts/72-remove-empty-helpers.
|
9
|
+
#
|
10
|
+
# Implementation:
|
11
|
+
#
|
12
|
+
# Review process:
|
13
|
+
# check all helper files, if the body of module is nil, then the helper file should be removed.
|
14
|
+
class RemoveEmptyHelpersReview < Review
|
15
|
+
def url
|
16
|
+
"http://rails-bestpractices.com/posts/72-remove-empty-helpers"
|
17
|
+
end
|
18
|
+
|
19
|
+
def interesting_files
|
20
|
+
HELPER_FILES
|
21
|
+
end
|
22
|
+
|
23
|
+
def interesting_nodes
|
24
|
+
[:module]
|
25
|
+
end
|
26
|
+
|
27
|
+
# check the body of module node, if it is nil, then it should be removed.
|
28
|
+
def start_module(module_node)
|
29
|
+
add_error "remove empty helpers" if module_node.body.is_a?(Core::Nil)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/rails_best_practices.yml
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe RailsBestPractices::Reviews::RemoveEmptyHelpersReview do
|
4
|
+
let(:runner) { RailsBestPractices::Core::Runner.new(:reviews => RailsBestPractices::Reviews::RemoveEmptyHelpersReview.new) }
|
5
|
+
|
6
|
+
it "should remove empty helpers" do
|
7
|
+
content =<<-EOF
|
8
|
+
module PostsHelper
|
9
|
+
end
|
10
|
+
EOF
|
11
|
+
runner.review('app/helpers/posts_helper.rb', content)
|
12
|
+
runner.should have(1).errors
|
13
|
+
runner.errors[0].to_s.should == "app/helpers/posts_helper.rb:1 - remove empty helpers"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not remove empty helpers" do
|
17
|
+
content =<<-EOF
|
18
|
+
module PostsHelper
|
19
|
+
def post_link(post)
|
20
|
+
post_path(post)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
EOF
|
24
|
+
runner.review('app/helpers/posts_helper.rb', content)
|
25
|
+
runner.should have(0).errors
|
26
|
+
end
|
27
|
+
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.9.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-05-15 00:00:00 +08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- lib/rails_best_practices/reviews/needless_deep_nesting_review.rb
|
194
194
|
- lib/rails_best_practices/reviews/not_use_default_route_review.rb
|
195
195
|
- lib/rails_best_practices/reviews/overuse_route_customizations_review.rb
|
196
|
+
- lib/rails_best_practices/reviews/remove_empty_helpers_review.rb
|
196
197
|
- lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb
|
197
198
|
- lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb
|
198
199
|
- lib/rails_best_practices/reviews/review.rb
|
@@ -236,6 +237,7 @@ files:
|
|
236
237
|
- spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb
|
237
238
|
- spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb
|
238
239
|
- spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb
|
240
|
+
- spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb
|
239
241
|
- spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb
|
240
242
|
- spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
|
241
243
|
- spec/rails_best_practices/reviews/review_spec.rb
|
@@ -278,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
278
280
|
requirements:
|
279
281
|
- - ">="
|
280
282
|
- !ruby/object:Gem::Version
|
281
|
-
hash:
|
283
|
+
hash: 251922047825024421
|
282
284
|
segments:
|
283
285
|
- 0
|
284
286
|
version: "0"
|
@@ -323,6 +325,7 @@ test_files:
|
|
323
325
|
- spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb
|
324
326
|
- spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb
|
325
327
|
- spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb
|
328
|
+
- spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb
|
326
329
|
- spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb
|
327
330
|
- spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb
|
328
331
|
- spec/rails_best_practices/reviews/review_spec.rb
|