Module: Eslintrb

Defined in:
lib/eslintrb.rb,
lib/eslintrb/lint.rb,
lib/eslintrb/version.rb,
lib/eslintrb/eslinttask.rb,
lib/eslintrb/reporter/default.rb

Defined Under Namespace

Modules: Reporter Classes: EslintTask, Lint

Constant Summary collapse

VERSION =
"2.1.0"
SUBMODULE =
"641ccd5459f8714f74e0646bda54e257986f5b11"

Class Method Summary collapse

Class Method Details

.lint(source, options = nil, globals = nil) ⇒ Object



9
10
11
# File 'lib/eslintrb.rb', line 9

def self.lint(source, options = nil, globals = nil)
  Lint.new(options, globals).lint(source)
end

.report(source, options = nil, globals = nil, out = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/eslintrb.rb', line 13

def self.report(source, options = nil, globals = nil, out = nil)
  reporter = Reporter::Default.new
  linter = Lint.new(options, globals)
  report = ''
  if source.is_a?(Array) then
    source.each do |src|
      if !src.is_a?(String) then
        p src.to_s
        raise ArgumentError, 'Expected array of strings. Instead get ' + src.class.to_s
      end
      errors = linter.lint(File.read(src))
      rep = reporter.format errors, src
      if out && rep.size > 0 then
        out.puts rep
      end
      report += rep
    end
  else
    errors = linter.lint(source)
    report = reporter.format errors
    if out then
      out.puts report
    end
  end
  report
end