class Pronto::TSLintNpm

Constants

CONFIG_FILE
CONFIG_KEYS

Attributes

tslint_executable[W]

Public Instance Methods

clean_up_tslint_output(output) click to toggle source
# File lib/pronto/tslint_npm.rb, line 80
def clean_up_tslint_output(output)
  # 1. Filter out offences without a warning or error
  # 2. Get the messages for that file
  # 3. Ignore errors without a line number for now
  return [] unless output.count > 0
  output.map do |offence|
    {
      msg: offence['failure'],
      line: offence['startPosition']['line'] + 1
    }
  end
end
files_to_lint() click to toggle source
# File lib/pronto/tslint_npm.rb, line 15
def files_to_lint
  @files_to_lint || /(.*\.ts)$/
end
files_to_lint=(regexp) click to toggle source
# File lib/pronto/tslint_npm.rb, line 19
def files_to_lint=(regexp)
  @files_to_lint = regexp.is_a?(Regexp) && regexp || Regexp.new(regexp)
end
inspect(patch) click to toggle source
# File lib/pronto/tslint_npm.rb, line 50
def inspect(patch)
  offences = run_tslint(patch)
  clean_up_tslint_output(offences)
    .map do |offence|
      patch
        .added_lines
        .select { |line| line.new_lineno == offence[:line] }
        .map { |line| new_message(offence[:msg], line) }
    end
end
new_message(offence, line) click to toggle source
# File lib/pronto/tslint_npm.rb, line 61
def new_message(offence, line)
  path = line.patch.delta.new_file[:path]
  level = :warning
  Message.new(path, line, level, offence, nil, self.class)
end
read_config() click to toggle source
# File lib/pronto/tslint_npm.rb, line 23
def read_config
  config_file = File.join(repo_path, CONFIG_FILE)
  return unless File.exist?(config_file)
  config = YAML.load_file(config_file)

  CONFIG_KEYS.each do |config_key|
    next unless config[config_key]
    send("#{config_key}=", config[config_key])
  end
end
repo_path() click to toggle source

private

# File lib/pronto/tslint_npm.rb, line 46
def repo_path
  @_repo_path ||= @patches.first.repo.path
end
run() click to toggle source
# File lib/pronto/tslint_npm.rb, line 34
def run
  return [] if !@patches || @patches.count.zero?
  read_config
  @patches
    .select { |patch| patch.additions > 0 }
    .select { |patch| ts_file?(patch.new_file_full_path) }
    .map { |patch| inspect(patch) }
    .flatten.compact
end
run_tslint(patch) click to toggle source
# File lib/pronto/tslint_npm.rb, line 71
def run_tslint(patch)
  Dir.chdir(repo_path) do
    escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
    JSON.parse(
      `#{tslint_executable} #{escaped_file_path} -t json`
    )
  end
end
ts_file?(path) click to toggle source
# File lib/pronto/tslint_npm.rb, line 67
def ts_file?(path)
  !!(files_to_lint =~ path.to_s)
end
tslint_executable() click to toggle source
# File lib/pronto/tslint_npm.rb, line 11
def tslint_executable
  @tslint_executable || 'tslint'.freeze
end