rails_best_practices 1.19.1 → 1.19.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Guardfile +1 -1
  4. data/README.md +1 -0
  5. data/Rakefile +2 -2
  6. data/bin/rails_best_practices +2 -1
  7. data/lib/rails_best_practices.rb +2 -1
  8. data/lib/rails_best_practices/analyzer.rb +13 -12
  9. data/lib/rails_best_practices/colorize.rb +2 -0
  10. data/lib/rails_best_practices/command.rb +6 -5
  11. data/lib/rails_best_practices/core.rb +2 -1
  12. data/lib/rails_best_practices/core/check.rb +19 -17
  13. data/lib/rails_best_practices/core/checks_loader.rb +3 -2
  14. data/lib/rails_best_practices/core/configs.rb +2 -1
  15. data/lib/rails_best_practices/core/controllers.rb +4 -1
  16. data/lib/rails_best_practices/core/error.rb +3 -2
  17. data/lib/rails_best_practices/core/gems.rb +4 -3
  18. data/lib/rails_best_practices/core/helpers.rb +4 -1
  19. data/lib/rails_best_practices/core/klasses.rb +3 -2
  20. data/lib/rails_best_practices/core/mailers.rb +2 -1
  21. data/lib/rails_best_practices/core/methods.rb +9 -10
  22. data/lib/rails_best_practices/core/model_associations.rb +6 -5
  23. data/lib/rails_best_practices/core/model_attributes.rb +2 -1
  24. data/lib/rails_best_practices/core/models.rb +2 -1
  25. data/lib/rails_best_practices/core/modules.rb +2 -1
  26. data/lib/rails_best_practices/core/routes.rb +2 -1
  27. data/lib/rails_best_practices/core/runner.rb +7 -6
  28. data/lib/rails_best_practices/core_ext/erubis.rb +4 -5
  29. data/lib/rails_best_practices/lexicals.rb +2 -1
  30. data/lib/rails_best_practices/lexicals/long_line_check.rb +2 -1
  31. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -1
  32. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -1
  33. data/lib/rails_best_practices/prepares.rb +2 -1
  34. data/lib/rails_best_practices/prepares/config_prepare.rb +3 -2
  35. data/lib/rails_best_practices/prepares/controller_prepare.rb +9 -8
  36. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -1
  37. data/lib/rails_best_practices/prepares/helper_prepare.rb +4 -3
  38. data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -1
  39. data/lib/rails_best_practices/prepares/mailer_prepare.rb +3 -2
  40. data/lib/rails_best_practices/prepares/model_prepare.rb +12 -12
  41. data/lib/rails_best_practices/prepares/route_prepare.rb +8 -7
  42. data/lib/rails_best_practices/prepares/schema_prepare.rb +3 -2
  43. data/lib/rails_best_practices/reviews.rb +2 -1
  44. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +7 -4
  45. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +8 -7
  46. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +4 -3
  47. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +5 -4
  48. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -1
  49. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -1
  50. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +2 -1
  51. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +3 -2
  52. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +3 -2
  53. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +3 -2
  54. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -2
  55. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -1
  56. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +3 -2
  57. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +3 -2
  58. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +3 -2
  59. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +5 -4
  60. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -1
  61. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -1
  62. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -1
  63. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -2
  64. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +4 -3
  65. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -1
  66. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -10
  67. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +4 -3
  68. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +6 -5
  69. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
  70. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -1
  71. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +8 -8
  72. data/lib/rails_best_practices/reviews/review.rb +4 -3
  73. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -1
  74. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -2
  75. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +5 -4
  76. data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
  77. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +5 -5
  78. data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -1
  79. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +2 -1
  80. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +4 -3
  81. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +4 -3
  82. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -1
  83. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  84. data/lib/rails_best_practices/version.rb +3 -2
  85. data/rails_best_practices.gemspec +11 -10
  86. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +3 -2
  87. data/spec/rails_best_practices/analyzer_spec.rb +6 -8
  88. data/spec/rails_best_practices/core/check_spec.rb +2 -0
  89. data/spec/rails_best_practices/core/checks_loader_spec.rb +2 -0
  90. data/spec/rails_best_practices/core/configs_spec.rb +2 -0
  91. data/spec/rails_best_practices/core/controllers_spec.rb +2 -0
  92. data/spec/rails_best_practices/core/error_spec.rb +2 -0
  93. data/spec/rails_best_practices/core/except_methods_spec.rb +2 -0
  94. data/spec/rails_best_practices/core/gems_spec.rb +2 -0
  95. data/spec/rails_best_practices/core/helpers_spec.rb +2 -0
  96. data/spec/rails_best_practices/core/klasses_spec.rb +2 -0
  97. data/spec/rails_best_practices/core/mailers_spec.rb +2 -0
  98. data/spec/rails_best_practices/core/methods_spec.rb +6 -4
  99. data/spec/rails_best_practices/core/model_associations_spec.rb +4 -2
  100. data/spec/rails_best_practices/core/model_attributes_spec.rb +2 -0
  101. data/spec/rails_best_practices/core/models_spec.rb +2 -0
  102. data/spec/rails_best_practices/core/modules_spec.rb +2 -0
  103. data/spec/rails_best_practices/core/routes_spec.rb +4 -2
  104. data/spec/rails_best_practices/core/runner_spec.rb +2 -0
  105. data/spec/rails_best_practices/core_ext/erubis_spec.rb +3 -1
  106. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +8 -7
  107. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +8 -6
  108. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +9 -7
  109. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -1
  110. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +23 -21
  111. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -1
  112. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +7 -5
  113. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +4 -2
  114. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +3 -1
  115. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +56 -54
  116. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +39 -37
  117. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +3 -1
  118. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +2 -0
  119. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +7 -5
  120. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +12 -10
  121. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +20 -18
  122. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +2 -0
  123. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +2 -0
  124. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -7
  125. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +2 -0
  126. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +2 -0
  127. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +2 -0
  128. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +2 -0
  129. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +2 -0
  130. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +11 -9
  131. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +2 -0
  132. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +2 -0
  133. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +2 -0
  134. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -7
  135. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +2 -0
  136. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -5
  137. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +2 -0
  138. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +21 -19
  139. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -4
  140. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -31
  141. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +13 -11
  142. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +65 -63
  143. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +2 -0
  144. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +2 -0
  145. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +24 -22
  146. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -7
  147. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -11
  148. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +3 -1
  149. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +2 -0
  150. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +2 -0
  151. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +7 -5
  152. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +2 -0
  153. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +3 -1
  154. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -7
  155. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +2 -0
  156. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +2 -0
  157. data/spec/spec_helper.rb +2 -0
  158. metadata +26 -26
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0107d87cb5888b9ef62445563d9af1328cbc9761
4
- data.tar.gz: 26ff059e4a7437ee9606afbd2c200d27615283fb
3
+ metadata.gz: e41de74a9e0a16b8a3b3feb2fb709f21aec80098
4
+ data.tar.gz: 98f10516376d7de5d3144b767196aa952b274748
5
5
  SHA512:
6
- metadata.gz: 921598700949438fd5975a90e2091112a2c5296ddf14a11560f7b391a20c7cc6936c875e399327924990128944bdae455bd3311ffcf0473d0bcc4b8f40388719
7
- data.tar.gz: 50585713ae56c85ee34c38c19c9b4cb13e0fe8e55a2f328b5f3609226ce77680dfc783edccde4614cd48658497161be5bf45c6ac76c863eb28ff2be93be92dc1
6
+ metadata.gz: 21e177d13d0f2137aebe7d683e87af1b97d53046e53b6bbd4722ae943a1061c5c6f740dee8efe9bc713c0be4550b70016849e17033faa6fd17e33a1204645963
7
+ data.tar.gz: 81473ba0611d37c8a4a005710983330d0aa6a8c4537ba976e71d93bc670f8ef4fda1d492a44fe1966d2dc0bd91452460ade65f250f252238c187bbe9064e5935
@@ -1,5 +1,10 @@
1
1
  # Next Release
2
2
 
3
+ ## 1.19.2
4
+
5
+ * Integrate with awesomecode.io
6
+ * Update to require_all 2.x
7
+
3
8
  ## 1.19.1
4
9
 
5
10
  * Add table_name and module_prefix to model ignored methods
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # A sample Guardfile
2
2
  # More info at https://github.com/guard/guard#readme
3
3
 
4
- guard 'rspec', :version => 2, :all_after_pass => false, :all_on_start => false, :cli => '--color --format nested --fail-fast' do
4
+ guard 'rspec', version: 2, all_after_pass: false, all_on_start: false, cli: '--color --format nested --fail-fast' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
6
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { 'spec' }
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/rails_best_practices.svg)](http://badge.fury.io/rb/rails_best_practices)
4
4
  [![Build Status](https://secure.travis-ci.org/flyerhzm/rails_best_practices.svg)](http://travis-ci.org/flyerhzm/rails_best_practices)
5
5
  [![Coverage Status](https://coveralls.io/repos/railsbp/rails_best_practices/badge.svg?branch=master)](https://coveralls.io/r/railsbp/rails_best_practices)
6
+ [![AwesomeCode Status for flyerhzm/rails_best_practices](https://awesomecode.io/projects/d02ecd70-e068-4ad4-b61a-7003ac24b49a/status)](https://awesomecode.io/projects/8)
6
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 !](https://pledgie.com/campaigns/12057.png?skin_name=chrome)](https://pledgie.com/campaigns/12057)
data/Rakefile CHANGED
@@ -14,5 +14,5 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
14
14
  spec.pattern = 'spec/**/*_spec.rb'
15
15
  end
16
16
 
17
- task :default => :spec
18
- task :test => :spec
17
+ task default: :spec
18
+ task test: :spec
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
4
5
 
5
6
  require 'rails_best_practices'
6
- require 'rails_best_practices/command'
7
+ require 'rails_best_practices/command'
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'code_analyzer'
3
4
  require 'require_all'
4
5
  require 'rails_best_practices/core'
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'fileutils'
3
4
  require 'json'
4
5
  require 'ruby-progressbar'
@@ -18,7 +19,7 @@ module RailsBestPractices
18
19
  attr_reader :path
19
20
 
20
21
  DEFAULT_CONFIG = File.join(File.dirname(__FILE__), '..', '..', 'rails_best_practices.yml')
21
- GITHUB_URL = 'https://github.com/'
22
+ GITHUB_URL = 'https://github.com/'.freeze
22
23
 
23
24
  # initialize
24
25
  #
@@ -88,7 +89,7 @@ module RailsBestPractices
88
89
  begin
89
90
  puts file if @options['debug']
90
91
  @runner.send(process, file, File.read(file))
91
- rescue
92
+ rescue StandardError
92
93
  if @options['debug']
93
94
  warning = "#{file} looks like it's not a valid Ruby file. Skipping..."
94
95
  plain_output(warning, 'red')
@@ -112,7 +113,7 @@ module RailsBestPractices
112
113
  end
113
114
 
114
115
  # By default, tmp, vender, spec, test, features are ignored.
115
- ['vendor', 'spec', 'test', 'features', 'tmp'].each do |dir|
116
+ %w[vendor spec test features tmp].each do |dir|
116
117
  files = file_ignore(files, File.join(@path, dir)) unless @options[dir]
117
118
  end
118
119
 
@@ -121,7 +122,7 @@ module RailsBestPractices
121
122
  files = file_ignore(files, pattern)
122
123
  end
123
124
 
124
- %w(Capfile Gemfile Gemfile.lock).each do |file|
125
+ %w[Capfile Gemfile Gemfile.lock].each do |file|
125
126
  files.unshift File.join(@path, file)
126
127
  end
127
128
 
@@ -134,7 +135,7 @@ module RailsBestPractices
134
135
  # @param [Array] dirs what directories to expand
135
136
  # @return [Array] all files expanded
136
137
  def expand_dirs_to_files(*dirs)
137
- extensions = ['rb', 'erb', 'rake', 'rhtml', 'haml', 'slim', 'builder', 'rxml', 'rabl']
138
+ extensions = %w[rb erb rake rhtml haml slim builder rxml rabl]
138
139
 
139
140
  dirs.flatten.map { |entry|
140
141
  next unless File.exist? entry
@@ -157,7 +158,7 @@ module RailsBestPractices
157
158
  mailers = files.find_all { |file| file =~ Core::Check::MAILER_FILES }
158
159
  helpers = files.find_all { |file| file =~ Core::Check::HELPER_FILES }
159
160
  others = files.find_all { |file| file !~ Core::Check::MAILER_FILES && file !~ Core::Check::MODEL_FILES && file !~ Core::Check::HELPER_FILES }
160
- return models + mailers + helpers + others
161
+ models + mailers + helpers + others
161
162
  end
162
163
 
163
164
  # ignore specific files.
@@ -174,7 +175,7 @@ module RailsBestPractices
174
175
  # @param [Array] files
175
176
  # @param [Regexp] patterns, files match any pattern will be accepted
176
177
  def file_accept(files, patterns)
177
- files.reject { |file| !patterns.any? { |pattern| file =~ pattern } }
178
+ files.select { |file| patterns.any? { |pattern| file =~ pattern } }
178
179
  end
179
180
 
180
181
  # output errors on terminal.
@@ -190,7 +191,7 @@ module RailsBestPractices
190
191
 
191
192
  # load hg commit and hg username info.
192
193
  def load_hg_info
193
- hg_progressbar = ProgressBar.create(:title => 'Hg Info', :total => errors.size) if display_bar?
194
+ hg_progressbar = ProgressBar.create(title: 'Hg Info', total: errors.size) if display_bar?
194
195
  errors.each do |error|
195
196
  hg_info = `cd #{@runner.class.base_path} && hg blame -lvcu #{error.filename[@runner.class.base_path.size..-1].gsub(/^\//, '')} | sed -n /:#{error.line_number.split(',').first}:/p`
196
197
  unless hg_info == ''
@@ -205,7 +206,7 @@ module RailsBestPractices
205
206
 
206
207
  # load git commit and git username info.
207
208
  def load_git_info
208
- git_progressbar = ProgressBar.create(:title => 'Git Info', :total => errors.size) if display_bar?
209
+ git_progressbar = ProgressBar.create(title: 'Git Info', total: errors.size) if display_bar?
209
210
  start = @runner.class.base_path =~ /\/$/ ? @runner.class.base_path.size : @runner.class.base_path.size + 1
210
211
  errors.each do |error|
211
212
  git_info = `cd #{@runner.class.base_path} && git blame -L #{error.line_number.split(',').first},+1 #{error.filename[start..-1]}`
@@ -313,8 +314,8 @@ module RailsBestPractices
313
314
 
314
315
  # analyze source codes.
315
316
  def analyze_source_codes
316
- @bar = ProgressBar.create(:title => 'Source Code', :total => parse_files.size * 3) if display_bar?
317
- ['lexical', 'prepare', 'review'].each { |process| send(:process, process) }
317
+ @bar = ProgressBar.create(title: 'Source Code', total: parse_files.size * 3) if display_bar?
318
+ %w[lexical prepare review].each { |process| send(:process, process) }
318
319
  @bar.finish if display_bar?
319
320
  end
320
321
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module RailsBestPractices
2
4
  class Colorize
3
5
  def self.red(message)
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require 'optparse'
3
4
 
4
5
  # Usage: rails_best_practices [options] path
@@ -84,7 +85,7 @@ OptionParser.new do |opts|
84
85
  options['silent'] = true
85
86
  end
86
87
 
87
- ['vendor', 'spec', 'test', 'features'].each do |pattern|
88
+ %w[vendor spec test features].each do |pattern|
88
89
  opts.on("--#{pattern}", "include #{pattern} files") do
89
90
  options[pattern] = true
90
91
  end
@@ -103,7 +104,7 @@ OptionParser.new do |opts|
103
104
 
104
105
  opts.on('-x', '--exclude PATTERNS', "Don't analyze files matching a pattern", '(comma-separated regexp list)') do |list|
105
106
  begin
106
- options['exclude'] = list.split(',').map{|x| Regexp.new x}
107
+ options['exclude'] = list.split(',').map { |x| Regexp.new x }
107
108
  rescue RegexpError => e
108
109
  raise OptionParser::InvalidArgument, e.message
109
110
  end
@@ -131,7 +132,7 @@ OptionParser.new do |opts|
131
132
  opts.parse!
132
133
  end
133
134
 
134
- if ARGV.size > 0 && !File.exists?(ARGV.first)
135
+ if !ARGV.empty? && !File.exist?(ARGV.first)
135
136
  puts "#{ARGV.first} doesn't exist"
136
137
  exit 1
137
138
  end
@@ -142,5 +143,5 @@ else
142
143
  analyzer = RailsBestPractices::Analyzer.new(ARGV.first, options)
143
144
  analyzer.analyze
144
145
  analyzer.output
145
- exit analyzer.runner.errors.size > 0 ? 1 : 0
146
+ exit !analyzer.runner.errors.empty? ? 1 : 0
146
147
  end
@@ -1,3 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  require_rel 'core'
3
4
  require_rel 'core_ext'
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module RailsBestPractices
3
4
  module Core
4
5
  # A Check class that takes charge of checking the sexp.
@@ -21,7 +22,7 @@ module RailsBestPractices
21
22
 
22
23
  SKIP_FILES = /db\/schema.rb/
23
24
 
24
- def initialize(options={})
25
+ def initialize(options = {})
25
26
  options.each do |key, value|
26
27
  instance_variable_set("@#{key}", value)
27
28
  end
@@ -46,11 +47,11 @@ module RailsBestPractices
46
47
  end
47
48
 
48
49
  def is_ignored?(node_file)
49
- regex_ignored_files.map{ |r| !!r.match(node_file) }.inject(:|)
50
+ regex_ignored_files.map { |r| !!r.match(node_file) }.inject(:|)
50
51
  end
51
52
 
52
53
  def regex_ignored_files
53
- @regex_ignored_files ||= Array(@ignored_files).map{ |pattern| Regexp.new(pattern) }
54
+ @regex_ignored_files ||= Array(@ignored_files).map { |pattern| Regexp.new(pattern) }
54
55
  end
55
56
 
56
57
  # add error if source code violates rails best practice.
@@ -99,7 +100,7 @@ module RailsBestPractices
99
100
  end
100
101
 
101
102
  class <<self
102
- def url(url=nil)
103
+ def url(url = nil)
103
104
  url ? @url = url : @url
104
105
  end
105
106
 
@@ -124,7 +125,7 @@ module RailsBestPractices
124
125
  end
125
126
 
126
127
  # end of the module.
127
- add_callback :end_module do |node|
128
+ add_callback :end_module do |_node|
128
129
  classable_modules.pop
129
130
  end
130
131
 
@@ -136,7 +137,7 @@ module RailsBestPractices
136
137
  end
137
138
 
138
139
  # end of the class
139
- add_callback :end_class do |node|
140
+ add_callback :end_class do |_node|
140
141
  klasses.pop
141
142
  # @klass = nil
142
143
  end
@@ -175,7 +176,7 @@ module RailsBestPractices
175
176
  end
176
177
 
177
178
  # end of module
178
- add_callback :end_module do |node|
179
+ add_callback :end_module do |_node|
179
180
  moduleable_modules.pop
180
181
  end
181
182
  end
@@ -272,7 +273,7 @@ module RailsBestPractices
272
273
  when 'try'
273
274
  mark_used(node.arguments.all.first)
274
275
  when 'send'
275
- if [:symbol_literal, :string_literal].include?(node.arguments.all.first.sexp_type)
276
+ if %i[symbol_literal string_literal].include?(node.arguments.all.first.sexp_type)
276
277
  mark_used(node.arguments.all.first)
277
278
  end
278
279
  else
@@ -281,6 +282,7 @@ module RailsBestPractices
281
282
  end
282
283
 
283
284
  private
285
+
284
286
  def mark_used(method_node)
285
287
  return if method_node == :call
286
288
  if :bare_assoc_hash == method_node.sexp_type
@@ -293,7 +295,7 @@ module RailsBestPractices
293
295
  call_method(method_name)
294
296
  end
295
297
 
296
- def call_method(method_name, class_name=nil)
298
+ def call_method(method_name, class_name = nil)
297
299
  name ||= respond_to?(:current_class_name) ? current_class_name : current_module_name
298
300
  if methods.has_method?(name, method_name)
299
301
  methods.get_method(name, method_name).mark_used
@@ -314,7 +316,7 @@ module RailsBestPractices
314
316
  interesting_files CONTROLLER_FILES
315
317
 
316
318
  # check if the controller is inherit from InheritedResources::Base.
317
- add_callback :start_class do |node|
319
+ add_callback :start_class do |_node|
318
320
  if 'InheritedResources::Base' == current_extend_class_name
319
321
  @inherited_resources = true
320
322
  end
@@ -352,12 +354,12 @@ module RailsBestPractices
352
354
  end
353
355
 
354
356
  def internal_except_methods
355
- raise NoMethodError.new 'no method internal_except_methods'
357
+ raise NoMethodError, 'no method internal_except_methods'
356
358
  end
357
359
  end
358
360
  end
359
361
 
360
- def self.matches method, except_method
362
+ def self.matches(method, except_method)
361
363
  class_name, method_name = except_method.split('#')
362
364
 
363
365
  method_name = '.*' if method_name == '*'
@@ -389,25 +391,25 @@ module RailsBestPractices
389
391
 
390
392
  # remember the current access control for methods.
391
393
  add_callback :start_var_ref do |node|
392
- if %w(public protected private).include? node.to_s
394
+ if %w[public protected private].include? node.to_s
393
395
  @access_control = node.to_s
394
396
  end
395
397
  end
396
398
 
397
399
  # remember the current access control for methods.
398
400
  add_callback :start_vcall do |node|
399
- if %w(public protected private).include? node.to_s
401
+ if %w[public protected private].include? node.to_s
400
402
  @access_control = node.to_s
401
403
  end
402
404
  end
403
405
 
404
406
  # set access control to "public" by default.
405
- add_callback :start_class do |node|
407
+ add_callback :start_class do |_node|
406
408
  @access_control = 'public'
407
409
  end
408
410
 
409
411
  # set access control to "public" by default.
410
- add_callback :start_module do |node|
412
+ add_callback :start_module do |_node|
411
413
  @access_control = 'public'
412
414
  end
413
415
  end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module RailsBestPractices
3
4
  module Core
4
5
  class ChecksLoader
@@ -46,4 +47,4 @@ module RailsBestPractices
46
47
  end
47
48
  end
48
49
  end
49
- end
50
+ end
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module RailsBestPractices
3
4
  module Core
4
5
  class Configs < Hash
@@ -1,4 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
3
+ require_rel 'klasses'
4
+
2
5
  module RailsBestPractices
3
6
  module Core
4
7
  # Controller classes.
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module RailsBestPractices
3
4
  module Core
4
5
  # Error is the violation to rails best practice.
@@ -8,7 +9,7 @@ module RailsBestPractices
8
9
  attr_reader :type, :url
9
10
  attr_accessor :git_commit, :git_username, :hg_commit, :hg_username
10
11
 
11
- def initialize(options={})
12
+ def initialize(options = {})
12
13
  super
13
14
  @type = options[:type]
14
15
  @url = options[:url]
@@ -1,13 +1,14 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module RailsBestPractices
3
4
  module Core
4
5
  class Gems < Array
5
6
  def has_gem?(gem_name)
6
- self.find { |gem| gem.name == gem_name }
7
+ find { |gem| gem.name == gem_name }
7
8
  end
8
9
 
9
10
  def gem_version(gem_name)
10
- self.find { |gem| gem.name == gem_name }.try(:version)
11
+ find { |gem| gem.name == gem_name }.try(:version)
11
12
  end
12
13
  end
13
14
 
@@ -1,4 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
3
+ require_rel 'modules'
4
+
2
5
  module RailsBestPractices
3
6
  module Core
4
7
  # Helper moduels.
@@ -1,4 +1,5 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module RailsBestPractices
3
4
  module Core
4
5
  # Klass container.
@@ -19,7 +20,7 @@ module RailsBestPractices
19
20
  def initialize(class_name, extend_class_name, modules)
20
21
  @modules = modules.dup
21
22
  base = @modules.map { |modu| "#{modu}::" }.join('')
22
- @class_name = base + class_name
23
+ @class_name = base + class_name
23
24
  if extend_class_name
24
25
  @extend_class_name = base + extend_class_name
25
26
  end