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 Lint
cops perf tweaks
#8358
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'set' | ||
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. No need to |
||
|
||
module RuboCop | ||
module Cop | ||
module Lint | ||
|
@@ -35,6 +37,11 @@ module Lint | |
class Debugger < Cop | ||
MSG = 'Remove debugger entry point `%<source>s`.' | ||
|
||
DEBUGGER_METHODS = %i[ | ||
debugger byebug remote_byebug pry remote_pry pry_remote console rescue | ||
save_and_open_page save_and_open_screenshot save_screenshot irb | ||
].to_set.freeze | ||
|
||
def_node_matcher :kernel?, <<~PATTERN | ||
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. I want to make a release of Should we also add |
||
{ | ||
(const nil? :Kernel) | ||
|
@@ -57,6 +64,7 @@ class Debugger < Cop | |
PATTERN | ||
|
||
def on_send(node) | ||
return unless DEBUGGER_METHODS.include?(node.method_name) | ||
return unless debugger_call?(node) || binding_irb?(node) | ||
|
||
add_offense(node) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'set' | ||
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. No need |
||
|
||
module RuboCop | ||
module Cop | ||
module Lint | ||
|
@@ -53,6 +55,9 @@ class DuplicateMethods < Cop | |
MSG = 'Method `%<method>s` is defined at both %<defined>s and ' \ | ||
'%<current>s.' | ||
|
||
METHOD_DEF_METHODS = %i[alias_method attr_reader attr_writer | ||
attr_accessor attr].to_set.freeze | ||
|
||
def initialize(config = nil, options = nil) | ||
super | ||
@definitions = {} | ||
|
@@ -97,7 +102,10 @@ def on_alias(node) | |
|
||
def_node_matcher :sym_name, '(sym $_name)' | ||
|
||
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity | ||
def on_send(node) | ||
return unless METHOD_DEF_METHODS.include?(node.method_name) | ||
|
||
if (name = alias_method?(node)) | ||
return unless 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 line is redundant. Apparently we don't have a cop for this 😅 |
||
return if node.ancestors.any?(&:if_type?) | ||
|
@@ -108,6 +116,7 @@ def on_send(node) | |
on_attr(node, *attr) | ||
end | ||
end | ||
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity | ||
|
||
private | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,10 @@ class InterpolationCheck < Cop | |
'Use double quoted strings if you need interpolation.' | ||
|
||
def on_str(node) | ||
return if heredoc?(node) | ||
|
||
parent = node.parent | ||
return if parent && (parent.dstr_type? || parent.regexp_type?) | ||
return unless /(?<!\\)#\{.*\}/.match?(node.source.scrub) | ||
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. AFAIK, |
||
return if heredoc?(node) | ||
|
||
add_offense(node) | ||
end | ||
|
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.
I was surprised to see that this line was still taking non-negligible time, so I investigated a bit and this led to a bunch of fixes and a bunch of optimizations in
rubocop-ast
🎉