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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Guardfile +1 -1
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/bin/rails_best_practices +2 -1
- data/lib/rails_best_practices.rb +2 -1
- data/lib/rails_best_practices/analyzer.rb +13 -12
- data/lib/rails_best_practices/colorize.rb +2 -0
- data/lib/rails_best_practices/command.rb +6 -5
- data/lib/rails_best_practices/core.rb +2 -1
- data/lib/rails_best_practices/core/check.rb +19 -17
- data/lib/rails_best_practices/core/checks_loader.rb +3 -2
- data/lib/rails_best_practices/core/configs.rb +2 -1
- data/lib/rails_best_practices/core/controllers.rb +4 -1
- data/lib/rails_best_practices/core/error.rb +3 -2
- data/lib/rails_best_practices/core/gems.rb +4 -3
- data/lib/rails_best_practices/core/helpers.rb +4 -1
- data/lib/rails_best_practices/core/klasses.rb +3 -2
- data/lib/rails_best_practices/core/mailers.rb +2 -1
- data/lib/rails_best_practices/core/methods.rb +9 -10
- data/lib/rails_best_practices/core/model_associations.rb +6 -5
- data/lib/rails_best_practices/core/model_attributes.rb +2 -1
- data/lib/rails_best_practices/core/models.rb +2 -1
- data/lib/rails_best_practices/core/modules.rb +2 -1
- data/lib/rails_best_practices/core/routes.rb +2 -1
- data/lib/rails_best_practices/core/runner.rb +7 -6
- data/lib/rails_best_practices/core_ext/erubis.rb +4 -5
- data/lib/rails_best_practices/lexicals.rb +2 -1
- data/lib/rails_best_practices/lexicals/long_line_check.rb +2 -1
- data/lib/rails_best_practices/lexicals/remove_tab_check.rb +2 -1
- data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +2 -1
- data/lib/rails_best_practices/prepares.rb +2 -1
- data/lib/rails_best_practices/prepares/config_prepare.rb +3 -2
- data/lib/rails_best_practices/prepares/controller_prepare.rb +9 -8
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/helper_prepare.rb +4 -3
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +3 -2
- data/lib/rails_best_practices/prepares/model_prepare.rb +12 -12
- data/lib/rails_best_practices/prepares/route_prepare.rb +8 -7
- data/lib/rails_best_practices/prepares/schema_prepare.rb +3 -2
- data/lib/rails_best_practices/reviews.rb +2 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +7 -4
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +8 -7
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +4 -3
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +5 -4
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +2 -1
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +2 -1
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +2 -1
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +3 -2
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +2 -1
- data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +3 -2
- data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +3 -2
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +5 -4
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +2 -1
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +2 -1
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +2 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +3 -2
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +4 -3
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +2 -1
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +11 -10
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +4 -3
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +6 -5
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +2 -2
- data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +2 -1
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +8 -8
- data/lib/rails_best_practices/reviews/review.rb +4 -3
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +3 -2
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +5 -4
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +2 -2
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +5 -5
- data/lib/rails_best_practices/reviews/use_observer_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +4 -3
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +4 -3
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +2 -1
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
- data/lib/rails_best_practices/version.rb +3 -2
- data/rails_best_practices.gemspec +11 -10
- data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +3 -2
- data/spec/rails_best_practices/analyzer_spec.rb +6 -8
- data/spec/rails_best_practices/core/check_spec.rb +2 -0
- data/spec/rails_best_practices/core/checks_loader_spec.rb +2 -0
- data/spec/rails_best_practices/core/configs_spec.rb +2 -0
- data/spec/rails_best_practices/core/controllers_spec.rb +2 -0
- data/spec/rails_best_practices/core/error_spec.rb +2 -0
- data/spec/rails_best_practices/core/except_methods_spec.rb +2 -0
- data/spec/rails_best_practices/core/gems_spec.rb +2 -0
- data/spec/rails_best_practices/core/helpers_spec.rb +2 -0
- data/spec/rails_best_practices/core/klasses_spec.rb +2 -0
- data/spec/rails_best_practices/core/mailers_spec.rb +2 -0
- data/spec/rails_best_practices/core/methods_spec.rb +6 -4
- data/spec/rails_best_practices/core/model_associations_spec.rb +4 -2
- data/spec/rails_best_practices/core/model_attributes_spec.rb +2 -0
- data/spec/rails_best_practices/core/models_spec.rb +2 -0
- data/spec/rails_best_practices/core/modules_spec.rb +2 -0
- data/spec/rails_best_practices/core/routes_spec.rb +4 -2
- data/spec/rails_best_practices/core/runner_spec.rb +2 -0
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +3 -1
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +8 -7
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +8 -6
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +9 -7
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +23 -21
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +7 -5
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +4 -2
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +56 -54
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +39 -37
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +12 -10
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +20 -18
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +11 -9
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +21 -19
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -4
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +33 -31
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +13 -11
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +65 -63
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +24 -22
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -11
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +7 -5
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +3 -1
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +2 -0
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -0
- metadata +26 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41de74a9e0a16b8a3b3feb2fb709f21aec80098
|
4
|
+
data.tar.gz: 98f10516376d7de5d3144b767196aa952b274748
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21e177d13d0f2137aebe7d683e87af1b97d53046e53b6bbd4722ae943a1061c5c6f740dee8efe9bc713c0be4550b70016849e17033faa6fd17e33a1204645963
|
7
|
+
data.tar.gz: 81473ba0611d37c8a4a005710983330d0aa6a8c4537ba976e71d93bc670f8ef4fda1d492a44fe1966d2dc0bd91452460ade65f250f252238c187bbe9064e5935
|
data/CHANGELOG.md
CHANGED
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', :
|
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
data/bin/rails_best_practices
CHANGED
data/lib/rails_best_practices.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
[
|
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
|
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 = [
|
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
|
-
|
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.
|
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(:
|
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(:
|
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(:
|
317
|
-
[
|
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,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
[
|
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.
|
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.
|
146
|
+
exit !analyzer.runner.errors.empty? ? 1 : 0
|
146
147
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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 |
|
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 |
|
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 |
|
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 [
|
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 |
|
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
|
357
|
+
raise NoMethodError, 'no method internal_except_methods'
|
356
358
|
end
|
357
359
|
end
|
358
360
|
end
|
359
361
|
|
360
|
-
def self.matches
|
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
|
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
|
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 |
|
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 |
|
412
|
+
add_callback :start_module do |_node|
|
411
413
|
@access_control = 'public'
|
412
414
|
end
|
413
415
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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
|
-
#
|
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
|
-
|
7
|
+
find { |gem| gem.name == gem_name }
|
7
8
|
end
|
8
9
|
|
9
10
|
def gem_version(gem_name)
|
10
|
-
|
11
|
+
find { |gem| gem.name == gem_name }.try(:version)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
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 =
|
23
|
+
@class_name = base + class_name
|
23
24
|
if extend_class_name
|
24
25
|
@extend_class_name = base + extend_class_name
|
25
26
|
end
|