Add utility `rubocop-parse`
What does this MR do and why?
This MR adds a new utility rubocop-parse
to be used instead of ruby-parse
.
In certain situations ruby-parse
emits different AST than what RuboCop emits internally. This is because RuboCop maps nodes emitted by parser
gem which leads to differences like:
ruby-parse
ruby-parse -e 'with(foo: 1)'
(send nil :with
(kwargs
(pair
(sym :foo)
(int 1))))
rubocop-parse
scripts/rubocop-parse -e 'with(foo: 1)'
(send nil :with
(hash
(pair
(sym :foo)
(int 1))))
Note that kwargshash.
Examples
$ scripts/rubocop-parse -h
Usage: scripts/rubocop-parse [-e code] [FILE...]
-e, --eval FRAGEMENT Process a fragment of Ruby code
-v, --ruby-version RUBY_VERSION Parse as Ruby would. Defaults to RuboCop TargetRubyVersion setting.
-h, --help
scripts/rubocop-parse -e "puts hello"
(send nil :puts
(send nil :hello))
scripts/rubocop-parse -e "puts hello" -v 3.0
(send nil :puts
(send nil :hello))
scripts/rubocop-parse app/models/project.rb | head
(begin
(send nil :require
(str "carrierwave/orm/activerecord"))
(class
(const nil :Project)
(const nil :ApplicationRecord)
(begin
(send nil :include
(const
(const nil :Gitlab) :ConfigHelper))
...
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Peter Leitzen