rails_best_practices 1.19.2 → 1.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +0 -1
  3. data/.travis.yml +2 -3
  4. data/CHANGELOG.md +7 -7
  5. data/Gemfile +3 -5
  6. data/Gemfile.lock +125 -0
  7. data/Guardfile +2 -0
  8. data/README.md +6 -6
  9. data/Rakefile +2 -17
  10. data/assets/result.html.erb +2 -0
  11. data/lib/rails_best_practices.rb +3 -2
  12. data/lib/rails_best_practices/analyzer.rb +61 -49
  13. data/lib/rails_best_practices/cli.rb +22 -0
  14. data/lib/rails_best_practices/command.rb +1 -131
  15. data/lib/rails_best_practices/core/check.rb +64 -56
  16. data/lib/rails_best_practices/core/checks_loader.rb +24 -23
  17. data/lib/rails_best_practices/core/configs.rb +1 -2
  18. data/lib/rails_best_practices/core/controllers.rb +1 -2
  19. data/lib/rails_best_practices/core/error.rb +1 -1
  20. data/lib/rails_best_practices/core/helpers.rb +1 -2
  21. data/lib/rails_best_practices/core/mailers.rb +1 -2
  22. data/lib/rails_best_practices/core/methods.rb +27 -21
  23. data/lib/rails_best_practices/core/model_associations.rb +10 -5
  24. data/lib/rails_best_practices/core/models.rb +1 -2
  25. data/lib/rails_best_practices/core/modules.rb +1 -1
  26. data/lib/rails_best_practices/core/routes.rb +2 -2
  27. data/lib/rails_best_practices/core/runner.rb +67 -73
  28. data/lib/rails_best_practices/lexicals/long_line_check.rb +7 -3
  29. data/lib/rails_best_practices/option_parser.rb +156 -0
  30. data/lib/rails_best_practices/prepares.rb +1 -1
  31. data/lib/rails_best_practices/prepares/controller_prepare.rb +24 -17
  32. data/lib/rails_best_practices/prepares/gemfile_prepare.rb +2 -2
  33. data/lib/rails_best_practices/prepares/helper_prepare.rb +6 -1
  34. data/lib/rails_best_practices/prepares/initializer_prepare.rb +3 -3
  35. data/lib/rails_best_practices/prepares/mailer_prepare.rb +2 -1
  36. data/lib/rails_best_practices/prepares/model_prepare.rb +63 -23
  37. data/lib/rails_best_practices/prepares/route_prepare.rb +28 -21
  38. data/lib/rails_best_practices/prepares/schema_prepare.rb +1 -1
  39. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +38 -34
  40. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +94 -89
  41. data/lib/rails_best_practices/reviews/check_destroy_return_value_review.rb +15 -5
  42. data/lib/rails_best_practices/reviews/check_save_return_value_review.rb +20 -8
  43. data/lib/rails_best_practices/reviews/default_scope_is_evil_review.rb +1 -1
  44. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +1 -1
  45. data/lib/rails_best_practices/reviews/hash_syntax_review.rb +16 -16
  46. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +12 -12
  47. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +10 -11
  48. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +25 -24
  49. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +4 -4
  50. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +9 -10
  51. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +10 -11
  52. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +24 -22
  53. data/lib/rails_best_practices/reviews/not_rescue_exception_review.rb +1 -1
  54. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +1 -2
  55. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +1 -1
  56. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +8 -8
  57. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +35 -32
  58. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +4 -4
  59. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +26 -19
  60. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +12 -10
  61. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +38 -18
  62. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +11 -11
  63. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +77 -74
  64. data/lib/rails_best_practices/reviews/review.rb +2 -1
  65. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +2 -3
  66. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +12 -12
  67. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +18 -15
  68. data/lib/rails_best_practices/reviews/use_model_association_review.rb +15 -15
  69. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +24 -22
  70. data/lib/rails_best_practices/reviews/use_observer_review.rb +28 -28
  71. data/lib/rails_best_practices/reviews/use_parentheses_in_method_def_review.rb +6 -6
  72. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +68 -66
  73. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +9 -8
  74. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +16 -14
  75. data/lib/rails_best_practices/reviews/use_turbo_sprockets_rails3_review.rb +2 -1
  76. data/lib/rails_best_practices/version.rb +1 -1
  77. data/rails_best_practices.gemspec +38 -43
  78. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +1 -2
  79. data/spec/rails_best_practices/analyzer_spec.rb +73 -42
  80. data/spec/rails_best_practices/core/check_spec.rb +5 -5
  81. data/spec/rails_best_practices/core/checks_loader_spec.rb +3 -3
  82. data/spec/rails_best_practices/core/configs_spec.rb +1 -1
  83. data/spec/rails_best_practices/core/controllers_spec.rb +1 -1
  84. data/spec/rails_best_practices/core/error_spec.rb +21 -18
  85. data/spec/rails_best_practices/core/except_methods_spec.rb +7 -7
  86. data/spec/rails_best_practices/core/gems_spec.rb +4 -4
  87. data/spec/rails_best_practices/core/helpers_spec.rb +1 -1
  88. data/spec/rails_best_practices/core/klasses_spec.rb +3 -3
  89. data/spec/rails_best_practices/core/mailers_spec.rb +1 -1
  90. data/spec/rails_best_practices/core/methods_spec.rb +6 -6
  91. data/spec/rails_best_practices/core/model_associations_spec.rb +10 -6
  92. data/spec/rails_best_practices/core/model_attributes_spec.rb +4 -4
  93. data/spec/rails_best_practices/core/models_spec.rb +1 -1
  94. data/spec/rails_best_practices/core/modules_spec.rb +5 -5
  95. data/spec/rails_best_practices/core/routes_spec.rb +5 -5
  96. data/spec/rails_best_practices/core/runner_spec.rb +9 -7
  97. data/spec/rails_best_practices/core_ext/erubis_spec.rb +10 -10
  98. data/spec/rails_best_practices/lexicals/long_line_check_spec.rb +32 -31
  99. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +6 -6
  100. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +6 -6
  101. data/spec/rails_best_practices/prepares/config_prepare_spec.rb +2 -2
  102. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +18 -10
  103. data/spec/rails_best_practices/prepares/gemfile_prepare_spec.rb +17 -17
  104. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +3 -3
  105. data/spec/rails_best_practices/prepares/initializer_prepare_spec.rb +3 -3
  106. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +2 -2
  107. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +79 -43
  108. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +141 -76
  109. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +2 -2
  110. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +18 -12
  111. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +28 -22
  112. data/spec/rails_best_practices/reviews/check_destroy_return_value_review_spec.rb +15 -13
  113. data/spec/rails_best_practices/reviews/check_save_return_value_review_spec.rb +31 -21
  114. data/spec/rails_best_practices/reviews/default_scope_is_evil_review_spec.rb +6 -6
  115. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +5 -5
  116. data/spec/rails_best_practices/reviews/hash_syntax_review_spec.rb +13 -13
  117. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +7 -7
  118. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +9 -9
  119. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +29 -22
  120. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +6 -6
  121. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +11 -6
  122. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +32 -22
  123. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +7 -7
  124. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +9 -7
  125. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +9 -9
  126. data/spec/rails_best_practices/reviews/not_rescue_exception_review_spec.rb +9 -9
  127. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +5 -5
  128. data/spec/rails_best_practices/reviews/not_use_time_ago_in_words_review_spec.rb +7 -7
  129. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +7 -7
  130. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +24 -17
  131. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +6 -6
  132. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +64 -31
  133. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +21 -14
  134. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +57 -53
  135. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +10 -8
  136. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +20 -14
  137. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +54 -31
  138. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +9 -9
  139. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +13 -13
  140. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +11 -9
  141. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +7 -7
  142. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +35 -31
  143. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +6 -6
  144. data/spec/rails_best_practices/reviews/use_parentheses_in_method_def_review_spec.rb +10 -8
  145. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +31 -24
  146. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +15 -11
  147. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +14 -14
  148. data/spec/rails_best_practices/reviews/use_turbo_sprockets_rails3_review_spec.rb +61 -59
  149. metadata +16 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e41de74a9e0a16b8a3b3feb2fb709f21aec80098
4
- data.tar.gz: 98f10516376d7de5d3144b767196aa952b274748
2
+ SHA256:
3
+ metadata.gz: e7a2b67944c27b7a11e48f2c490a4ea1080fc4df39ad1d59b20cdeaedfb4b083
4
+ data.tar.gz: d96f6d7da9909bac895162f70ae1247a98a8df39da7fd2ce17365e959568c4f6
5
5
  SHA512:
6
- metadata.gz: 21e177d13d0f2137aebe7d683e87af1b97d53046e53b6bbd4722ae943a1061c5c6f740dee8efe9bc713c0be4550b70016849e17033faa6fd17e33a1204645963
7
- data.tar.gz: 81473ba0611d37c8a4a005710983330d0aa6a8c4537ba976e71d93bc670f8ef4fda1d492a44fe1966d2dc0bd91452460ade65f250f252238c187bbe9064e5935
6
+ metadata.gz: 244acdd4067af5f87364236d4fe5bc40d5a4d68b98d1c6786aaf0e53c7766626ef670c4aaa61d793a47bba643fddcd2cbd545a4697dff8d0a3d6f7238912c2b5
7
+ data.tar.gz: 9b4ca4c95172317d9017691399fcb9211295bad98959477fa8fa24a054a7a6283dc7cdbabd926e925ccf0f3ea9bfe1dde3e594cc42a2db7bd3b37758cb7bdc6e
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  .DS_STORE
2
2
  .*.swp
3
- Gemfile.lock
4
3
  pkg/**
5
4
  *.gem
6
5
  .bundle
data/.travis.yml CHANGED
@@ -1,5 +1,4 @@
1
- sudo: false
2
1
  language: ruby
3
- cache: bundler
4
2
  rvm:
5
- - 2.3.3
3
+ - 2.6.4
4
+ script: bundle exec rspec spec
data/CHANGELOG.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # Next Release
2
2
 
3
- ## 1.19.2
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
- * Forcing requrie_all version
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', '~> 2.14.0'
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Guardfile
2
4
  # More info at https://github.com/guard/guard#readme
3
5
 
data/README.md CHANGED
@@ -3,7 +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
+ [![AwesomeCode Status for flyerhzm/rails_best_practices](https://awesomecode.io/projects/d02ecd70-e068-4ad4-b61a-7003ac24b49a/status)](https://awesomecode.io/repos/flyerhzm/rails_best_practices)
7
7
 
8
8
  [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
9
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)
@@ -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
- RDoc: <http://rdoc.rails-bestpractices.com>
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
- require 'bundler'
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
- $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
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'
@@ -121,6 +121,8 @@
121
121
  <a href='subl://open?url=file://<%= File.expand_path(error.filename) %>&amp;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) %>&amp;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 %>
@@ -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/'.freeze
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 ||= begin
108
- files = expand_dirs_to_files(@path)
109
- files = file_sort(files)
107
+ @parse_files ||=
108
+ begin
109
+ files = expand_dirs_to_files(@path)
110
+ files = file_sort(files)
110
111
 
111
- if @options['only'].present?
112
- files = file_accept(files, @options['only'])
113
- end
112
+ if @options['only'].present?
113
+ files = file_accept(files, @options['only'])
114
+ end
114
115
 
115
- # By default, tmp, vender, spec, test, features are ignored.
116
- %w[vendor spec test features tmp].each do |dir|
117
- files = file_ignore(files, File.join(@path, dir)) unless @options[dir]
118
- end
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
- # Exclude files based on exclude regexes if the option is set.
121
- @options['exclude'].each do |pattern|
122
- files = file_ignore(files, pattern)
123
- end
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
- %w[Capfile Gemfile Gemfile.lock].each do |file|
126
- files.unshift File.join(@path, file)
127
- end
126
+ %w[Capfile Gemfile Gemfile.lock].each do |file|
127
+ files.unshift File.join(@path, file)
128
+ end
128
129
 
129
- files.compact
130
- end
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 { |entry|
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
- }.flatten
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 = files.find_all { |file| file !~ Core::Check::MAILER_FILES && file !~ Core::Check::MODEL_FILES && file !~ Core::Check::HELPER_FILES }
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
- 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`
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 =~ /\/$/ ? @runner.class.base_path.size : @runner.class.base_path.size + 1
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
- git_info = `cd #{@runner.class.base_path} && git blame -L #{error.line_number.split(',').first},+1 #{error.filename[start..-1]}`
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 = @options['template'] ? File.read(File.expand_path(@options['template'])) : File.read(File.join(File.dirname(__FILE__), '..', '..', 'assets', 'result.html.erb'))
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'] ? @options['last-commit-id'] : `cd #{@runner.class.base_path} && git rev-parse HEAD`.chomp
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
- errors: errors,
238
- error_types: error_types,
239
- textmate: @options['with-textmate'],
240
- sublime: @options['with-sublime'],
241
- mvim: @options['with-mvim'],
242
- github: @options['with-github'],
243
- github_name: @options['github-name'],
244
- last_commit_id: last_commit_id,
245
- git: @options['with-git'],
246
- hg: @options['with-hg']
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 = REXML::Document.new.tap do |d|
255
- d << REXML::XMLDecl.new
256
- end
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 = errors.map do |err|
291
- {
292
- filename: err.filename,
293
- line_number: err.line_number,
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)