Merge pull request #4044 from GauthamGoli/urls_cop_bug
urls_cop: Search for func calls to match `url` and `mirror` calls
This commit is contained in:
commit
64ae942bab
@ -99,6 +99,17 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns array of function call nodes matching func_name in every descendant of node
|
||||||
|
# Ex. function call: foo(*args, **kwargs)
|
||||||
|
# Does not match method calls: foo.bar(*args, **kwargs)
|
||||||
|
# Returns every function calls if no func_name is passed
|
||||||
|
def find_every_func_call_by_name(node, func_name = nil)
|
||||||
|
return if node.nil?
|
||||||
|
node.each_descendant(:send).select do |func_node|
|
||||||
|
func_node.receiver.nil? && (func_name.nil? || func_name == func_node.method_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Given a method_name and arguments, yields to a block with
|
# Given a method_name and arguments, yields to a block with
|
||||||
# matching method passed as a parameter to the block
|
# matching method passed as a parameter to the block
|
||||||
def find_method_with_args(node, method_name, *args)
|
def find_method_with_args(node, method_name, *args)
|
||||||
|
|||||||
@ -6,8 +6,8 @@ module RuboCop
|
|||||||
# This cop audits urls and mirrors in Formulae
|
# This cop audits urls and mirrors in Formulae
|
||||||
class Urls < FormulaCop
|
class Urls < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
urls = find_every_method_call_by_name(body_node, :url)
|
urls = find_every_func_call_by_name(body_node, :url)
|
||||||
mirrors = find_every_method_call_by_name(body_node, :mirror)
|
mirrors = find_every_func_call_by_name(body_node, :mirror)
|
||||||
|
|
||||||
# GNU urls; doesn't apply to mirrors
|
# GNU urls; doesn't apply to mirrors
|
||||||
gnu_pattern = %r{^(?:https?|ftp)://ftpmirror.gnu.org/(.*)}
|
gnu_pattern = %r{^(?:https?|ftp)://ftpmirror.gnu.org/(.*)}
|
||||||
@ -195,8 +195,8 @@ module RuboCop
|
|||||||
module FormulaAuditStrict
|
module FormulaAuditStrict
|
||||||
class PyPiUrls < FormulaCop
|
class PyPiUrls < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
urls = find_every_method_call_by_name(body_node, :url)
|
urls = find_every_func_call_by_name(body_node, :url)
|
||||||
mirrors = find_every_method_call_by_name(body_node, :mirror)
|
mirrors = find_every_func_call_by_name(body_node, :mirror)
|
||||||
urls += mirrors
|
urls += mirrors
|
||||||
|
|
||||||
# Check pypi urls
|
# Check pypi urls
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user