New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Small Style
cops perf tweaks
#8359
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ class FormatString < Cop | |
|
||
MSG = 'Favor `%<prefer>s` over `%<current>s`.' | ||
|
||
FORMAT_METHODS = %i[format sprintf %].freeze | ||
|
||
def_node_matcher :formatter, <<~PATTERN | ||
{ | ||
(send nil? ${:sprintf :format} _ _ ...) | ||
|
@@ -53,6 +55,8 @@ class FormatString < Cop | |
PATTERN | ||
|
||
def on_send(node) | ||
return unless FORMAT_METHODS.include?(node.method_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pattern that comes back very often for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcandre I'd find that incredibly useful for many cops I write. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool :-) Please check #8365 and let me know how well that fits what you'd like. It could be made more general but I think that |
||
|
||
formatter(node) do |selector| | ||
detected_style = selector == :% ? :percent : selector | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but shouldn't it be
Node#access_modifier?
itself that should be sped up instead of just this cop? I think just changing the order of the conditions inrubocop-ast
should give you most of the speed up, but I may be wrong