rails_best_practices 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,10 +7,10 @@ module RailsBestPractices
7
7
  NODE_TYPES = [:call, :defn, :defs, :if, :unless, :class, :lasgn, :ivar, :block, :iter]
8
8
 
9
9
  CONTROLLER_FILES = /_controller\.rb$/
10
- MIGRATION_FILES = /db\/migrate\/.*\.rb/
11
- MODLE_FILES = /models\/.*\.rb/
12
- VIEW_FILES = /views\/.*\.(erb|haml)/
13
- PARTIAL_VIEW_FILES = /views\/.*\/_.*\.(erb|haml)/
10
+ MIGRATION_FILES = /db\/migrate\/.*\.rb$/
11
+ MODLE_FILES = /models\/.*\.rb$/
12
+ VIEW_FILES = /views\/.*\.(erb|haml)$/
13
+ PARTIAL_VIEW_FILES = /views\/.*\/_.*\.(erb|haml)$/
14
14
 
15
15
  attr_reader :errors
16
16
 
@@ -45,8 +45,11 @@ module RailsBestPractices
45
45
  def member_and_collection_count_for_rails2(node)
46
46
  hash_nodes = node.grep_nodes(:node_type => :hash)
47
47
  return 0 if hash_nodes.empty?
48
- customize_hash = eval(hash_nodes.first.to_ruby)
49
- (customize_hash[:member].size || 0) + (customize_hash[:collection].size || 0)
48
+ hash_key_node = hash_nodes.first[1]
49
+ if :lit == hash_key_node.node_type and [:member, :collection].include? hash_key_node[1]
50
+ customize_hash = eval(hash_nodes.first.to_ruby)
51
+ (customize_hash[:member].size || 0) + (customize_hash[:collection].size || 0)
52
+ end
50
53
  end
51
54
  end
52
55
  end
@@ -21,7 +21,7 @@ module RailsBestPractices
21
21
  def evaluate_start(node)
22
22
  block_body = node.grep_nodes(:node_type => :block).first.body
23
23
  block_body.each do |iter|
24
- if :call == iter[1].node_type and !(DEFAULT_MIGRATION_MESSAGES << :say_with_time).include? iter[1].message
24
+ if :iter == iter.node_type and :call == iter[1].node_type and !(DEFAULT_MIGRATION_MESSAGES << :say_with_time).include? iter[1].message
25
25
  add_error("use say with time in migrations", iter[1].file, iter[1].line)
26
26
  end
27
27
  end
@@ -44,7 +44,10 @@ runner.set_debug if options['debug']
44
44
 
45
45
  files = RailsBestPractices::analyze_files(ARGV, options)
46
46
  bar = ProgressBar.new('Analyzing', files.size)
47
- files.each { |file| runner.check_file(file); bar.inc }
47
+ files.each do |file|
48
+ runner.check_file(file)
49
+ bar.inc unless options['debug']
50
+ end
48
51
  bar.finish
49
52
 
50
53
  runner.errors.each {|error| puts error.to_s.red}
@@ -23,12 +23,13 @@ module RailsBestPractices
23
23
  end
24
24
 
25
25
  def check(filename, content)
26
- if filename =~ /.*\.erb/
26
+ puts filename if @debug
27
+ if filename =~ /.*\.erb$/
27
28
  content = ERB.new(content).src
28
29
  # remove the coding line which exists in Ruby 1.9
29
30
  content.gsub!(/#coding:US-ASCII\n/, '')
30
31
  end
31
- if filename =~ /.*\.haml/
32
+ if filename =~ /.*\.haml$/
32
33
  require 'haml'
33
34
  content = Haml::Engine.new(content).precompiled
34
35
  # remove \xxx characters
@@ -55,7 +56,6 @@ module RailsBestPractices
55
56
  private
56
57
 
57
58
  def parse(filename, content)
58
- puts filename if @debug
59
59
  begin
60
60
  RubyParser.new.parse(content, filename)
61
61
  rescue Exception => e
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module RailsBestPractices
3
- VERSION = "0.4.5"
3
+ VERSION = "0.4.6"
4
4
  end
5
5
 
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: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Richard Huang
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-10 00:00:00 +08:00
18
+ date: 2010-10-15 00:00:00 +08:00
19
19
  default_executable: rails_best_practices
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency