rails_best_practices-gorgeouscode 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/.gemtest +0 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.rspec.example +2 -0
  5. data/.rvmrc +2 -0
  6. data/.rvmrc.example +2 -0
  7. data/.travis.yml +1 -0
  8. data/Gemfile +10 -0
  9. data/Gemfile.lock +61 -0
  10. data/Guardfile +8 -0
  11. data/MIT_LICENSE +20 -0
  12. data/README.md +242 -0
  13. data/Rakefile +33 -0
  14. data/assets/result.html.erb +130 -0
  15. data/bin/rails_best_practices +6 -0
  16. data/install_supported_rubies.sh +7 -0
  17. data/lib/rails_best_practices.rb +32 -0
  18. data/lib/rails_best_practices/analyzer.rb +256 -0
  19. data/lib/rails_best_practices/command.rb +127 -0
  20. data/lib/rails_best_practices/core.rb +20 -0
  21. data/lib/rails_best_practices/core/check.rb +472 -0
  22. data/lib/rails_best_practices/core/checking_visitor.rb +82 -0
  23. data/lib/rails_best_practices/core/controllers.rb +8 -0
  24. data/lib/rails_best_practices/core/error.rb +36 -0
  25. data/lib/rails_best_practices/core/helpers.rb +8 -0
  26. data/lib/rails_best_practices/core/klasses.rb +34 -0
  27. data/lib/rails_best_practices/core/mailers.rb +8 -0
  28. data/lib/rails_best_practices/core/methods.rb +169 -0
  29. data/lib/rails_best_practices/core/model_associations.rb +57 -0
  30. data/lib/rails_best_practices/core/model_attributes.rb +41 -0
  31. data/lib/rails_best_practices/core/models.rb +8 -0
  32. data/lib/rails_best_practices/core/modules.rb +39 -0
  33. data/lib/rails_best_practices/core/nil.rb +37 -0
  34. data/lib/rails_best_practices/core/routes.rb +43 -0
  35. data/lib/rails_best_practices/core/runner.rb +261 -0
  36. data/lib/rails_best_practices/core_ext/enumerable.rb +9 -0
  37. data/lib/rails_best_practices/core_ext/erubis.rb +36 -0
  38. data/lib/rails_best_practices/core_ext/sexp.rb +837 -0
  39. data/lib/rails_best_practices/lexicals.rb +3 -0
  40. data/lib/rails_best_practices/lexicals/remove_tab_check.rb +26 -0
  41. data/lib/rails_best_practices/lexicals/remove_trailing_whitespace_check.rb +26 -0
  42. data/lib/rails_best_practices/prepares.rb +64 -0
  43. data/lib/rails_best_practices/prepares/controller_prepare.rb +100 -0
  44. data/lib/rails_best_practices/prepares/helper_prepare.rb +41 -0
  45. data/lib/rails_best_practices/prepares/mailer_prepare.rb +28 -0
  46. data/lib/rails_best_practices/prepares/model_prepare.rb +138 -0
  47. data/lib/rails_best_practices/prepares/route_prepare.rb +233 -0
  48. data/lib/rails_best_practices/prepares/schema_prepare.rb +33 -0
  49. data/lib/rails_best_practices/reviews.rb +33 -0
  50. data/lib/rails_best_practices/reviews/add_model_virtual_attribute_review.rb +85 -0
  51. data/lib/rails_best_practices/reviews/always_add_db_index_review.rb +176 -0
  52. data/lib/rails_best_practices/reviews/dry_bundler_in_capistrano_review.rb +33 -0
  53. data/lib/rails_best_practices/reviews/isolate_seed_data_review.rb +77 -0
  54. data/lib/rails_best_practices/reviews/keep_finders_on_their_own_model_review.rb +57 -0
  55. data/lib/rails_best_practices/reviews/law_of_demeter_review.rb +70 -0
  56. data/lib/rails_best_practices/reviews/move_code_into_controller_review.rb +49 -0
  57. data/lib/rails_best_practices/reviews/move_code_into_helper_review.rb +56 -0
  58. data/lib/rails_best_practices/reviews/move_code_into_model_review.rb +48 -0
  59. data/lib/rails_best_practices/reviews/move_finder_to_named_scope_review.rb +48 -0
  60. data/lib/rails_best_practices/reviews/move_model_logic_into_model_review.rb +49 -0
  61. data/lib/rails_best_practices/reviews/needless_deep_nesting_review.rb +83 -0
  62. data/lib/rails_best_practices/reviews/not_use_default_route_review.rb +47 -0
  63. data/lib/rails_best_practices/reviews/not_use_time_ago_in_words_review.rb +30 -0
  64. data/lib/rails_best_practices/reviews/overuse_route_customizations_review.rb +102 -0
  65. data/lib/rails_best_practices/reviews/protect_mass_assignment_review.rb +46 -0
  66. data/lib/rails_best_practices/reviews/remove_empty_helpers_review.rb +30 -0
  67. data/lib/rails_best_practices/reviews/remove_unused_methods_in_controllers_review.rb +111 -0
  68. data/lib/rails_best_practices/reviews/remove_unused_methods_in_helpers_review.rb +47 -0
  69. data/lib/rails_best_practices/reviews/remove_unused_methods_in_models_review.rb +108 -0
  70. data/lib/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review.rb +67 -0
  71. data/lib/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review.rb +40 -0
  72. data/lib/rails_best_practices/reviews/restrict_auto_generated_routes_review.rb +152 -0
  73. data/lib/rails_best_practices/reviews/review.rb +67 -0
  74. data/lib/rails_best_practices/reviews/simplify_render_in_controllers_review.rb +38 -0
  75. data/lib/rails_best_practices/reviews/simplify_render_in_views_review.rb +38 -0
  76. data/lib/rails_best_practices/reviews/use_before_filter_review.rb +60 -0
  77. data/lib/rails_best_practices/reviews/use_model_association_review.rb +70 -0
  78. data/lib/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review.rb +83 -0
  79. data/lib/rails_best_practices/reviews/use_observer_review.rb +104 -0
  80. data/lib/rails_best_practices/reviews/use_query_attribute_review.rb +113 -0
  81. data/lib/rails_best_practices/reviews/use_say_with_time_in_migrations_review.rb +50 -0
  82. data/lib/rails_best_practices/reviews/use_scope_access_review.rb +58 -0
  83. data/lib/rails_best_practices/version.rb +4 -0
  84. data/rails_best_practices.gemspec +53 -0
  85. data/rails_best_practices.yml +34 -0
  86. data/rake_rubies.sh +9 -0
  87. data/spec/fixtures/lib/rails_best_practices/plugins/reviews/not_use_rails_root_review.rb +11 -0
  88. data/spec/rails_best_practices/analyzer_spec.rb +45 -0
  89. data/spec/rails_best_practices/core/check_spec.rb +63 -0
  90. data/spec/rails_best_practices/core/checking_visitor_spec.rb +78 -0
  91. data/spec/rails_best_practices/core/controllers_spec.rb +5 -0
  92. data/spec/rails_best_practices/core/error_spec.rb +28 -0
  93. data/spec/rails_best_practices/core/helpers_spec.rb +5 -0
  94. data/spec/rails_best_practices/core/klasses_spec.rb +12 -0
  95. data/spec/rails_best_practices/core/mailers_spec.rb +5 -0
  96. data/spec/rails_best_practices/core/methods_spec.rb +44 -0
  97. data/spec/rails_best_practices/core/model_associations_spec.rb +22 -0
  98. data/spec/rails_best_practices/core/model_attributes_spec.rb +22 -0
  99. data/spec/rails_best_practices/core/models_spec.rb +5 -0
  100. data/spec/rails_best_practices/core/modules_spec.rb +26 -0
  101. data/spec/rails_best_practices/core/nil_spec.rb +35 -0
  102. data/spec/rails_best_practices/core/routes_spec.rb +27 -0
  103. data/spec/rails_best_practices/core/runner_spec.rb +22 -0
  104. data/spec/rails_best_practices/core_ext/enumerable_spec.rb +7 -0
  105. data/spec/rails_best_practices/core_ext/erubis_spec.rb +24 -0
  106. data/spec/rails_best_practices/core_ext/sexp_spec.rb +570 -0
  107. data/spec/rails_best_practices/lexicals/remove_tab_check_spec.rb +39 -0
  108. data/spec/rails_best_practices/lexicals/remove_trailing_whitespace_check_spec.rb +39 -0
  109. data/spec/rails_best_practices/prepares/controller_prepare_spec.rb +146 -0
  110. data/spec/rails_best_practices/prepares/helper_prepare_spec.rb +41 -0
  111. data/spec/rails_best_practices/prepares/mailer_prepare_spec.rb +14 -0
  112. data/spec/rails_best_practices/prepares/model_prepare_spec.rb +378 -0
  113. data/spec/rails_best_practices/prepares/route_prepare_spec.rb +691 -0
  114. data/spec/rails_best_practices/prepares/schema_prepare_spec.rb +28 -0
  115. data/spec/rails_best_practices/reviews/add_model_virtual_attribute_review_spec.rb +105 -0
  116. data/spec/rails_best_practices/reviews/always_add_db_index_review_spec.rb +260 -0
  117. data/spec/rails_best_practices/reviews/dry_bundler_in_capistrano_review_spec.rb +35 -0
  118. data/spec/rails_best_practices/reviews/isolate_seed_data_review_spec.rb +98 -0
  119. data/spec/rails_best_practices/reviews/keep_finders_on_their_own_model_review_spec.rb +95 -0
  120. data/spec/rails_best_practices/reviews/law_of_demeter_review_spec.rb +167 -0
  121. data/spec/rails_best_practices/reviews/move_code_into_controller_review_spec.rb +41 -0
  122. data/spec/rails_best_practices/reviews/move_code_into_helper_review_spec.rb +24 -0
  123. data/spec/rails_best_practices/reviews/move_code_into_model_review_spec.rb +68 -0
  124. data/spec/rails_best_practices/reviews/move_finder_to_named_scope_review_spec.rb +78 -0
  125. data/spec/rails_best_practices/reviews/move_model_logic_into_model_review_spec.rb +62 -0
  126. data/spec/rails_best_practices/reviews/needless_deep_nesting_review_spec.rb +167 -0
  127. data/spec/rails_best_practices/reviews/not_use_default_route_review_spec.rb +57 -0
  128. data/spec/rails_best_practices/reviews/not_use_times_ago_in_words_review_spec.rb +49 -0
  129. data/spec/rails_best_practices/reviews/overuse_route_customizations_review_spec.rb +177 -0
  130. data/spec/rails_best_practices/reviews/protect_mass_assignment_review_spec.rb +77 -0
  131. data/spec/rails_best_practices/reviews/remove_empty_helpers_review_spec.rb +27 -0
  132. data/spec/rails_best_practices/reviews/remove_unused_methods_in_controllers_review_spec.rb +314 -0
  133. data/spec/rails_best_practices/reviews/remove_unused_methods_in_helpers_review_spec.rb +84 -0
  134. data/spec/rails_best_practices/reviews/remove_unused_methods_in_models_review_spec.rb +670 -0
  135. data/spec/rails_best_practices/reviews/replace_complex_creation_with_factory_method_review_spec.rb +71 -0
  136. data/spec/rails_best_practices/reviews/replace_instance_variable_with_local_variable_review_spec.rb +40 -0
  137. data/spec/rails_best_practices/reviews/restrict_auto_generated_routes_review_spec.rb +354 -0
  138. data/spec/rails_best_practices/reviews/simplify_render_in_controllers_review_spec.rb +66 -0
  139. data/spec/rails_best_practices/reviews/simplify_render_in_views_review_spec.rb +82 -0
  140. data/spec/rails_best_practices/reviews/use_before_filter_review_spec.rb +116 -0
  141. data/spec/rails_best_practices/reviews/use_model_association_review_spec.rb +65 -0
  142. data/spec/rails_best_practices/reviews/use_multipart_alternative_as_content_type_of_email_review_spec.rb +213 -0
  143. data/spec/rails_best_practices/reviews/use_observer_review_spec.rb +154 -0
  144. data/spec/rails_best_practices/reviews/use_query_attribute_review_spec.rb +210 -0
  145. data/spec/rails_best_practices/reviews/use_say_with_time_in_migrations_review_spec.rb +118 -0
  146. data/spec/rails_best_practices/reviews/use_scope_access_review_spec.rb +184 -0
  147. data/spec/spec_helper.rb +17 -0
  148. metadata +386 -0
File without changes
@@ -0,0 +1,9 @@
1
+ .DS_STORE
2
+ .*.swp
3
+ pkg/**
4
+ *.gem
5
+ .bundle
6
+ rdoc/**
7
+ doc/**
8
+ .yardoc/**
9
+ rails_best_practices_output.html
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format nested
2
+ --color
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm gemset use ruby-1.9.3-p125@rails_best_practices
@@ -0,0 +1,2 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm gemset use rails_best_practices
@@ -0,0 +1 @@
1
+ rvm: 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ if RUBY_PLATFORM =~ /darwin/i
5
+ gem 'rb-fsevent'
6
+ gem 'growl'
7
+ end
8
+
9
+ gem 'guard'
10
+ gem 'guard-rspec'
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_best_practices-gorgeouscode (1.0.0)
5
+ activesupport
6
+ colored
7
+ erubis
8
+ i18n
9
+ progressbar
10
+ sexp_processor
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ activesupport (3.2.6)
16
+ i18n (~> 0.6)
17
+ multi_json (~> 1.0)
18
+ colored (1.2)
19
+ diff-lcs (1.1.3)
20
+ erubis (2.7.0)
21
+ growl (1.0.3)
22
+ guard (0.8.8)
23
+ thor (~> 0.14.6)
24
+ guard-rspec (0.5.7)
25
+ guard (>= 0.8.4)
26
+ haml (3.1.3)
27
+ i18n (0.6.0)
28
+ multi_json (1.3.6)
29
+ progressbar (0.11.0)
30
+ rake (0.9.2.2)
31
+ rb-fsevent (0.4.3.1)
32
+ rspec (2.7.0)
33
+ rspec-core (~> 2.7.0)
34
+ rspec-expectations (~> 2.7.0)
35
+ rspec-mocks (~> 2.7.0)
36
+ rspec-core (2.7.1)
37
+ rspec-expectations (2.7.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.7.0)
40
+ sexp_processor (4.0.0)
41
+ slim (1.0.4)
42
+ temple (~> 0.3.4)
43
+ tilt (~> 1.3.2)
44
+ temple (0.3.4)
45
+ thor (0.14.6)
46
+ tilt (1.3.3)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ bundler
53
+ growl
54
+ guard
55
+ guard-rspec
56
+ haml
57
+ rails_best_practices-gorgeouscode!
58
+ rake
59
+ rb-fsevent
60
+ rspec
61
+ slim
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2, :all_after_pass => false, :all_on_start => false, :cli => "--color --format nested --fail-fast" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 - 2012 Richard Huang (flyerhzm@gmail.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,242 @@
1
+ rails_best_practices
2
+ ====================
3
+
4
+ [![Build Status](https://secure.travis-ci.org/railsbp/rails_best_practices.png)](http://travis-ci.org/railsbp/rails_best_practices)
5
+
6
+ [![Click here to lend your support to: rails best practices and make a donation at www.pledgie.com !](http://www.pledgie.com/campaigns/12057.png?skin_name=chrome)](http://www.pledgie.com/campaigns/12057)
7
+
8
+ rails_best_practices is a code metric tool to check the quality of rails codes.
9
+
10
+ it supports following ORM/ODMs:
11
+
12
+ * activerecord
13
+ * mongoid
14
+ * mongomapper
15
+
16
+ following template engines:
17
+
18
+ * erb
19
+ * haml
20
+ * slim
21
+
22
+ rails_best_practices works well only in ruby 1.9.2 and ruby 1.9.3 so far.
23
+
24
+ Usage
25
+ -----
26
+
27
+ At the root directory of rails app
28
+
29
+ rails_best_practices .
30
+
31
+ or html output
32
+
33
+ rails_best_practices -f html .
34
+
35
+ By default rails_best_practices will do parse codes in vendor, spec, test and features directories. If you need, see the command options:
36
+
37
+ $ rails_best_practices -h
38
+ Usage: rails_best_practices [options]
39
+ -d, --debug Debug mode
40
+ -f, --format FORMAT output format
41
+ --without-color only output plain text without color
42
+ --with-textmate open file by textmate in html format
43
+ --with-mvim open file by mvim in html format
44
+ --with-hg display hg commit and username, only support html format
45
+ --with-git display git commit and username, only support html format
46
+ --template TEMPLATE customize erb template
47
+ --output-file OUTPUT_FILE output html file for the analyzing result
48
+ --silent silent mode
49
+ --vendor include vendor files
50
+ --spec include spec files
51
+ --test include test files
52
+ --features include features files
53
+ -x, --exclude PATTERNS Don't analyze files matching a pattern
54
+ (comma-separated regexp list)
55
+ -o, --only PATTERNS analyze files only matching a pattern
56
+ (comma-separated regexp list)
57
+ -g, --generate Generate configuration yaml
58
+ -v, --version Show this version
59
+ -h, --help Show this message
60
+
61
+ Resources
62
+ ---------
63
+
64
+ Homepage: <http://rails-bestpractices.com>
65
+
66
+ Online Service: <http://railsbp.com>
67
+
68
+ Github: <http://github.com/railsbp/rails_best_practices>
69
+
70
+ RDoc: <http://rdoc.rails-bestpractices.com>
71
+
72
+ Team Blog <http://rails-bestpractices.com/blog/posts>
73
+
74
+ Google Group: <https://groups.google.com/group/rails_best_practices>
75
+
76
+ Wiki: <http://github.com/railsbp/rails_best_practices/wiki>
77
+
78
+ Issue Tracker: <http://github.com/railsbp/rails_best_practices/issues>
79
+
80
+ Install
81
+ -------
82
+
83
+ rails_best_practices gem is rewritten based on ripper instead of ruby_parser to support ruby 1.9 new syntax.
84
+
85
+ gem install rails_best_practices
86
+
87
+ or add in Gemfile
88
+
89
+ gem "rails_best_practices"
90
+
91
+ Issue
92
+ -----
93
+
94
+ If you install the rails_best_practices with bundler-installed github-sourced gem, please use the following command instead.
95
+
96
+ bundle exec rails_best_practices .
97
+
98
+ If you got NoMethodError or any syntax error, you should use debug mode to detect which file rails_best_practices is parsing and getting the error.
99
+
100
+ rails_best_practices -d .
101
+
102
+ Then give me the error stack and the source code of the file that rails_best_practices is parsing error.
103
+
104
+ Customize Configuration
105
+ -----------------------
106
+
107
+ First run
108
+
109
+ rails_best_practices -g
110
+
111
+ to generate `rails_best_practices.yml` file.
112
+
113
+ Now you can customize this configuration file, the default configuration is as follows:
114
+
115
+ MoveFinderToNamedScopeCheck: { }
116
+ UseModelAssociationCheck: { }
117
+ UseScopeAccessCheck: { }
118
+ AddModelVirtualAttributeCheck: { }
119
+ ReplaceComplexCreationWithFactoryMethodCheck: { attribute_assignment_count: 2 }
120
+ MoveModelLogicIntoModelCheck: { use_count: 4 }
121
+ OveruseRouteCustomizationsCheck: { customize_count: 3 }
122
+ NeedlessDeepNestingCheck: { nested_count: 2 }
123
+ NotUseDefaultRouteCheck: { }
124
+ KeepFindersOnTheirOwnModelCheck: { }
125
+ LawOfDemeterCheck: { }
126
+ UseObserverCheck: { }
127
+ IsolateSeedDataCheck: { }
128
+ AlwaysAddDbIndexCheck: { }
129
+ UseBeforeFilterCheck: { customize_count: 2 }
130
+ MoveCodeIntoControllerCheck: { }
131
+ MoveCodeIntoModelCheck: { use_count: 2 }
132
+ MoveCodeIntoHelperCheck: { array_count: 3 }
133
+ ReplaceInstanceVariableWithLocalVariableCheck: { }
134
+ DryBundlerInCapistranoCheck: { }
135
+ UseSayWithTimeInMigrationsCheck: { }
136
+ UseQueryAttributeCheck: { }
137
+ RemoveTrailingWhitespaceCheck: { }
138
+ UseMultipartAlternativeAsContentTypeOfEmailCheck: {}
139
+ SimplifyRenderInViewsCheck: {}
140
+ SimplifyRenderInControllersCheck: {}
141
+ RemoveEmptyHelpersCheck: {}
142
+ RemoveTabCheck: {}
143
+ RestrictAutoGeneratedRoutesCheck: { }
144
+ RemoveUnusedMethodsInModelsCheck: { except_methods: [] }
145
+ RemoveUnusedMethodsInControllersCheck: { except_methods: [] }
146
+ RemoveUnusedMethodsInHelpersCheck: { except_methods: [] }
147
+ NotUseTimeAgoInWordsCheck: {}
148
+ ProtectMassAssignmentCheck: {}
149
+
150
+ You can remove or comment one review to disable it, and you can change the options.
151
+
152
+ Implementation
153
+ --------------
154
+
155
+ Move code from Controller to Model
156
+
157
+ 1. Move finder to named_scope (rails2 only)
158
+ 2. Use model association
159
+ 3. Use scope access
160
+ 4. Add model virtual attribute
161
+ 5. Replace complex creation with factory method
162
+ 6. Move model logic into the Model
163
+
164
+ RESTful Conventions
165
+
166
+ 1. Overuse route customizations
167
+ 2. Needless deep nesting
168
+ 3. Not use default route
169
+ 4. Restrict auto-generated routes
170
+
171
+ Model
172
+
173
+ 1. Keep finders on their own model (rails2 only)
174
+ 2. the law of demeter
175
+ 3. Use observer
176
+ 4. Use query attribute
177
+ 5. Remove unused methods in models
178
+ 6. Protect mass assignment
179
+
180
+ Mailer
181
+
182
+ 1. Use multipart/alternative as content_type of email
183
+
184
+ Migration
185
+
186
+ 1. Isolating seed data
187
+ 2. Always add db`index
188
+ 3. Use say with time in migrations
189
+
190
+ Controller
191
+
192
+ 1. Use before_filter
193
+ 2. Simplify render in controllers
194
+ 3. Remove unused methods in controllers
195
+
196
+ Helper
197
+
198
+ 1. Remove empty helpers
199
+ 2. Remove unused methods in helpers
200
+
201
+ View
202
+
203
+ 1. Move code into controller
204
+ 2. Move code into model
205
+ 3. Move code into helper
206
+ 4. Replace instance variable with local variable
207
+ 5. Simplify render in views
208
+ 6. Not use time_ago_in_words
209
+
210
+ Deployment
211
+
212
+ 1. Dry bundler in capistrano
213
+
214
+ Other
215
+
216
+ 1. Remove trailing whitespace
217
+ 2. Remove tab
218
+
219
+ Write Your Own Check List
220
+ -------------------------
221
+
222
+ If you want to write your own check list (some check list only for your rails projects), please read this first, [How to write your own check list?][1]
223
+
224
+ Contribute
225
+ ----------
226
+
227
+ If you want to add your rails best practices into the gem, please post your best practices on <http://rails-bestpractices.com>
228
+
229
+ Contact Us
230
+ ----------
231
+
232
+ We provide rails consulting services, you can contact us by twitter or email.
233
+
234
+ Follow us on twitter: <http://twitter.com/railsbp>
235
+
236
+ Send us email: <team@railsbp.com>
237
+
238
+
239
+ Copyright © 2009 - 2011 Richard Huang (flyerhzm@gmail.com), released under the MIT license
240
+
241
+
242
+ [1]:https://github.com/railsbp/rails_best_practices/wiki/How-to-write-your-own-check-list
@@ -0,0 +1,33 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ require "rake"
5
+ require "rspec"
6
+ require "rspec/core/rake_task"
7
+
8
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
9
+ require "rails_best_practices/version"
10
+
11
+ task :build do
12
+ system "gem build rails_best_practices.gemspec"
13
+ end
14
+
15
+ task :install => :build do
16
+ system "sudo gem install rails_best_practices-#{RailsBestPractices::VERSION}.gem"
17
+ end
18
+
19
+ task :release => :build do
20
+ puts "Tagging #{RailsBestPractices::VERSION}..."
21
+ system "git tag -a #{RailsBestPractices::VERSION}regedor -m 'Tagging #{RailsBestPractices::VERSION}regedor'"
22
+ puts "Pushing to Github..."
23
+ system "git push --tags"
24
+ puts "Pushing to rubygems.org..."
25
+ system "gem push rails_best_practices-#{RailsBestPractices::VERSION}.gem"
26
+ end
27
+
28
+ RSpec::Core::RakeTask.new(:spec) do |spec|
29
+ spec.pattern = "spec/**/*_spec.rb"
30
+ end
31
+
32
+ task :default => :spec
33
+ task :test => :spec
@@ -0,0 +1,130 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html>
3
+ <head>
4
+ <meta charset='UTF-8' />
5
+ <title>Output of rails_best_practices</title>
6
+ <style type="text/css">
7
+ body {
8
+ color: #333;
9
+ background: #eee;
10
+ padding: 0 20px;
11
+ }
12
+ h1 {
13
+ color: ##4E4E4E;
14
+ }
15
+ p {
16
+ margin: 5px 0;
17
+ }
18
+ table {
19
+ background: white;
20
+ border: 1px solid #666;
21
+ border-collapse: collapse;
22
+ margin: 10px 0;
23
+ font-size: 14px;
24
+ }
25
+ table th, table td {
26
+ padding: 4px;
27
+ border: 1px solid #D0D0D0;
28
+ }
29
+ table th {
30
+ background-color: #DFC;
31
+ color: #337022;
32
+ }
33
+ table td.filename {
34
+ color: #ED1556;
35
+ }
36
+ table tr:hover {
37
+ background-color: #FFFFC0;
38
+ }
39
+ ul {
40
+ clear: both;
41
+ display: inline-block;
42
+ padding: 0;
43
+ margin: 0;
44
+ }
45
+ ul li {
46
+ list-style: none;
47
+ display: none;
48
+ float: left;
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <h1>rails_best_practices output</h1>
54
+ <p>
55
+ Please go to
56
+ <a href='http://rails-bestpractices.com' target='_blank'>http://rails-bestpractices.com</a>
57
+ to see more useful Rails Best Practices.
58
+ </p>
59
+ <p>
60
+ <% if @errors.empty? %>
61
+ No error found. Cool!
62
+ <% else %>
63
+ Found <%= @errors.size %> warnings.
64
+ <% end %>
65
+ </p>
66
+ <ul>
67
+ <% @error_types.each do |error_type| %>
68
+ <li>
69
+ <input type="checkbox" id="<%= error_type.split(':').last %>" value="<%= error_type.split(':').last %>" />
70
+ <label for="<%= error_type.split(':').last%>"><%= error_type.split(':').last%></label>
71
+ </li>
72
+ <% end %>
73
+ </ul>
74
+ <table>
75
+ <tr>
76
+ <th>Filename</th>
77
+ <th>Line Number</th>
78
+ <th>Warning Message</th>
79
+ <% if @hg %>
80
+ <th>Hg Commit</th>
81
+ <th>Hg Username</th>
82
+ <% elsif @git %>
83
+ <th>Git Commit</th>
84
+ <th>Git Username</th>
85
+ <% end %>
86
+ </tr>
87
+ <% @errors.each do |error| %>
88
+ <tr class="<%= error.type.split(':').last %>">
89
+ <td class='filename'>
90
+ <% if @github %>
91
+ <a href='https://github.com/<%= @github_name %>/blob/<%= @last_commit_id %>/<%= error.short_filename %>#L<%= error.first_line_number %>' target='_blank'><%= error.short_filename %></a>
92
+ <% elsif @textmate %>
93
+ <a href='txmt://open/?url=file://<%= File.expand_path(error.filename) %>&amp;line=<%= error.line_number %>'><%= error.short_filename %></a>
94
+ <% elsif @mvim %>
95
+ <a href='mvim://open/?url=file://<%= File.expand_path(error.filename) %>&amp;line=<%= error.line_number %>'><%= error.short_filename %></a>
96
+ <% else %>
97
+ <%= error.short_filename %>
98
+ <% end %>
99
+ </td>
100
+ <td class='line'><%= error.line_number %></td>
101
+ <td class='message'>
102
+ <a href='<%= error.url %>' target='_blank'><%= error.message %></a>
103
+ </td>
104
+ <% if @hg %>
105
+ <td class='hg_commit'><%= error.hg_commit %></td>
106
+ <td class='hg_usename'><%= error.hg_username %></td>
107
+ <% elsif @git %>
108
+ <td class='git_commit'><%= error.git_commit %></td>
109
+ <td class='git_usename'><%= error.git_username %></td>
110
+ <% end %>
111
+ </tr>
112
+ <% end %>
113
+ </table>
114
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
115
+ <script type="text/javascript">
116
+ $(function() {
117
+ $('ul li').show();
118
+ $('input[type=checkbox]').prop('checked', true).click(function() {
119
+ if ($(this).attr('checked')) {
120
+ $(this).prop('checked', true);
121
+ $('.'+$(this).val()).show();
122
+ } else {
123
+ $(this).prop('checked', false);
124
+ $('.'+$(this).val()).hide();
125
+ }
126
+ });
127
+ });
128
+ </script>
129
+ </body>
130
+ </html>