Class: Pronto::JSHint

Inherits:
Runner
  • Object
show all
Defined in:
lib/pronto/jshint.rb

Instance Method Summary collapse

Instance Method Details

#inspect(patch) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pronto/jshint.rb', line 15

def inspect(patch)
  offences = if File.exist?('.jshintrc')
               Jshintrb.lint(patch.new_file_full_path, :jshintrc)
             else
               Jshintrb.lint(patch.new_file_full_path)
             end.compact

  offences.map do |offence|
    patch.added_lines.select { |line| line.new_lineno == offence['line'] }
      .map { |line| new_message(offence, line) }
  end
end

#js_file?(path) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/pronto/jshint.rb', line 35

def js_file?(path)
  %w(.js .es6 .js.es6).include? File.extname(path)
end

#new_message(offence, line) ⇒ Object



28
29
30
31
32
33
# File 'lib/pronto/jshint.rb', line 28

def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  level = :warning

  Message.new(path, line, level, offence['reason'], nil, self.class)
end

#runObject



6
7
8
9
10
11
12
13
# File 'lib/pronto/jshint.rb', line 6

def run
  return [] unless @patches

  @patches.select { |patch| patch.additions > 0 }
    .select { |patch| js_file?(patch.new_file_full_path) }
    .map { |patch| inspect(patch) }
    .flatten.compact
end