Class: Xing::Edicts::StructureChecker

Inherits:
Edict::Rule
  • Object
show all
Includes:
Find
Defined in:
lib/xing/edicts/structure-checker.rb

Defined Under Namespace

Classes: Context, Error, Problem

Instance Method Summary collapse

Instance Method Details

#actionObject



21
22
23
24
# File 'lib/xing/edicts/structure-checker.rb', line 21

def action
  analyze
  report
end

#analyzeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/xing/edicts/structure-checker.rb', line 26

def analyze
  context = context_from_hash(context_hash || {:escapes => %w{common framework build}})
  return unless File.directory?(dir)
  find(dir) do |path|
    if File.directory?(path)
    else
      next if File.basename(path)[0] == ?.
      case path
      when /\.js\z/
        check_imports(path, context)
      end
    end
  end
end

#check_imports(path, context) ⇒ Object



78
79
80
81
82
83
# File 'lib/xing/edicts/structure-checker.rb', line 78

def check_imports(path, context)
  checker = Xing::Utils::ImportChecker.new(path, context)
  checker.check do |message, line, lineno|
    problem message, line, lineno, path
  end
end

#context_from_hash(hash) ⇒ Object



41
42
43
# File 'lib/xing/edicts/structure-checker.rb', line 41

def context_from_hash(hash)
  Context.new(hash)
end

#problem(msg, line, lineno, file) ⇒ Object



74
75
76
# File 'lib/xing/edicts/structure-checker.rb', line 74

def problem(msg, line, lineno, file)
  @problems << Problem.new(msg, line.chomp, lineno + 1, file)
end

#reportObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xing/edicts/structure-checker.rb', line 45

def report
  unless @problems.empty?
    @problems.group_by do |problem|
      problem.file
    end.each do |file, problems|
      out_stream.puts "In #{file}"
      problems.each{|prob| out_stream.puts "  " + prob.to_s}
      out_stream.puts
    end
    out_stream.puts "Problems found in ECMAScript structure"
    #raise Error, "Problems found in ECMAScript structure"
  end
end

#setupObject



17
18
19
# File 'lib/xing/edicts/structure-checker.rb', line 17

def setup
  @problems = []
end