Issue #14938 has been updated by nobu (Nobuyoshi Nakada).


Why don't you use ripper?

```ruby
#!/usr/bin/ruby
require 'ripper'
class Lint < Ripper
  def warn(*s)
    @results << [:warning, lineno, column, *s]
  end
  alias warning warn

  def results
    unless defined?(@results) and @results
      @results = []
      parse
    end
    @results
  end
end

$VERBOSE = true
results = Lint.new("def f;a = 0;end").results
p results
```

```
$ ruby lint.rb 
[[:warning, 1, 15, "assigned but unused variable - %s", "a"]]
```

----------------------------------------
Feature #14938: Provide API to get same result as ruby -wc
https://bugs.ruby-lang.org/issues/14938#change-73153

* Author: mtsmfm (Fumiaki Matsushima)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
I'm the author of an implementation of Ruby Language Server.
Currently, it uses `RubyVM::InstructionSequence.compile` to get the result of `ruby -wc` and parses message and location by regexp.

https://github.com/mtsmfm/language_server-ruby/blob/v0.11.0/lib/language_server/linter/ruby_wc.rb#L30

Do you have any plan to provide API?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>