Class: JSHint4r::Linter

Inherits:
Object
  • Object
show all
Defined in:
lib/jshint4r/linter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, opts = nil) ⇒ Linter

param

ExecJS::*::Context context

param

Hash opts



7
8
9
10
# File 'lib/jshint4r/linter.rb', line 7

def initialize( context, opts = nil )
  @context = context
  @opts    = opts || {}
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



11
12
13
# File 'lib/jshint4r/linter.rb', line 11

def context
  @context
end

#optsObject (readonly)

Returns the value of attribute opts.



11
12
13
# File 'lib/jshint4r/linter.rb', line 11

def opts
  @opts
end

Instance Method Details

#allow_unsafe_character(errors) ⇒ Object

param

Array errors

return

Array



31
32
33
34
35
36
37
38
39
40
# File 'lib/jshint4r/linter.rb', line 31

def allow_unsafe_character( errors )
  errors.select { |e|
    case e['reason']
    when /Unsafe character\./, /Too many errors\./
      false
    else
      true
    end
  }
end

#lint(target) ⇒ Object

param

File

return

Array or nil



17
18
19
20
21
22
23
24
25
# File 'lib/jshint4r/linter.rb', line 17

def lint( target )
  errors = context.call('JSHINT.run', File.read(target), opts )
  if errors
    errors = errors.compact
    errors = allow_unsafe_character(errors) if opts['unsafechar']
  end

  errors
end