rails_best_practices 1.10.0 → 1.10.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_best_practices (1.10.0)
4
+ rails_best_practices (1.10.1)
5
5
  activesupport
6
6
  awesome_print
7
7
  colored
data/README.md CHANGED
@@ -1,8 +1,9 @@
1
- rails_best_practices
2
- ====================
1
+ # rails_best_practices
3
2
 
4
3
  [![Build Status](https://secure.travis-ci.org/railsbp/rails_best_practices.png)](http://travis-ci.org/railsbp/rails_best_practices)
5
4
 
5
+ [![Coderwall Endorse](http://api.coderwall.com/flyerhzm/endorsecount.png)](http://coderwall.com/flyerhzm)
6
+
6
7
  [![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
 
8
9
  rails_best_practices is a code metric tool to check the quality of rails codes.
@@ -21,8 +22,7 @@ following template engines:
21
22
 
22
23
  rails_best_practices works well only in ruby 1.9.2 and ruby 1.9.3 so far.
23
24
 
24
- Usage
25
- -----
25
+ ## Usage
26
26
 
27
27
  At the root directory of rails app
28
28
 
@@ -58,8 +58,7 @@ By default rails_best_practices will do parse codes in vendor, spec, test and fe
58
58
  -v, --version Show this version
59
59
  -h, --help Show this message
60
60
 
61
- Resources
62
- ---------
61
+ ## Resources
63
62
 
64
63
  Homepage: <http://rails-bestpractices.com>
65
64
 
@@ -77,8 +76,7 @@ Wiki: <http://github.com/railsbp/rails_best_practices/wiki>
77
76
 
78
77
  Issue Tracker: <http://github.com/railsbp/rails_best_practices/issues>
79
78
 
80
- Install
81
- -------
79
+ ## Install
82
80
 
83
81
  rails_best_practices gem is rewritten based on ripper instead of ruby_parser to support ruby 1.9 new syntax.
84
82
 
@@ -88,8 +86,7 @@ or add in Gemfile
88
86
 
89
87
  gem "rails_best_practices"
90
88
 
91
- Issue
92
- -----
89
+ ## Issue
93
90
 
94
91
  If you install the rails_best_practices with bundler-installed github-sourced gem, please use the following command instead.
95
92
 
@@ -101,8 +98,7 @@ If you got NoMethodError or any syntax error, you should use debug mode to detec
101
98
 
102
99
  Then give me the error stack and the source code of the file that rails_best_practices is parsing error.
103
100
 
104
- Customize Configuration
105
- -----------------------
101
+ ## Customize Configuration
106
102
 
107
103
  First run
108
104
 
@@ -152,8 +148,7 @@ Now you can customize this configuration file, the default configuration is as f
152
148
 
153
149
  You can remove or comment one review to disable it, and you can change the options.
154
150
 
155
- Implementation
156
- --------------
151
+ ## Implementation
157
152
 
158
153
  Move code from Controller to Model
159
154
 
@@ -222,18 +217,15 @@ Other
222
217
  4. Use parentheses in method def
223
218
  5. Long line
224
219
 
225
- Write Your Own Check List
226
- -------------------------
220
+ ## Write Your Own Check List
227
221
 
228
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]
229
223
 
230
- Contribute
231
- ----------
224
+ ## Contribute
232
225
 
233
226
  If you want to add your rails best practices into the gem, please post your best practices on <http://rails-bestpractices.com>
234
227
 
235
- Contact Us
236
- ----------
228
+ ## Contact Us
237
229
 
238
230
  We provide rails consulting services, you can contact us by twitter or email.
239
231
 
@@ -13,6 +13,8 @@ module RailsBestPractices
13
13
  interesting_nodes :hash, :bare_assoc_hash
14
14
  interesting_files ALL_FILES
15
15
 
16
+ VALID_SYMBOL_KEY = /\A[@$_A-Za-z]([_\w]*[!_=?\w])?\z/
17
+
16
18
  def initialize(options = {})
17
19
  super()
18
20
  @only_symbol = options[:only_symbol]
@@ -21,43 +23,51 @@ module RailsBestPractices
21
23
 
22
24
  # check hash node to see if it is ruby 1.8 style.
23
25
  def start_hash(node)
24
- return if s(:hash, nil) == node
25
- pair_nodes = node[1][1]
26
-
27
- if hash_is_18?(pair_nodes)
26
+ if !empty_hash?(node) &&
27
+ hash_is_18?(node) &&
28
+ valid_keys?(node) &&
29
+ !haml_class_node?(node)
28
30
  add_error "change Hash Syntax to 1.9"
29
31
  end
30
32
  end
31
33
 
32
- # check bare_assoc_hash node to see if it is ruby 1.8 style.
33
- def start_bare_assoc_hash(node)
34
- pair_nodes = node[1]
34
+ alias_method :start_bare_assoc_hash, :start_hash
35
35
 
36
- if hash_is_18?(pair_nodes)
37
- add_error "change Hash Syntax to 1.9"
36
+ protected
37
+ # check if hash node is empty.
38
+ def empty_hash?(node)
39
+ s(:hash, nil) == node || s(:bare_assoc_hash, nil) == node
38
40
  end
39
- end
40
41
 
41
- protected
42
42
  # check if hash key/value pairs are ruby 1.8 style.
43
- #
44
- # hash key of ruby 1.9 style is :@label,
45
- # so if it is not, then it is ruby 1.8 style.
46
- def hash_is_18?(pair_nodes)
43
+ def hash_is_18?(node)
44
+ pair_nodes = :hash == node.sexp_type ? node[1][1] : node[1]
47
45
  return false if pair_nodes.blank?
46
+
48
47
  pair_nodes.size.times do |i|
49
48
  if @only_symbol
50
49
  return true if :symbol_literal == pair_nodes[i][1].sexp_type
51
50
  elsif @only_string
52
51
  return true if :string_literal == pair_nodes[i][1].sexp_type
53
- elsif :@label != pair_nodes[i][1].sexp_type
52
+ elsif :symbol_literal == pair_nodes[i][1].sexp_type ||
53
+ :string_literal == pair_nodes[i][1].sexp_type
54
54
  return true
55
55
  end
56
56
  end
57
57
 
58
58
  false
59
59
  end
60
+
61
+ # check if the hash keys are valid to be converted to ruby 1.9
62
+ # syntax.
63
+ def valid_keys?(node)
64
+ node.hash_keys.all? { |key| key =~ VALID_SYMBOL_KEY }
65
+ end
66
+
67
+ # check if hash is generated by haml class or id nodes.
68
+ def haml_class_node?(node)
69
+ node.hash_size == 1 && (node.hash_keys.first == "class" || node.hash_keys.first == "id")
70
+ end
60
71
  end
61
72
  end
62
73
  end
63
-
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "1.10.0"
3
+ VERSION = "1.10.1"
4
4
  end
@@ -62,6 +62,32 @@ module RailsBestPractices
62
62
  runner.should have(1).errors
63
63
  runner.errors[0].to_s.should == "app/models/user.rb:3 - change Hash Syntax to 1.9"
64
64
  end
65
+
66
+ it "should ignore haml_out" do
67
+ content =<<-EOF
68
+ %div{ class: "foo1" }
69
+ .div{ class: "foo2" }
70
+ #div{ class: "foo3" }
71
+ EOF
72
+ runner.review('app/views/files/show.html.haml', content)
73
+ runner.should have(0).errors
74
+ end
75
+
76
+ it "should not consider hash with array key" do
77
+ content =<<-EOF
78
+ transition [:unverified, :verified] => :deleted
79
+ EOF
80
+ runner.review('app/models/post.rb', content)
81
+ runner.should have(0).errors
82
+ end
83
+
84
+ it "should not consider hash with charaters not valid for symbol" do
85
+ content =<<-EOF
86
+ subject.stub(:` => 'Error')
87
+ EOF
88
+ runner.review('app/models/post.rb', content)
89
+ runner.should have(0).errors
90
+ end
65
91
  end
66
92
  end
67
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_best_practices
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.0
4
+ version: 1.10.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-19 00:00:00.000000000 Z
12
+ date: 2012-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sexp_processor
16
- requirement: &70312121266920 !ruby/object:Gem::Requirement
16
+ requirement: &70244299371240 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70312121266920
24
+ version_requirements: *70244299371240
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: progressbar
27
- requirement: &70312121266140 !ruby/object:Gem::Requirement
27
+ requirement: &70244299370320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70312121266140
35
+ version_requirements: *70244299370320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: colored
38
- requirement: &70312121264060 !ruby/object:Gem::Requirement
38
+ requirement: &70244299368200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70312121264060
46
+ version_requirements: *70244299368200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: erubis
49
- requirement: &70312121262840 !ruby/object:Gem::Requirement
49
+ requirement: &70244299367020 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70312121262840
57
+ version_requirements: *70244299367020
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: i18n
60
- requirement: &70312121261320 !ruby/object:Gem::Requirement
60
+ requirement: &70244299365100 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70312121261320
68
+ version_requirements: *70244299365100
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &70312121281720 !ruby/object:Gem::Requirement
71
+ requirement: &70244299385840 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70312121281720
79
+ version_requirements: *70244299385840
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: awesome_print
82
- requirement: &70312121280640 !ruby/object:Gem::Requirement
82
+ requirement: &70244299384580 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70312121280640
90
+ version_requirements: *70244299384580
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &70312121279160 !ruby/object:Gem::Requirement
93
+ requirement: &70244299383080 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70312121279160
101
+ version_requirements: *70244299383080
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec
104
- requirement: &70312121276940 !ruby/object:Gem::Requirement
104
+ requirement: &70244299380940 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70312121276940
112
+ version_requirements: *70244299380940
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: haml
115
- requirement: &70312121275740 !ruby/object:Gem::Requirement
115
+ requirement: &70244299379800 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70312121275740
123
+ version_requirements: *70244299379800
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: slim
126
- requirement: &70312121295400 !ruby/object:Gem::Requirement
126
+ requirement: &70244299399240 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70312121295400
134
+ version_requirements: *70244299399240
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: bundler
137
- requirement: &70312121292680 !ruby/object:Gem::Requirement
137
+ requirement: &70244299396840 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70312121292680
145
+ version_requirements: *70244299396840
146
146
  description: a code metric tool for rails codes, written in Ruby.
147
147
  email:
148
148
  - flyerhzm@gmail.com
@@ -325,7 +325,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
325
325
  version: '0'
326
326
  segments:
327
327
  - 0
328
- hash: -3377092891025064967
328
+ hash: -3797206044319773055
329
329
  required_rubygems_version: !ruby/object:Gem::Requirement
330
330
  none: false
331
331
  requirements: