rails_best_practices 1.14.0 → 1.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f156688bf7014687ef1fbe360333886dabc39369
4
- data.tar.gz: 18c27a29f89c40d5c4fc621719685f5b281cc480
3
+ metadata.gz: 9d6e0107b4ea24053498f1c9996cf1109cd7f7ca
4
+ data.tar.gz: 136b20157ca9b1f557d69955fc320e018be97749
5
5
  SHA512:
6
- metadata.gz: e59f2708ddd9c4e71d2e3d9be3544ddd05411d9ca038387a33bcc3c48ebf1a059d945421137b151ddaad9a4c67b91d17944e0f7caae70a5fed3cd21cfc6a9657
7
- data.tar.gz: 51edce3a83696df402cebe5e20e32b1108c8dd2d594d05f54d47215585e7364b1cd929967e7fb6bf7ea6296b5904e7720426c23d843e7b251b7053a5fe059f95
6
+ metadata.gz: c565ecd5732afe084d926f71fdd4780e4a6201d79f6fa9406a5acf115faced692731935b042b87ee7915e76adab2cce1fe481c00e718002e913854199cd21f89
7
+ data.tar.gz: 0d9f67c5435ee528e2f0f17ad1d866bb3f4ee88c340ece9732002ea8247a5f21ec3a4417eda96c994f45e43f353020cf59959f809012a875d2055c37cf6fe9fe
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # rails_best_practices
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/rails_best_practices.png)](http://badge.fury.io/rb/rails_best_practices)
3
4
  [![Build Status](https://secure.travis-ci.org/railsbp/rails_best_practices.png)](http://travis-ci.org/railsbp/rails_best_practices)
4
- [![Coverage
5
- Status](https://coveralls.io/repos/railsbp/rails_best_practices/badge.png?branch=master)](https://coveralls.io/r/railsbp/rails_best_practices)
6
- [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
5
+ [![Coverage Status](https://coveralls.io/repos/railsbp/rails_best_practices/badge.png?branch=master)](https://coveralls.io/r/railsbp/rails_best_practices)
6
+ [![Code Climate](https://codeclimate.com/repos/51eb7073f3ea00179b00db0b/badges/095127e7bb641dbc825b/gpa.png)](https://codeclimate.com/repos/51eb7073f3ea00179b00db0b/feed)
7
7
 
8
+ [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
8
9
  [![Click here to lend your support to: rails best practices and make a donation at www.pledgie.com !](http://www.pledgie.com/campaigns/12057.png?skin_name=chrome)](http://www.pledgie.com/campaigns/12057)
9
10
 
10
11
  rails_best_practices is a code metric tool to check the quality of rails codes.
@@ -46,7 +46,7 @@ module RailsBestPractices
46
46
  # @param [String] message, is the string message for violation of the rails best practice
47
47
  # @param [String] filename, is the filename of source code
48
48
  # @param [Integer] line_number, is the line number of the source code which is reviewing
49
- def add_error(message, filename = @node.file, line_number = @node.line)
49
+ def add_error(message, filename = @node.file, line_number = @node.line_number)
50
50
  errors << RailsBestPractices::Core::Error.new(
51
51
  filename: filename,
52
52
  line_number: line_number,
@@ -12,7 +12,7 @@ module RailsBestPractices
12
12
  #
13
13
  # @param [String] class name
14
14
  # @param [String] method name
15
- # @param [Hash] method meta, file and line, {"file" => "app/models/post.rb", "line" => 5}
15
+ # @param [Hash] method meta, file and line, {"file" => "app/models/post.rb", "line_number" => 5}
16
16
  # @param [String] access control, public, protected or private
17
17
  def add_method(class_name, method_name, meta={}, access_control="public")
18
18
  return if class_name == ""
@@ -141,15 +141,15 @@ module RailsBestPractices
141
141
  end
142
142
  end
143
143
 
144
- # Method info includes class name, method name, access control, file, line, used.
144
+ # Method info includes class name, method name, access control, file, line_number, used.
145
145
  class Method
146
- attr_reader :access_control, :class_name, :method_name, :used, :file, :line
146
+ attr_reader :access_control, :class_name, :method_name, :used, :file, :line_number
147
147
 
148
148
  def initialize(class_name, method_name, access_control, meta)
149
149
  @class_name = class_name
150
150
  @method_name = method_name
151
151
  @file = meta["file"]
152
- @line = meta["line"]
152
+ @line_number = meta["line_number"]
153
153
  @access_control = access_control
154
154
  @used = false
155
155
  end
@@ -163,6 +163,7 @@ module RailsBestPractices
163
163
  def publicize
164
164
  @access_control = "public"
165
165
  end
166
+
166
167
  end
167
168
  end
168
169
  end
@@ -32,7 +32,7 @@ module RailsBestPractices
32
32
  add_callback :end_class do |node|
33
33
  if @inherited_resources && "ApplicationController" != current_class_name
34
34
  @actions.each do |action|
35
- @methods.add_method(current_class_name, action, {"file" => node.file, "line" => node.line})
35
+ @methods.add_method(current_class_name, action, {"file" => node.file, "line_number" => node.line_number})
36
36
  end
37
37
  end
38
38
  end
@@ -73,16 +73,16 @@ module RailsBestPractices
73
73
  # the remembered methods (@methods) are like
74
74
  # {
75
75
  # "PostsController" => {
76
- # "save" => {"file" => "app/controllers/posts_controller.rb", "line" => 10, "unused" => false},
77
- # "find" => {"file" => "app/controllers/posts_controller.rb", "line" => 10, "unused" => false}
76
+ # "save" => {"file" => "app/controllers/posts_controller.rb", "line_number" => 10, "unused" => false},
77
+ # "find" => {"file" => "app/controllers/posts_controller.rb", "line_number" => 10, "unused" => false}
78
78
  # },
79
79
  # "CommentsController" => {
80
- # "create" => {"file" => "app/controllers/comments_controller.rb", "line" => 10, "unused" => false},
80
+ # "create" => {"file" => "app/controllers/comments_controller.rb", "line_number" => 10, "unused" => false},
81
81
  # }
82
82
  # }
83
83
  add_callback :start_def do |node|
84
84
  method_name = node.method_name.to_s
85
- @methods.add_method(current_class_name, method_name, {"file" => node.file, "line" => node.line}, current_access_control)
85
+ @methods.add_method(current_class_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
86
86
  end
87
87
 
88
88
  # ask Reviews::RemoveUnusedMoethodsInHelperReview to check the controllers who include helpers.
@@ -24,14 +24,14 @@ module RailsBestPractices
24
24
  # the remembered methods (@methods) are like
25
25
  # {
26
26
  # "PostsHelper" => {
27
- # "create_time" => {"file" => "app/helpers/posts_helper.rb", "line" => 10, "unused" => false},
28
- # "update_time" => {"file" => "app/helpers/posts_helper.rb", "line" => 10, "unused" => false}
27
+ # "create_time" => {"file" => "app/helpers/posts_helper.rb", "line_number" => 10, "unused" => false},
28
+ # "update_time" => {"file" => "app/helpers/posts_helper.rb", "line_number" => 10, "unused" => false}
29
29
  # }
30
30
  # }
31
31
  add_callback :start_def do |node|
32
32
  if node.file =~ HELPER_FILES
33
33
  method_name = node.method_name.to_s
34
- @methods.add_method(current_module_name, method_name, {"file" => node.file, "line" => node.line}, current_access_control)
34
+ @methods.add_method(current_module_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
35
35
  end
36
36
  end
37
37
  end
@@ -30,11 +30,11 @@ module RailsBestPractices
30
30
  # the remembered methods (@methods) are like
31
31
  # {
32
32
  # "Post" => {
33
- # "save" => {"file" => "app/models/post.rb", "line" => 10, "unused" => false, "unused" => false},
34
- # "find" => {"file" => "app/models/post.rb", "line" => 10, "unused" => false, "unused" => false}
33
+ # "save" => {"file" => "app/models/post.rb", "line_number" => 10, "unused" => false, "unused" => false},
34
+ # "find" => {"file" => "app/models/post.rb", "line_number" => 10, "unused" => false, "unused" => false}
35
35
  # },
36
36
  # "Comment" => {
37
- # "create" => {"file" => "app/models/comment.rb", "line" => 10, "unused" => false, "unused" => false},
37
+ # "create" => {"file" => "app/models/comment.rb", "line_number" => 10, "unused" => false, "unused" => false},
38
38
  # }
39
39
  # }
40
40
  add_callback :start_def do |node|
@@ -42,7 +42,7 @@ module RailsBestPractices
42
42
  "ActionMailer::Base" != current_extend_class_name &&
43
43
  (classable_modules.empty? || klasses.any?)
44
44
  method_name = node.method_name.to_s
45
- @methods.add_method(current_class_name, method_name, {"file" => node.file, "line" => node.line}, current_access_control)
45
+ @methods.add_method(current_class_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
46
46
  end
47
47
  end
48
48
 
@@ -51,17 +51,17 @@ module RailsBestPractices
51
51
  # the remembered methods (@methods) are like
52
52
  # {
53
53
  # "Post" => {
54
- # "save" => {"file" => "app/models/post.rb", "line" => 10, "unused" => false, "unused" => false},
55
- # "find" => {"file" => "app/models/post.rb", "line" => 10, "unused" => false, "unused" => false}
54
+ # "save" => {"file" => "app/models/post.rb", "line_number" => 10, "unused" => false, "unused" => false},
55
+ # "find" => {"file" => "app/models/post.rb", "line_number" => 10, "unused" => false, "unused" => false}
56
56
  # },
57
57
  # "Comment" => {
58
- # "create" => {"file" => "app/models/comment.rb", "line" => 10, "unused" => false, "unused" => false},
58
+ # "create" => {"file" => "app/models/comment.rb", "line_number" => 10, "unused" => false, "unused" => false},
59
59
  # }
60
60
  # }
61
61
  add_callback :start_defs do |node|
62
62
  if @klass && "ActionMailer::Base" != current_extend_class_name
63
63
  method_name = node.method_name.to_s
64
- @methods.add_method(current_class_name, method_name, {"file" => node.file, "line" => node.line}, current_access_control)
64
+ @methods.add_method(current_class_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
65
65
  end
66
66
  end
67
67
 
@@ -80,11 +80,11 @@ module RailsBestPractices
80
80
  case node.message.to_s
81
81
  when *%w(named_scope scope alias_method)
82
82
  method_name = node.arguments.all.first.to_s
83
- @methods.add_method(current_class_name, method_name, {"file" => node.file, "line" => node.line}, current_access_control)
83
+ @methods.add_method(current_class_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
84
84
  when "alias_method_chain"
85
85
  method, feature = *node.arguments.all.map(&:to_s)
86
- @methods.add_method(current_class_name, "#{method}_with_#{feature}", {"file" => node.file, "line" => node.line}, current_access_control)
87
- @methods.add_method(current_class_name, "#{method}", {"file" => node.file, "line" => node.line}, current_access_control)
86
+ @methods.add_method(current_class_name, "#{method}_with_#{feature}", {"file" => node.file, "line_number" => node.line_number}, current_access_control)
87
+ @methods.add_method(current_class_name, "#{method}", {"file" => node.file, "line_number" => node.line_number}, current_access_control)
88
88
  when "field"
89
89
  arguments = node.arguments.all
90
90
  attribute_name = arguments.first.to_s
@@ -102,7 +102,7 @@ module RailsBestPractices
102
102
  # check alias node to remembr the alias methods.
103
103
  add_callback :start_alias do |node|
104
104
  method_name = node.new_method.to_s
105
- @methods.add_method(current_class_name, method_name, {"file" => node.file, "line" => node.line}, current_access_control)
105
+ @methods.add_method(current_class_name, method_name, {"file" => node.file, "line_number" => node.line_number}, current_access_control)
106
106
  end
107
107
 
108
108
  # after prepare process, fix incorrect associations' class_name.
@@ -74,7 +74,7 @@ module RailsBestPractices
74
74
  table_node = @table_nodes[table]
75
75
  foreign_key.each do |column|
76
76
  if not_indexed?(table, column)
77
- add_error "always add db index (#{table} => [#{Array(column).join(', ')}])", table_node.file, table_node.line
77
+ add_error "always add db index (#{table} => [#{Array(column).join(', ')}])", table_node.file, table_node.line_number
78
78
  end
79
79
  end
80
80
  end
@@ -31,7 +31,7 @@ module RailsBestPractices
31
31
  # and the message of the right value node is one of the find, all, first and last,
32
32
  # then it is a finder and should be moved to controller.
33
33
  add_callback :start_assign do |node|
34
- add_error "move code into controller", node.file, node.right_value.line if finder?(node.right_value)
34
+ add_error "move code into controller", node.file, node.right_value.line_number if finder?(node.right_value)
35
35
  end
36
36
 
37
37
  private
@@ -70,7 +70,7 @@ module RailsBestPractices
70
70
  end
71
71
  @counter -= 1
72
72
  elsif [:command_call, :command].include?(node.sexp_type) && ["resources", "resource"].include?(node.message.to_s)
73
- add_error "needless deep nesting (nested_count > #{@nested_count})", @file, node.line if @counter >= @nested_count && !@shallow_nodes.include?(node)
73
+ add_error "needless deep nesting (nested_count > #{@nested_count})", @file, node.line_number if @counter >= @nested_count && !@shallow_nodes.include?(node)
74
74
  end
75
75
  end
76
76
  end
@@ -18,7 +18,7 @@ module RailsBestPractices
18
18
  # check rescue node to see if its type is Exception
19
19
  add_callback :start_rescue do |rescue_node|
20
20
  if rescue_node.exception_classes.any? { |rescue_class| "Exception" == rescue_class.to_s }
21
- add_error "not rescue Exception", rescue_node.file, rescue_node.exception_classes.first.line
21
+ add_error "not rescue Exception", rescue_node.file, rescue_node.exception_classes.first.line_number
22
22
  end
23
23
  end
24
24
  end
@@ -46,7 +46,7 @@ module RailsBestPractices
46
46
  # then they are overuse route customizations.
47
47
  add_callback :start_command_call do |node|
48
48
  if member_and_collection_count_for_rails2(node) > @customize_count
49
- add_error "overuse route customizations (customize_count > #{@customize_count})", node.file, node.receiver.line
49
+ add_error "overuse route customizations (customize_count > #{@customize_count})", node.file, node.receiver.line_number
50
50
  end
51
51
  end
52
52
 
@@ -59,7 +59,7 @@ module RailsBestPractices
59
59
  # then they are overuse route customizations.
60
60
  add_callback :start_method_add_block do |node|
61
61
  if member_and_collection_count_for_rails3(node) > @customize_count
62
- add_error "overuse route customizations (customize_count > #{@customize_count})", node.file, node.line
62
+ add_error "overuse route customizations (customize_count > #{@customize_count})", node.file, node.line_number
63
63
  end
64
64
  end
65
65
 
@@ -94,7 +94,7 @@ module RailsBestPractices
94
94
  end
95
95
  @controller_methods.get_all_unused_methods.each do |method|
96
96
  if !excepted?(method)
97
- add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line
97
+ add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line_number
98
98
  end
99
99
  end
100
100
  end
@@ -26,7 +26,7 @@ module RailsBestPractices
26
26
  add_callback :after_check do
27
27
  @helper_methods.get_all_unused_methods.each do |method|
28
28
  if !excepted?(method)
29
- add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line
29
+ add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line_number
30
30
  end
31
31
  end
32
32
  end
@@ -80,7 +80,7 @@ module RailsBestPractices
80
80
  add_callback :after_check do
81
81
  @model_methods.get_all_unused_methods.each do |method|
82
82
  if !excepted?(method) && method.method_name !~ /=$/
83
- add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line
83
+ add_error "remove unused methods (#{method.class_name}##{method.method_name})", method.file, method.line_number
84
84
  end
85
85
  end
86
86
  end
@@ -2,14 +2,14 @@
2
2
  module RailsBestPractices
3
3
  module Reviews
4
4
  # Review a controller file to make sure to use before_filter to remove duplicated first code
5
- # line in different action.
5
+ # line_number in different action.
6
6
  #
7
7
  # See the best practice detailed here http://rails-bestpractices.com/posts/22-use-before_filter.
8
8
  #
9
9
  # Implementation:
10
10
  #
11
11
  # Review process:
12
- # check all first code line in method definitions (actions),
12
+ # check all first code line_number in method definitions (actions),
13
13
  # if they are duplicated, then they should be moved to before_filter.
14
14
  class UseBeforeFilterReview < Review
15
15
  interesting_nodes :class
@@ -21,11 +21,11 @@ module RailsBestPractices
21
21
  @customize_count = options['customize_count'] || 2
22
22
  end
23
23
 
24
- # check class define node to see if there are method define nodes whose first code line are duplicated.
24
+ # check class define node to see if there are method define nodes whose first code line_number are duplicated.
25
25
  #
26
26
  # it will check every def nodes in the class node until protected or private identification,
27
- # if there are defn nodes who have the same first code line,
28
- # then these duplicated first code lines should be moved to before_filter.
27
+ # if there are defn nodes who have the same first code line_number,
28
+ # then these duplicated first code line_numbers should be moved to before_filter.
29
29
  add_callback :start_class do |node|
30
30
  @first_sentences = {}
31
31
 
@@ -39,7 +39,7 @@ module RailsBestPractices
39
39
  if def_nodes.size > @customize_count
40
40
  add_error "use before_filter for #{def_nodes.map { |node| node.method_name.to_s }.join(',')}",
41
41
  node.file,
42
- def_nodes.map(&:line).join(',')
42
+ def_nodes.map(&:line_number).join(',')
43
43
  end
44
44
  end
45
45
  end
@@ -49,7 +49,7 @@ module RailsBestPractices
49
49
  def remember_first_sentence(node)
50
50
  first_sentence = node.body.statements.first
51
51
  return unless first_sentence
52
- first_sentence = first_sentence.remove_line_and_column
52
+ first_sentence = first_sentence.remove_line_number_and_column
53
53
  unless first_sentence == s(:nil)
54
54
  @first_sentences[first_sentence] ||= []
55
55
  @first_sentences[first_sentence] << node
@@ -43,7 +43,7 @@ module RailsBestPractices
43
43
  receiver_node = query_attribute_node.receiver
44
44
  add_error "use query attribute (#{receiver_node.receiver}.#{receiver_node.message}?)",
45
45
  node.file,
46
- query_attribute_node.line
46
+ query_attribute_node.line_number
47
47
  end
48
48
  end
49
49
  end
@@ -39,7 +39,7 @@ module RailsBestPractices
39
39
  child_node
40
40
  end
41
41
  if :call == receiver_node.sexp_type
42
- add_error("use say with time in migrations", node.file, child_node.line)
42
+ add_error("use say with time in migrations", node.file, child_node.line_number)
43
43
  end
44
44
  end
45
45
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.14.0"
3
+ VERSION = "1.14.1"
4
4
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.add_dependency("activesupport")
18
18
  s.add_dependency("awesome_print")
19
- s.add_dependency("code_analyzer")
19
+ s.add_dependency("code_analyzer", ">= 0.4.0")
20
20
  s.add_dependency("colored")
21
21
  s.add_dependency("erubis")
22
22
  s.add_dependency("i18n")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-21 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.4.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.4.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: colored
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -398,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
398
  version: 1.3.6
399
399
  requirements: []
400
400
  rubyforge_project:
401
- rubygems_version: 2.0.3
401
+ rubygems_version: 2.0.6
402
402
  signing_key:
403
403
  specification_version: 4
404
404
  summary: a code metric tool for rails codes.