Skip to content

Add interactive mode to scripts/rubocop-parse

Peter Leitzen requested to merge pl-rubocop-parse-interactive into master

What does this MR do and why?

The startup of scripts/rubocop-parse is slow due to RuboCop etc.

With the interactive mode you can do sessions like:

  $ scripts/rubocop-parse -i
  Ruby version: 2.7

  Use `ast(source_string, version: nil)` method to parse code and output AST. For example:
    ast('puts :hello')

  >> ast("puts 1 + 1")
  (send nil :puts
    (send
      (int 1) :+
      (int 1)))
  => nil
  >> ast(%{class Foo; end})
  (class
    (const nil :Foo) nil nil)
  => nil
  >>

Screenshots or screen recordings

$ scripts/rubocop-parse
Usage: scripts/rubocop-parse [-e code] [FILE...]
    -e, --eval FRAGMENT              Process a fragment of Ruby code
    -i, --interactive
    -v, --ruby-version RUBY_VERSION  Parse as Ruby would. Defaults to RuboCop TargetRubyVersion setting.
    -h, --help

$ scripts/rubocop-parse -e "puts 1"
(send nil :puts
  (int 1))

$ scripts/rubocop-parse app/models/error_tracking.rb
(module
  (const nil :ErrorTracking)
  (defs
    (self) :table_name_prefix
    (args)
    (str "error_tracking_")))

$ scripts/rubocop-parse -i
Ruby version: 2.7

Use `ast(source_string, version: nil)` method to parse code and output AST. For example:
  ast('puts :hello')

>> ast("1 + 2")
(send
  (int 1) :+
  (int 2))
=> nil
>> ast("class Foo; end")
(class
  (const nil :Foo) nil nil)
=> nil
>>
>>

How to set up and validate locally

See above.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports

Loading