Module: Solargraph::Diagnostics::RubocopHelpers
- Included in:
- Rubocop, LanguageServer::Message::TextDocument::Formatting
- Defined in:
- lib/solargraph/diagnostics/rubocop_helpers.rb
Overview
Utility methods for the RuboCop diagnostics reporter.
Class Method Summary collapse
-
.fix_drive_letter(path) ⇒ String
RuboCop internally uses capitalized drive letters for Windows paths, so we need to convert the paths provided to the command.
-
.generate_options(filename, code) ⇒ Array(Array<String>, Array<String>)
Generate command-line options for the specified filename and code.
- .redirect_stdout ⇒ String
Class Method Details
.fix_drive_letter(path) ⇒ String
RuboCop internally uses capitalized drive letters for Windows paths, so we need to convert the paths provided to the command.
28 29 30 31 |
# 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) ⇒ Array(Array<String>, Array<String>)
Generate command-line options for the specified filename and code.
15 16 17 18 19 20 21 |
# File 'lib/solargraph/diagnostics/rubocop_helpers.rb', line 15 def filename, code args = ['-f', 'j', filename] = RuboCop::Options.new , paths = .parse(args) [:stdin] = code [, paths] end |
.redirect_stdout ⇒ String
TODO:
This is a smelly way to redirect output, but the RuboCop specs do the same thing.
36 37 38 39 40 41 42 |
# 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 |