Class: LanguageServer::Linter::Rubocop
- Inherits:
-
Object
- Object
- LanguageServer::Linter::Rubocop
- Defined in:
- lib/language_server/linter/rubocop.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source, config_path = "") ⇒ Rubocop
constructor
A new instance of Rubocop.
Constructor Details
#initialize(source, config_path = "") ⇒ Rubocop
Returns a new instance of Rubocop.
9 10 11 12 |
# File 'lib/language_server/linter/rubocop.rb', line 9 def initialize(source, config_path="") @source = source @config_path = config_path end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/language_server/linter/rubocop.rb', line 15 def call return [] unless defined? ::RuboCop args = [] args += ["--config", @config_path] if @config_path != '' args += ["--format", "json","--stdin", "lsp_buffer.rb"] o = nil begin $stdin = StringIO.new(@source) $stdout = StringIO.new config_store = ::RuboCop::ConfigStore.new , paths = ::RuboCop::Options.new.parse(args) config_store. = [:config] if [:config] runner = ::RuboCop::Runner.new(, config_store) runner.run(paths) o = $stdout.string ensure $stdin = STDIN $stdout = STDOUT end return [] unless o JSON .parse(o)['files'].map { |v| v['offenses'] } .flatten .map { |v| Error.new(line_num: v['location']['line'].to_i - 1, message: v['message'], type: convert_type(v['severity'])) } end |