rails_best_practices 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +5 -0
- data/lib/rails_best_practices.rb +6 -0
- data/lib/rails_best_practices/checks.rb +1 -0
- data/lib/rails_best_practices/checks/dry_bundler_in_capistrano_check.rb +1 -1
- data/lib/rails_best_practices/checks/use_say_with_time_in_migrations_check.rb +31 -0
- data/lib/rails_best_practices/command.rb +10 -1
- data/lib/rails_best_practices/version.rb +1 -1
- data/rails_best_practices.yml +1 -0
- metadata +56 -40
data/README.textile
CHANGED
@@ -24,6 +24,9 @@ Usage: rails_best_practices [options]
|
|
24
24
|
--spec include spec files
|
25
25
|
--test include test files
|
26
26
|
--stories include stories files
|
27
|
+
-x, --exclude PATTERNS Don't analyze files matching a pattern
|
28
|
+
(comma-separated regexp list)
|
29
|
+
-v, --version Show this version
|
27
30
|
-h, --help Show this message
|
28
31
|
</code></pre>
|
29
32
|
|
@@ -85,6 +88,7 @@ MoveCodeIntoModelCheck: { }
|
|
85
88
|
MoveCodeIntoHelperCheck: { array_count: 3 }
|
86
89
|
ReplaceInstanceVariableWithLocalVariableCheck: { }
|
87
90
|
DryBundlerInCapistranoCheck: { }
|
91
|
+
UseSayWithTimeInMigrationsCheck: { }
|
88
92
|
</code></pre>
|
89
93
|
|
90
94
|
*************************************************
|
@@ -112,6 +116,7 @@ h2. Implementation
|
|
112
116
|
* Migration
|
113
117
|
## Isolating Seed Data
|
114
118
|
## Always add DB index
|
119
|
+
## Use Say with Time in Migrations
|
115
120
|
|
116
121
|
* Controller
|
117
122
|
## Use before_filter
|
data/lib/rails_best_practices.rb
CHANGED
@@ -11,6 +11,12 @@ module RailsBestPractices
|
|
11
11
|
['vendor', 'spec', 'test', 'stories', 'features'].each do |pattern|
|
12
12
|
files = ignore_files(files, "#{pattern}/") unless options[pattern]
|
13
13
|
end
|
14
|
+
|
15
|
+
# Exclude files based on exclude regexes if the option is set.
|
16
|
+
for pattern in options[:exclude]
|
17
|
+
files = ignore_files(files, pattern)
|
18
|
+
end
|
19
|
+
|
14
20
|
files
|
15
21
|
end
|
16
22
|
|
@@ -19,3 +19,4 @@ require 'rails_best_practices/checks/move_code_into_model_check'
|
|
19
19
|
require 'rails_best_practices/checks/move_code_into_helper_check'
|
20
20
|
require 'rails_best_practices/checks/replace_instance_variable_with_local_variable_check'
|
21
21
|
require 'rails_best_practices/checks/dry_bundler_in_capistrano_check'
|
22
|
+
require 'rails_best_practices/checks/use_say_with_time_in_migrations_check'
|
@@ -6,7 +6,7 @@ module RailsBestPractices
|
|
6
6
|
# Check config/deploy.rb file to make sure using the bundler's capistrano recipe.
|
7
7
|
#
|
8
8
|
# Implementation: check the method call,
|
9
|
-
# if there is a call "namespace :bundler", then it should use bundler's capistrano recipe.
|
9
|
+
# if there is a method call "namespace" with argument ":bundler", then it should use bundler's capistrano recipe.
|
10
10
|
class DryBundlerInCapistranoCheck < Check
|
11
11
|
|
12
12
|
def interesting_nodes
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rails_best_practices/checks/check'
|
3
|
+
|
4
|
+
module RailsBestPractices
|
5
|
+
module Checks
|
6
|
+
# Check a migration file to make sure to use say_with_time for customized data changes to produce a more readable output.
|
7
|
+
#
|
8
|
+
# Implementation: check if there are any first level messages called in self.up and self.down except say_with_time and default migration messages (such as :add_column and :create_table)
|
9
|
+
class UseSayWithTimeInMigrationsCheck < Check
|
10
|
+
|
11
|
+
DEFAULT_MIGRATION_MESSAGES = [:add_column, :add_index, :add_timestamps, :change_column, :change_column_default, :change_table, :create_table, :drop_table, :remove_column, :remove_index, :remove_timestamps, :rename_column, :rename_index, :rename_table]
|
12
|
+
|
13
|
+
def interesting_nodes
|
14
|
+
[:defs]
|
15
|
+
end
|
16
|
+
|
17
|
+
def interesting_files
|
18
|
+
MIGRATION_FILES
|
19
|
+
end
|
20
|
+
|
21
|
+
def evaluate_start(node)
|
22
|
+
block_body = node.grep_nodes(:node_type => :block).first.body
|
23
|
+
block_body.each do |iter|
|
24
|
+
if :call == iter[1].node_type and !(DEFAULT_MIGRATION_MESSAGES << :say_with_time).include? iter[1].message
|
25
|
+
add_error("use say with time in migrations", iter[1].file, iter[1].line)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -18,7 +18,8 @@ OptionParser.new do |opts|
|
|
18
18
|
end
|
19
19
|
|
20
20
|
opts.on_tail('-v', '--version', 'Show this version') do
|
21
|
-
|
21
|
+
require 'rails_best_practices/version'
|
22
|
+
puts RailsBestPractices::VERSION
|
22
23
|
exit
|
23
24
|
end
|
24
25
|
|
@@ -26,6 +27,14 @@ OptionParser.new do |opts|
|
|
26
27
|
puts opts
|
27
28
|
exit
|
28
29
|
end
|
30
|
+
|
31
|
+
opts.on("-x", "--exclude PATTERNS", "Don't analyze files matching a pattern", "(comma-separated regexp list)") do |list|
|
32
|
+
begin
|
33
|
+
options[:exclude] = list.split(/,/).map{|x| Regexp.new x}
|
34
|
+
rescue RegexpError => e
|
35
|
+
raise OptionParser::InvalidArgument, e.message
|
36
|
+
end
|
37
|
+
end
|
29
38
|
|
30
39
|
opts.parse!
|
31
40
|
end
|
data/rails_best_practices.yml
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_best_practices
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 5
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 5
|
10
|
+
version: 0.4.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Richard Huang
|
@@ -15,11 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-10 00:00:00 +08:00
|
19
19
|
default_executable: rails_best_practices
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
23
|
none: false
|
24
24
|
requirements:
|
25
25
|
- - ~>
|
@@ -30,12 +30,12 @@ dependencies:
|
|
30
30
|
- 0
|
31
31
|
- 4
|
32
32
|
version: 2.0.4
|
33
|
-
requirement: *id001
|
34
|
-
type: :runtime
|
35
33
|
name: ruby_parser
|
36
34
|
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -46,12 +46,12 @@ dependencies:
|
|
46
46
|
- 2
|
47
47
|
- 4
|
48
48
|
version: 1.2.4
|
49
|
-
requirement: *id002
|
50
|
-
type: :runtime
|
51
49
|
name: ruby2ruby
|
52
50
|
prerelease: false
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
56
56
|
requirements:
|
57
57
|
- - ~>
|
@@ -62,12 +62,12 @@ dependencies:
|
|
62
62
|
- 9
|
63
63
|
- 0
|
64
64
|
version: 0.9.0
|
65
|
-
requirement: *id003
|
66
|
-
type: :runtime
|
67
65
|
name: progressbar
|
68
66
|
prerelease: false
|
67
|
+
type: :runtime
|
68
|
+
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
71
71
|
none: false
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
@@ -77,12 +77,12 @@ dependencies:
|
|
77
77
|
- 1
|
78
78
|
- 2
|
79
79
|
version: "1.2"
|
80
|
-
requirement: *id004
|
81
|
-
type: :runtime
|
82
80
|
name: colored
|
83
81
|
prerelease: false
|
82
|
+
type: :runtime
|
83
|
+
version_requirements: *id004
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
|
-
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
88
88
|
- - "="
|
@@ -95,12 +95,12 @@ dependencies:
|
|
95
95
|
- beta
|
96
96
|
- 22
|
97
97
|
version: 2.0.0.beta.22
|
98
|
-
requirement: *id005
|
99
|
-
type: :development
|
100
98
|
name: rspec
|
101
99
|
prerelease: false
|
100
|
+
type: :development
|
101
|
+
version_requirements: *id005
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
|
-
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
104
104
|
none: false
|
105
105
|
requirements:
|
106
106
|
- - "="
|
@@ -111,10 +111,25 @@ dependencies:
|
|
111
111
|
- 0
|
112
112
|
- 18
|
113
113
|
version: 3.0.18
|
114
|
-
requirement: *id006
|
115
|
-
type: :development
|
116
114
|
name: haml
|
117
115
|
prerelease: false
|
116
|
+
type: :development
|
117
|
+
version_requirements: *id006
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - "="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 7
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
- 6
|
128
|
+
version: "0.6"
|
129
|
+
name: watchr
|
130
|
+
prerelease: false
|
131
|
+
type: :development
|
132
|
+
version_requirements: *id007
|
118
133
|
description: a code metric tool for rails codes, written in Ruby.
|
119
134
|
email:
|
120
135
|
- flyerhzm@gmail.com
|
@@ -126,37 +141,38 @@ extra_rdoc_files:
|
|
126
141
|
- MIT_LICENSE
|
127
142
|
- README.textile
|
128
143
|
files:
|
129
|
-
- lib/rails_best_practices
|
130
|
-
- lib/rails_best_practices/
|
131
|
-
- lib/rails_best_practices/checks/
|
132
|
-
- lib/rails_best_practices/checks/
|
133
|
-
- lib/rails_best_practices/checks/isolate_seed_data_check.rb
|
144
|
+
- lib/rails_best_practices.rb
|
145
|
+
- lib/rails_best_practices/version.rb
|
146
|
+
- lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
|
147
|
+
- lib/rails_best_practices/checks/use_model_association_check.rb
|
134
148
|
- lib/rails_best_practices/checks/keep_finders_on_their_own_model_check.rb
|
149
|
+
- lib/rails_best_practices/checks/add_model_virtual_attribute_check.rb
|
150
|
+
- lib/rails_best_practices/checks/use_say_with_time_in_migrations_check.rb
|
135
151
|
- lib/rails_best_practices/checks/law_of_demeter_check.rb
|
152
|
+
- lib/rails_best_practices/checks/use_scope_access_check.rb
|
136
153
|
- lib/rails_best_practices/checks/move_code_into_controller_check.rb
|
137
|
-
- lib/rails_best_practices/checks/move_code_into_helper_check.rb
|
138
|
-
- lib/rails_best_practices/checks/move_code_into_model_check.rb
|
139
|
-
- lib/rails_best_practices/checks/move_finder_to_named_scope_check.rb
|
140
154
|
- lib/rails_best_practices/checks/move_model_logic_into_model_check.rb
|
141
|
-
- lib/rails_best_practices/checks/needless_deep_nesting_check.rb
|
142
155
|
- lib/rails_best_practices/checks/not_use_default_route_check.rb
|
143
|
-
- lib/rails_best_practices/checks/overuse_route_customizations_check.rb
|
144
156
|
- lib/rails_best_practices/checks/replace_complex_creation_with_factory_method_check.rb
|
157
|
+
- lib/rails_best_practices/checks/dry_bundler_in_capistrano_check.rb
|
158
|
+
- lib/rails_best_practices/checks/isolate_seed_data_check.rb
|
159
|
+
- lib/rails_best_practices/checks/always_add_db_index_check.rb
|
145
160
|
- lib/rails_best_practices/checks/replace_instance_variable_with_local_variable_check.rb
|
146
|
-
- lib/rails_best_practices/checks/
|
147
|
-
- lib/rails_best_practices/checks/
|
161
|
+
- lib/rails_best_practices/checks/needless_deep_nesting_check.rb
|
162
|
+
- lib/rails_best_practices/checks/move_code_into_helper_check.rb
|
148
163
|
- lib/rails_best_practices/checks/use_observer_check.rb
|
149
|
-
- lib/rails_best_practices/checks/
|
164
|
+
- lib/rails_best_practices/checks/check.rb
|
165
|
+
- lib/rails_best_practices/checks/overuse_route_customizations_check.rb
|
166
|
+
- lib/rails_best_practices/checks/use_before_filter_check.rb
|
167
|
+
- lib/rails_best_practices/checks/move_code_into_model_check.rb
|
168
|
+
- lib/rails_best_practices/core.rb
|
150
169
|
- lib/rails_best_practices/checks.rb
|
151
|
-
- lib/rails_best_practices/command.rb
|
152
170
|
- lib/rails_best_practices/core/checking_visitor.rb
|
153
171
|
- lib/rails_best_practices/core/core_ext.rb
|
154
172
|
- lib/rails_best_practices/core/error.rb
|
155
|
-
- lib/rails_best_practices/core/runner.rb
|
156
173
|
- lib/rails_best_practices/core/visitable_sexp.rb
|
157
|
-
- lib/rails_best_practices/core.rb
|
158
|
-
- lib/rails_best_practices/
|
159
|
-
- lib/rails_best_practices.rb
|
174
|
+
- lib/rails_best_practices/core/runner.rb
|
175
|
+
- lib/rails_best_practices/command.rb
|
160
176
|
- rails_best_practices.yml
|
161
177
|
- MIT_LICENSE
|
162
178
|
- README.textile
|