rails_best_practices 1.19.2 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.travis.yml +2 -3
- data/CHANGELOG.md +7 -7
- data/Gemfile +3 -5
- data/Gemfile.lock +125 -0
- data/Guardfile +2 -0
- data/README.md +6 -6
- data/Rakefile +2 -17
- data/assets/result.html.erb +2 -0
- data/lib/rails_best_practices.rb +3 -2
- data/lib/rails_best_practices/analyzer.rb +61 -49
- data/lib/rails_best_practices/cli.rb +22 -0
- data/lib/rails_best_practices/command.rb +1 -131
- data/lib/rails_best_practices/core/check.rb +64 -56
- data/lib/rails_best_practices/core/checks_loader.rb +24 -23
- data/lib/rails_best_practices/core/configs.rb +1 -2
- data/lib/rails_best_practices/core/controllers.rb +1 -2
- data/lib/rails_best_practices/core/error.rb +1 -1
- data/lib/rails_best_practices/core/helpers.rb +1 -2
- data/lib/rails_best_practices/core/mailers.rb +1 -2
- data/lib/rails_best_practices/core/methods.rb +27 -21
- data/lib/rails_best_practices/core/model_associations.rb +10 -5
- data/lib/rails_best_practices/core/models.rb +1 -2
- data/lib/rails_best_practices/core/modules.rb +1 -1
- data/lib/rails_best_practices/core/routes.rb +2 -2
- data/lib/rails_best_practices/core/runner.rb +67 -73
- data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
- data/lib/rails_best_practices/option_parser.rb +156 -0
- data/lib/rails_best_practices/prepares.rb +1 -1
- data/lib/rails_best_practices/prepares/controller_prepare.rb +24 -17
- data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -2
- data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
- data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
- data/lib/rails_best_practices/prepares/mailer_prepare.rb +2 -1
- data/lib/rails_best_practices/prepares/model_prepare.rb +63 -23
- data/lib/rails_best_practices/prepares/route_prepare.rb +28 -21
- data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
- data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +38 -34
- data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +94 -89
- data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +15 -5
- data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +20 -8
- data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
- data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
- data/lib/rails_best_practices/reviews/hash_syntax_review.rb +16 -16
- data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +12 -12
- data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +10 -11
- data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +25 -24
- data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +4 -4
- data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +9 -10
- data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +10 -11
- data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +24 -22
- data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
- data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
- data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
- data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +8 -8
- data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +35 -32
- data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +26 -19
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +12 -10
- data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +38 -18
- data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +11 -11
- data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +77 -74
- data/lib/rails_best_practices/reviews/review.rb +2 -1
- data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -3
- data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +12 -12
- data/lib/rails_best_practices/reviews/use_before_filter_review.rb +18 -15
- data/lib/rails_best_practices/reviews/use_model_association_review.rb +15 -15
- data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +24 -22
- data/lib/rails_best_practices/reviews/use_observer_review.rb +28 -28
- data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
- data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +68 -66
- data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -8
- data/lib/rails_best_practices/reviews/use_scope_access_review.rb +16 -14
- data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.gemspec +38 -43
- data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
- data/spec/rails_best_practices/analyzer_spec.rb +73 -42
- data/spec/rails_best_practices/core/check_spec.rb +5 -5
- data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
- data/spec/rails_best_practices/core/configs_spec.rb +1 -1
- data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
- data/spec/rails_best_practices/core/error_spec.rb +21 -18
- data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
- data/spec/rails_best_practices/core/gems_spec.rb +4 -4
- data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
- data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
- data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
- data/spec/rails_best_practices/core/methods_spec.rb +6 -6
- data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
- data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
- data/spec/rails_best_practices/core/models_spec.rb +1 -1
- data/spec/rails_best_practices/core/modules_spec.rb +5 -5
- data/spec/rails_best_practices/core/routes_spec.rb +5 -5
- data/spec/rails_best_practices/core/runner_spec.rb +9 -7
- data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
- data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +32 -31
- data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
- data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
- data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
- data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +17 -17
- data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
- data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
- data/spec/rails_best_practices/prepares/route_prepare_spec.rb +141 -76
- data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
- data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
- data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
- data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
- data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
- data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +13 -13
- data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +29 -22
- data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
- data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +32 -22
- data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
- data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
- data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -17
- data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +64 -31
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +21 -14
- data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +57 -53
- data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
- data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +20 -14
- data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
- data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
- data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
- data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
- data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
- data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +35 -31
- data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
- data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +10 -8
- data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
- data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
- data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
- data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +61 -59
- metadata +16 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e7a2b67944c27b7a11e48f2c490a4ea1080fc4df39ad1d59b20cdeaedfb4b083
|
4
|
+
data.tar.gz: d96f6d7da9909bac895162f70ae1247a98a8df39da7fd2ce17365e959568c4f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 244acdd4067af5f87364236d4fe5bc40d5a4d68b98d1c6786aaf0e53c7766626ef670c4aaa61d793a47bba643fddcd2cbd545a4697dff8d0a3d6f7238912c2b5
|
7
|
+
data.tar.gz: 9b4ca4c95172317d9017691399fcb9211295bad98959477fa8fa24a054a7a6283dc7cdbabd926e925ccf0f3ea9bfe1dde3e594cc42a2db7bd3b37758cb7bdc6e
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Next Release
|
2
2
|
|
3
|
-
## 1.
|
4
|
-
|
5
|
-
* Integrate with awesomecode.io
|
6
|
-
* Update to require_all 2.x
|
7
|
-
|
8
|
-
## 1.19.1
|
3
|
+
## 1.20.0 (2020-02-29)
|
9
4
|
|
5
|
+
* Support ruby 2.7
|
6
|
+
* Add the link format for vscode
|
7
|
+
* Add cli class
|
10
8
|
* Add table_name and module_prefix to model ignored methods
|
11
|
-
*
|
9
|
+
* Fix false positive remove unused method for around_action in
|
10
|
+
controller
|
11
|
+
* Fix current_class_name in end_class callback
|
12
12
|
|
13
13
|
## 1.19.0 (2017-07-26)
|
14
14
|
|
data/Gemfile
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
gemspec
|
3
5
|
|
4
6
|
gem 'coveralls', require: false
|
5
7
|
|
6
|
-
if RUBY_PLATFORM =~ /darwin/i
|
7
|
-
gem 'growl'
|
8
|
-
gem 'rb-fsevent'
|
9
|
-
end
|
10
8
|
gem 'guard'
|
11
9
|
gem 'guard-rspec'
|
12
10
|
gem 'pry'
|
13
|
-
gem 'rspec'
|
11
|
+
gem 'rspec'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails_best_practices (1.20.1)
|
5
|
+
activesupport
|
6
|
+
code_analyzer (>= 0.5.2)
|
7
|
+
erubis
|
8
|
+
i18n
|
9
|
+
json
|
10
|
+
require_all (~> 3.0)
|
11
|
+
ruby-progressbar
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activesupport (6.1.3.2)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
tzinfo (~> 2.0)
|
21
|
+
zeitwerk (~> 2.3)
|
22
|
+
awesome_print (1.8.0)
|
23
|
+
code_analyzer (0.5.2)
|
24
|
+
sexp_processor
|
25
|
+
coderay (1.1.2)
|
26
|
+
concurrent-ruby (1.1.8)
|
27
|
+
coveralls (0.8.23)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov (~> 0.16.1)
|
30
|
+
term-ansicolor (~> 1.3)
|
31
|
+
thor (>= 0.19.4, < 2.0)
|
32
|
+
tins (~> 1.6)
|
33
|
+
diff-lcs (1.3)
|
34
|
+
docile (1.3.2)
|
35
|
+
erubis (2.7.0)
|
36
|
+
ffi (1.11.3)
|
37
|
+
formatador (0.2.5)
|
38
|
+
guard (2.16.1)
|
39
|
+
formatador (>= 0.2.4)
|
40
|
+
listen (>= 2.7, < 4.0)
|
41
|
+
lumberjack (>= 1.0.12, < 2.0)
|
42
|
+
nenv (~> 0.1)
|
43
|
+
notiffany (~> 0.0)
|
44
|
+
pry (>= 0.9.12)
|
45
|
+
shellany (~> 0.0)
|
46
|
+
thor (>= 0.18.1)
|
47
|
+
guard-rspec (4.3.1)
|
48
|
+
guard (~> 2.1)
|
49
|
+
rspec (>= 2.14, < 4.0)
|
50
|
+
haml (5.1.2)
|
51
|
+
temple (>= 0.8.0)
|
52
|
+
tilt
|
53
|
+
i18n (1.8.10)
|
54
|
+
concurrent-ruby (~> 1.0)
|
55
|
+
json (2.3.0)
|
56
|
+
listen (3.2.1)
|
57
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
58
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
59
|
+
lumberjack (1.0.13)
|
60
|
+
method_source (0.9.2)
|
61
|
+
minitest (5.14.4)
|
62
|
+
nenv (0.3.0)
|
63
|
+
notiffany (0.1.3)
|
64
|
+
nenv (~> 0.1)
|
65
|
+
shellany (~> 0.0)
|
66
|
+
pry (0.12.2)
|
67
|
+
coderay (~> 1.1.0)
|
68
|
+
method_source (~> 0.9.0)
|
69
|
+
rake (13.0.1)
|
70
|
+
rb-fsevent (0.10.3)
|
71
|
+
rb-inotify (0.10.1)
|
72
|
+
ffi (~> 1.0)
|
73
|
+
require_all (3.0.0)
|
74
|
+
rspec (3.9.0)
|
75
|
+
rspec-core (~> 3.9.0)
|
76
|
+
rspec-expectations (~> 3.9.0)
|
77
|
+
rspec-mocks (~> 3.9.0)
|
78
|
+
rspec-core (3.9.1)
|
79
|
+
rspec-support (~> 3.9.1)
|
80
|
+
rspec-expectations (3.9.1)
|
81
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
+
rspec-support (~> 3.9.0)
|
83
|
+
rspec-mocks (3.9.1)
|
84
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
+
rspec-support (~> 3.9.0)
|
86
|
+
rspec-support (3.9.2)
|
87
|
+
ruby-progressbar (1.11.0)
|
88
|
+
sexp_processor (4.15.2)
|
89
|
+
shellany (0.0.1)
|
90
|
+
simplecov (0.16.1)
|
91
|
+
docile (~> 1.1)
|
92
|
+
json (>= 1.8, < 3)
|
93
|
+
simplecov-html (~> 0.10.0)
|
94
|
+
simplecov-html (0.10.2)
|
95
|
+
slim (4.0.1)
|
96
|
+
temple (>= 0.7.6, < 0.9)
|
97
|
+
tilt (>= 2.0.6, < 2.1)
|
98
|
+
temple (0.8.2)
|
99
|
+
term-ansicolor (1.7.1)
|
100
|
+
tins (~> 1.0)
|
101
|
+
thor (1.0.1)
|
102
|
+
tilt (2.0.10)
|
103
|
+
tins (1.22.2)
|
104
|
+
tzinfo (2.0.4)
|
105
|
+
concurrent-ruby (~> 1.0)
|
106
|
+
zeitwerk (2.4.2)
|
107
|
+
|
108
|
+
PLATFORMS
|
109
|
+
ruby
|
110
|
+
|
111
|
+
DEPENDENCIES
|
112
|
+
awesome_print
|
113
|
+
bundler
|
114
|
+
coveralls
|
115
|
+
guard
|
116
|
+
guard-rspec
|
117
|
+
haml
|
118
|
+
pry
|
119
|
+
rails_best_practices!
|
120
|
+
rake
|
121
|
+
rspec
|
122
|
+
slim
|
123
|
+
|
124
|
+
BUNDLED WITH
|
125
|
+
2.1.4
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
[](http://badge.fury.io/rb/rails_best_practices)
|
4
4
|
[](http://travis-ci.org/flyerhzm/rails_best_practices)
|
5
5
|
[](https://coveralls.io/r/railsbp/rails_best_practices)
|
6
|
-
[](https://awesomecode.io/
|
6
|
+
[](https://awesomecode.io/repos/flyerhzm/rails_best_practices)
|
7
7
|
|
8
8
|
[](http://coderwall.com/flyerhzm)
|
9
9
|
[](https://pledgie.com/campaigns/12057)
|
@@ -64,6 +64,7 @@ To see the full list of command-line options, run:
|
|
64
64
|
-f, --format FORMAT output format
|
65
65
|
--without-color only output plain text without color
|
66
66
|
--with-textmate open file by textmate in html format
|
67
|
+
--with-vscode open file by vscode in html format
|
67
68
|
--with-sublime open file by sublime in html format (requires https://github.com/asuth/subl-handler)
|
68
69
|
--with-mvim open file by mvim in html format
|
69
70
|
--with-github GITHUB_NAME open file on github in html format. GITHUB_NAME is like railsbp/rails-bestpractices OR full URL to GitHub:FI repo
|
@@ -89,13 +90,9 @@ To see the full list of command-line options, run:
|
|
89
90
|
|
90
91
|
Homepage: <http://rails-bestpractices.com>
|
91
92
|
|
92
|
-
Online Service: <http://railsbp.com>
|
93
|
-
|
94
93
|
GitHub: <http://github.com/railsbp/rails_best_practices>
|
95
94
|
|
96
|
-
|
97
|
-
|
98
|
-
Team Blog <http://rails-bestpractices.com/blog/posts>
|
95
|
+
Team Blog <http://rails-bestpractices.com>
|
99
96
|
|
100
97
|
Google Group: <https://groups.google.com/group/rails_best_practices>
|
101
98
|
|
@@ -186,6 +183,9 @@ Now you can customize this configuration file. The default configuration is as f
|
|
186
183
|
UseScopeAccessCheck: { }
|
187
184
|
UseTurboSprocketsRails3Check: { }
|
188
185
|
|
186
|
+
Now, at the root directory of a Rails app, run:
|
187
|
+
|
188
|
+
rails_best_practices . -c config/rails_best_practices.yml
|
189
189
|
|
190
190
|
You can remove or comment a review to disable it, and you can change the options.
|
191
191
|
|
data/Rakefile
CHANGED
@@ -1,18 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
|
4
|
-
Bundler.setup
|
5
|
-
|
6
|
-
require 'rake'
|
7
|
-
require 'rspec'
|
8
|
-
require 'rspec/core/rake_task'
|
1
|
+
# frozen_string_literal: true
|
9
2
|
|
10
|
-
|
11
|
-
require 'rails_best_practices/version'
|
12
|
-
|
13
|
-
RSpec::Core::RakeTask.new(:spec) do |spec|
|
14
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
task default: :spec
|
18
|
-
task test: :spec
|
3
|
+
require 'bundler/gem_tasks'
|
data/assets/result.html.erb
CHANGED
@@ -121,6 +121,8 @@
|
|
121
121
|
<a href='subl://open?url=file://<%= File.expand_path(error.filename) %>&line=<%= error.line_number %>'><%= error.short_filename %></a>
|
122
122
|
<% elsif @mvim %>
|
123
123
|
<a href='mvim://open/?url=file://<%= File.expand_path(error.filename) %>&line=<%= error.line_number %>'><%= error.short_filename %></a>
|
124
|
+
<% elsif @vscode %>
|
125
|
+
<a href='vscode://file/<%= File.expand_path(error.filename) %>:<%= error.line_number %>'><%= error.short_filename %></a>
|
124
126
|
<% else %>
|
125
127
|
<%= error.short_filename %>
|
126
128
|
<% end %>
|
data/lib/rails_best_practices.rb
CHANGED
@@ -8,6 +8,7 @@ require 'rails_best_practices/analyzer'
|
|
8
8
|
require 'rails_best_practices/lexicals'
|
9
9
|
require 'rails_best_practices/prepares'
|
10
10
|
require 'rails_best_practices/reviews'
|
11
|
+
require 'rails_best_practices/option_parser'
|
12
|
+
require 'rails_best_practices/cli'
|
11
13
|
|
12
|
-
module RailsBestPractices
|
13
|
-
end
|
14
|
+
module RailsBestPractices; end
|
@@ -19,7 +19,7 @@ module RailsBestPractices
|
|
19
19
|
attr_reader :path
|
20
20
|
|
21
21
|
DEFAULT_CONFIG = File.join(File.dirname(__FILE__), '..', '..', 'rails_best_practices.yml')
|
22
|
-
GITHUB_URL = 'https://github.com/'
|
22
|
+
GITHUB_URL = 'https://github.com/'
|
23
23
|
|
24
24
|
# initialize
|
25
25
|
#
|
@@ -104,30 +104,31 @@ module RailsBestPractices
|
|
104
104
|
#
|
105
105
|
# @return [Array] all files for parsing
|
106
106
|
def parse_files
|
107
|
-
@parse_files ||=
|
108
|
-
|
109
|
-
|
107
|
+
@parse_files ||=
|
108
|
+
begin
|
109
|
+
files = expand_dirs_to_files(@path)
|
110
|
+
files = file_sort(files)
|
110
111
|
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
if @options['only'].present?
|
113
|
+
files = file_accept(files, @options['only'])
|
114
|
+
end
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
116
|
+
# By default, tmp, vender, spec, test, features are ignored.
|
117
|
+
%w[vendor spec test features tmp].each do |dir|
|
118
|
+
files = file_ignore(files, File.join(@path, dir)) unless @options[dir]
|
119
|
+
end
|
119
120
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
# Exclude files based on exclude regexes if the option is set.
|
122
|
+
@options['exclude'].each do |pattern|
|
123
|
+
files = file_ignore(files, pattern)
|
124
|
+
end
|
124
125
|
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
%w[Capfile Gemfile Gemfile.lock].each do |file|
|
127
|
+
files.unshift File.join(@path, file)
|
128
|
+
end
|
128
129
|
|
129
|
-
|
130
|
-
|
130
|
+
files.compact
|
131
|
+
end
|
131
132
|
end
|
132
133
|
|
133
134
|
# expand all files with extenstion rb, erb, haml, slim, builder and rxml under the dirs
|
@@ -137,14 +138,15 @@ module RailsBestPractices
|
|
137
138
|
def expand_dirs_to_files(*dirs)
|
138
139
|
extensions = %w[rb erb rake rhtml haml slim builder rxml rabl]
|
139
140
|
|
140
|
-
dirs.flatten.map
|
141
|
+
dirs.flatten.map do |entry|
|
141
142
|
next unless File.exist? entry
|
143
|
+
|
142
144
|
if File.directory? entry
|
143
145
|
Dir[File.join(entry, '**', "*.{#{extensions.join(',')}}")]
|
144
146
|
else
|
145
147
|
entry
|
146
148
|
end
|
147
|
-
|
149
|
+
end.flatten
|
148
150
|
end
|
149
151
|
|
150
152
|
# sort files, models first, mailers, helpers, and then sort other files by characters.
|
@@ -157,7 +159,10 @@ module RailsBestPractices
|
|
157
159
|
models = files.find_all { |file| file =~ Core::Check::MODEL_FILES }
|
158
160
|
mailers = files.find_all { |file| file =~ Core::Check::MAILER_FILES }
|
159
161
|
helpers = files.find_all { |file| file =~ Core::Check::HELPER_FILES }
|
160
|
-
others =
|
162
|
+
others =
|
163
|
+
files.find_all do |file|
|
164
|
+
file !~ Core::Check::MAILER_FILES && file !~ Core::Check::MODEL_FILES && file !~ Core::Check::HELPER_FILES
|
165
|
+
end
|
161
166
|
models + mailers + helpers + others
|
162
167
|
end
|
163
168
|
|
@@ -193,7 +198,10 @@ module RailsBestPractices
|
|
193
198
|
def load_hg_info
|
194
199
|
hg_progressbar = ProgressBar.create(title: 'Hg Info', total: errors.size) if display_bar?
|
195
200
|
errors.each do |error|
|
196
|
-
|
201
|
+
info_command = "cd #{@runner.class.base_path}"
|
202
|
+
info_command += " && hg blame -lvcu #{error.filename[@runner.class.base_path.size..-1].gsub(%r{^/}, '')}"
|
203
|
+
info_command += " | sed -n /:#{error.line_number.split(',').first}:/p"
|
204
|
+
hg_info = system(info_command)
|
197
205
|
unless hg_info == ''
|
198
206
|
hg_commit_username = hg_info.split(':')[0].strip
|
199
207
|
error.hg_username = hg_commit_username.split(/\ /)[0..-2].join(' ')
|
@@ -207,9 +215,11 @@ module RailsBestPractices
|
|
207
215
|
# load git commit and git username info.
|
208
216
|
def load_git_info
|
209
217
|
git_progressbar = ProgressBar.create(title: 'Git Info', total: errors.size) if display_bar?
|
210
|
-
start = @runner.class.base_path =~
|
218
|
+
start = @runner.class.base_path =~ %r{/$} ? @runner.class.base_path.size : @runner.class.base_path.size + 1
|
211
219
|
errors.each do |error|
|
212
|
-
|
220
|
+
info_command = "cd #{@runner.class.base_path}"
|
221
|
+
info_command += " && git blame -L #{error.line_number.split(',').first},+1 #{error.filename[start..-1]}"
|
222
|
+
git_info = system(info_command)
|
213
223
|
unless git_info == ''
|
214
224
|
git_commit, git_username = git_info.split(/\d{4}-\d{2}-\d{2}/).first.split('(')
|
215
225
|
error.git_commit = git_commit.split(' ').first.strip
|
@@ -223,10 +233,13 @@ module RailsBestPractices
|
|
223
233
|
# output errors with html format.
|
224
234
|
def output_html_errors
|
225
235
|
require 'erubis'
|
226
|
-
template =
|
236
|
+
template =
|
237
|
+
@options['template'] ?
|
238
|
+
File.read(File.expand_path(@options['template'])) :
|
239
|
+
File.read(File.join(File.dirname(__FILE__), '..', '..', 'assets', 'result.html.erb'))
|
227
240
|
|
228
241
|
if @options['with-github']
|
229
|
-
last_commit_id = @options['last-commit-id']
|
242
|
+
last_commit_id = @options['last-commit-id'] || `cd #{@runner.class.base_path} && git rev-parse HEAD`.chomp
|
230
243
|
unless @options['github-name'].start_with?('https')
|
231
244
|
@options['github-name'] = GITHUB_URL + @options['github-name']
|
232
245
|
end
|
@@ -234,26 +247,28 @@ module RailsBestPractices
|
|
234
247
|
File.open(@options['output-file'], 'w+') do |file|
|
235
248
|
eruby = Erubis::Eruby.new(template)
|
236
249
|
file.puts eruby.evaluate(
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
250
|
+
errors: errors,
|
251
|
+
error_types: error_types,
|
252
|
+
textmate: @options['with-textmate'],
|
253
|
+
vscode: @options['with-vscode'],
|
254
|
+
sublime: @options['with-sublime'],
|
255
|
+
mvim: @options['with-mvim'],
|
256
|
+
github: @options['with-github'],
|
257
|
+
github_name: @options['github-name'],
|
258
|
+
last_commit_id: last_commit_id,
|
259
|
+
git: @options['with-git'],
|
260
|
+
hg: @options['with-hg']
|
261
|
+
)
|
248
262
|
end
|
249
263
|
end
|
250
264
|
|
251
265
|
def output_xml_errors
|
252
266
|
require 'rexml/document'
|
253
267
|
|
254
|
-
document =
|
255
|
-
|
256
|
-
|
268
|
+
document =
|
269
|
+
REXML::Document.new.tap do |d|
|
270
|
+
d << REXML::XMLDecl.new
|
271
|
+
end
|
257
272
|
|
258
273
|
checkstyle = REXML::Element.new('checkstyle', document)
|
259
274
|
|
@@ -287,13 +302,10 @@ module RailsBestPractices
|
|
287
302
|
|
288
303
|
# output errors with json format.
|
289
304
|
def output_json_errors
|
290
|
-
errors_as_hashes =
|
291
|
-
|
292
|
-
filename:
|
293
|
-
|
294
|
-
message: err.message
|
295
|
-
}
|
296
|
-
end
|
305
|
+
errors_as_hashes =
|
306
|
+
errors.map do |err|
|
307
|
+
{ filename: err.filename, line_number: err.line_number, message: err.message }
|
308
|
+
end
|
297
309
|
|
298
310
|
File.open(@options['output-file'], 'w+') do |file|
|
299
311
|
file.write JSON.dump(errors_as_hashes)
|