module Solargraph::Diagnostics::RubocopHelpers

Utility methods for the RuboCop diagnostics reporter.

Public Instance Methods

fix_drive_letter(path) click to toggle source

RuboCop internally uses capitalized drive letters for Windows paths, so we need to convert the paths provided to the command.

@param path [String] @return [String]

# File lib/solargraph/diagnostics/rubocop_helpers.rb, line 28
def fix_drive_letter path
  return path unless path.match(/^[a-z]:/)
  path[0].upcase + path[1..-1]
end
generate_options(filename, code) click to toggle source

Generate command-line options for the specified filename and code.

@param filename [String] @param code [String] @return [Array(Array<String>, Array<String>)]

# File lib/solargraph/diagnostics/rubocop_helpers.rb, line 15
def generate_options filename, code
  args = ['-f', 'j', filename]
  base_options = RuboCop::Options.new
  options, paths = base_options.parse(args)
  options[:stdin] = code
  [options, paths]
end
redirect_stdout() { || ... } click to toggle source

@todo This is a smelly way to redirect output, but the RuboCop specs do

the same thing.

@return [String]

# File lib/solargraph/diagnostics/rubocop_helpers.rb, line 36
def redirect_stdout
  redir = StringIO.new
  $stdout = redir
  yield if block_given?
  $stdout = STDOUT
  redir.string
end