rails_best_practices 1.19.2 → 1.19.3

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: e41de74a9e0a16b8a3b3feb2fb709f21aec80098
4
- data.tar.gz: 98f10516376d7de5d3144b767196aa952b274748
3
+ metadata.gz: 4a366fcb2bd3097eb1afcc7fa940b233a4177c6d
4
+ data.tar.gz: 45c9b324f42e0974e7314c1db9e634c782665e93
5
5
  SHA512:
6
- metadata.gz: 21e177d13d0f2137aebe7d683e87af1b97d53046e53b6bbd4722ae943a1061c5c6f740dee8efe9bc713c0be4550b70016849e17033faa6fd17e33a1204645963
7
- data.tar.gz: 81473ba0611d37c8a4a005710983330d0aa6a8c4537ba976e71d93bc670f8ef4fda1d492a44fe1966d2dc0bd91452460ade65f250f252238c187bbe9064e5935
6
+ metadata.gz: fa6aed2c8549d66e9650e456787a57cc32fb052011506e10cdc94ee43803d2016d644ec4e0aae1d9b08d583abb5d2eab7c4dd26eb8754e60bac46a02f8ad4459
7
+ data.tar.gz: 5558cb09e7a4a4f38af75078762d3dba880bd29a97ea2ba743df3e20edf8ca51a0fd3f440808f29043b8d00d99503257de3e18849ea3d6d355930728dd9187f6
@@ -1,5 +1,11 @@
1
1
  # Next Release
2
2
 
3
+ ## 1.19.3
4
+
5
+ * Fix false positive remove unused method for around_action in
6
+ controller
7
+ * Fix current_class_name in end_class callback
8
+
3
9
  ## 1.19.2
4
10
 
5
11
  * Integrate with awesomecode.io
data/README.md CHANGED
@@ -89,13 +89,9 @@ To see the full list of command-line options, run:
89
89
 
90
90
  Homepage: <http://rails-bestpractices.com>
91
91
 
92
- Online Service: <http://railsbp.com>
93
-
94
92
  GitHub: <http://github.com/railsbp/rails_best_practices>
95
93
 
96
- RDoc: <http://rdoc.rails-bestpractices.com>
97
-
98
- Team Blog <http://rails-bestpractices.com/blog/posts>
94
+ Team Blog <http://rails-bestpractices.com>
99
95
 
100
96
  Google Group: <https://groups.google.com/group/rails_best_practices>
101
97
 
data/Rakefile CHANGED
@@ -7,7 +7,7 @@ require 'rake'
7
7
  require 'rspec'
8
8
  require 'rspec/core/rake_task'
9
9
 
10
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
10
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
11
11
  require 'rails_best_practices/version'
12
12
 
13
13
  RSpec::Core::RakeTask.new(:spec) do |spec|
@@ -139,7 +139,7 @@ module RailsBestPractices
139
139
  # end of the class
140
140
  add_callback :end_class do |_node|
141
141
  klasses.pop
142
- # @klass = nil
142
+ @klass = nil
143
143
  end
144
144
  end
145
145
  end
@@ -296,12 +296,12 @@ module RailsBestPractices
296
296
  end
297
297
 
298
298
  def call_method(method_name, class_name = nil)
299
- name ||= respond_to?(:current_class_name) ? current_class_name : current_module_name
300
- if methods.has_method?(name, method_name)
301
- methods.get_method(name, method_name).mark_used
299
+ class_name ||= respond_to?(:current_class_name) ? current_class_name : current_module_name
300
+ if methods.has_method?(class_name, method_name)
301
+ methods.get_method(class_name, method_name).mark_used
302
302
  end
303
- methods.mark_parent_class_method_used(name, method_name)
304
- methods.mark_subclasses_method_used(name, method_name)
303
+ methods.mark_parent_class_method_used(class_name, method_name)
304
+ methods.mark_subclasses_method_used(class_name, method_name)
305
305
  methods.possible_public_used(method_name)
306
306
  end
307
307
  end
@@ -157,7 +157,6 @@ module RailsBestPractices
157
157
 
158
158
  # load all plugin reviews.
159
159
  def load_plugin_reviews
160
-
161
160
  plugins = File.join(Runner.base_path, 'lib', 'rails_best_practices', 'plugins', 'reviews')
162
161
  if File.directory?(plugins)
163
162
  Dir[File.expand_path(File.join(plugins, '*.rb'))].each do |review|
@@ -169,7 +168,6 @@ module RailsBestPractices
169
168
  end
170
169
  end
171
170
  end
172
-
173
171
  end
174
172
  end
175
173
  end
@@ -24,6 +24,7 @@ module RailsBestPractices
24
24
  # also check if the controller is inherit from InheritedResources::Base.
25
25
  add_callback :start_class do |_node|
26
26
  @controllers << @klass
27
+ @current_controller_name = @klass.to_s
27
28
  if @inherited_resources
28
29
  @actions = DEFAULT_ACTIONS
29
30
  end
@@ -31,9 +32,9 @@ module RailsBestPractices
31
32
 
32
33
  # remember the action names at the end of class node if the controller is a InheritedResources.
33
34
  add_callback :end_class do |node|
34
- if @inherited_resources && 'ApplicationController' != current_class_name
35
+ if @inherited_resources && 'ApplicationController' != @current_controller_name
35
36
  @actions.each do |action|
36
- @methods.add_method(current_class_name, action, 'file' => node.file, 'line_number' => node.line_number)
37
+ @methods.add_method(@current_controller_name, action, 'file' => node.file, 'line_number' => node.line_number)
37
38
  end
38
39
  end
39
40
  end
@@ -168,11 +168,10 @@ module RailsBestPractices
168
168
  foreign_id_keys = foreign_keys.select { |key| key.size == 1 && key.first =~ /_id/ }
169
169
  foreign_type_keys = foreign_keys.select { |key| key.size == 1 && key.first =~ /_type/ }
170
170
  foreign_id_keys.each do |id_key|
171
- if type_key = foreign_type_keys.detect { |type_key| type_key.first == id_key.first.sub(/_id/, '') + '_type' }
172
- foreign_keys.delete(id_key)
173
- foreign_keys.delete(type_key)
174
- foreign_keys << id_key + type_key
175
- end
171
+ next unless type_key = foreign_type_keys.detect { |type_key| type_key.first == id_key.first.sub(/_id/, '') + '_type' }
172
+ foreign_keys.delete(id_key)
173
+ foreign_keys.delete(type_key)
174
+ foreign_keys << id_key + type_key
176
175
  end
177
176
  }
178
177
  end
@@ -30,11 +30,15 @@ module RailsBestPractices
30
30
  @inherited_resources = false
31
31
  end
32
32
 
33
+ add_callback :start_class do |_node|
34
+ @current_controller_name = @klass.to_s
35
+ end
36
+
33
37
  # mark custom inherited_resources methods as used.
34
38
  add_callback :end_class do |_node|
35
39
  if @inherited_resources
36
40
  INHERITED_RESOURCES_METHODS.each do |method|
37
- call_method(method)
41
+ call_method(method, @current_controller_name)
38
42
  end
39
43
  end
40
44
  end
@@ -56,7 +60,7 @@ module RailsBestPractices
56
60
  action_name = first_argument.hash_value('state').to_s
57
61
  call_method(action_name, current_class_name)
58
62
  end
59
- when 'around_filter'
63
+ when 'around_filter', 'around_action'
60
64
  node.arguments.all.each { |argument| mark_used(argument) }
61
65
  when 'layout'
62
66
  first_argument = node.arguments.all.first
@@ -37,11 +37,10 @@ module RailsBestPractices
37
37
  remember_first_sentence(statement_node) if :def == statement_node.sexp_type
38
38
  end
39
39
  @first_sentences.each do |_first_sentence, def_nodes|
40
- if def_nodes.size > @customize_count
41
- add_error "use before_filter for #{def_nodes.map { |node| node.method_name.to_s }.join(',')}",
42
- node.file,
43
- def_nodes.map(&:line_number).join(',')
44
- end
40
+ next unless def_nodes.size > @customize_count
41
+ add_error "use before_filter for #{def_nodes.map { |node| node.method_name.to_s }.join(',')}",
42
+ node.file,
43
+ def_nodes.map(&:line_number).join(',')
45
44
  end
46
45
  end
47
46
 
@@ -40,12 +40,11 @@ module RailsBestPractices
40
40
  node.conditional_statement.all_conditions
41
41
  end
42
42
  all_conditions.each do |condition_node|
43
- if query_attribute_node = query_attribute_node(condition_node)
44
- receiver_node = query_attribute_node.receiver
45
- add_error "use query attribute (#{receiver_node.receiver}.#{receiver_node.message}?)",
46
- node.file,
47
- query_attribute_node.line_number
48
- end
43
+ next unless query_attribute_node = query_attribute_node(condition_node)
44
+ receiver_node = query_attribute_node.receiver
45
+ add_error "use query attribute (#{receiver_node.receiver}.#{receiver_node.message}?)",
46
+ node.file,
47
+ query_attribute_node.line_number
49
48
  end
50
49
  end
51
50
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsBestPractices
4
- VERSION = '1.19.2'.freeze
4
+ VERSION = '1.19.3'.freeze
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../lib/rails_best_practices/version', __FILE__)
3
+ require File.expand_path('lib/rails_best_practices/version', __dir__)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'rails_best_practices'
@@ -46,10 +46,6 @@ Gem::Specification.new do |s|
46
46
 
47
47
  http://rails-bestpractices.com
48
48
 
49
- Please also try our online service
50
-
51
- http://railsbp.com
52
-
53
49
  Enjoy!
54
50
 
55
51
  Richard Huang (flyerhzm@gmail.com)
@@ -89,6 +89,24 @@ module RailsBestPractices
89
89
  expect(runner.errors.size).to eq(0)
90
90
  end
91
91
 
92
+ it 'should not remove unused methods for around_action (new syntax)' do
93
+ content = <<-EOF
94
+ class PostsController < ActiveRecord::Base
95
+ around_action :use_time_zone
96
+
97
+ protected
98
+
99
+ def use_time_zone(&block)
100
+ Time.use_zone(current_user.time_zone, &block)
101
+ end
102
+ end
103
+ EOF
104
+ runner.prepare('app/controllers/posts_controller.rb', content)
105
+ runner.review('app/controllers/posts_controller.rb', content)
106
+ runner.after_review
107
+ expect(runner.errors.size).to eq(0)
108
+ end
109
+
92
110
  it 'should not remove unused methods for layout' do
93
111
  content = <<-EOF
94
112
  RailsBestPracticesCom::Application.routes.draw do
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.19.2
4
+ version: 1.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-01 00:00:00.000000000 Z
11
+ date: 2018-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -376,10 +376,6 @@ post_install_message: |
376
376
 
377
377
  http://rails-bestpractices.com
378
378
 
379
- Please also try our online service
380
-
381
- http://railsbp.com
382
-
383
379
  Enjoy!
384
380
 
385
381
  Richard Huang (flyerhzm@gmail.com)