Add test for top level method def
This commit is contained in:
parent
7dfe09ccae
commit
6dad9d8b44
@ -232,6 +232,7 @@ module RuboCop
|
|||||||
@offense_source_range = def_node.source_range
|
@offense_source_range = def_node.source_range
|
||||||
return def_node
|
return def_node
|
||||||
end
|
end
|
||||||
|
return if node.parent.nil?
|
||||||
# If not found then, parent node becomes the offensive node
|
# If not found then, parent node becomes the offensive node
|
||||||
@offensive_node = node.parent
|
@offensive_node = node.parent
|
||||||
@offense_source_range = node.parent.source_range
|
@offense_source_range = node.parent.source_range
|
||||||
|
|||||||
@ -271,9 +271,9 @@ module RuboCop
|
|||||||
problem "Use the `#{match}` Ruby method instead of `#{m.source}`"
|
problem "Use the `#{match}` Ruby method instead of `#{m.source}`"
|
||||||
end
|
end
|
||||||
|
|
||||||
# if find_method_def(@processed_source.ast)
|
if find_method_def(@processed_source.ast)
|
||||||
# problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
|
problem "Define method #{method_name(@offensive_node)} in the class body, not at the top-level"
|
||||||
# end
|
end
|
||||||
#
|
#
|
||||||
# find_instance_method_call(body_node, :build, :without?) do |m|
|
# find_instance_method_call(body_node, :build, :without?) do |m|
|
||||||
# next unless unless_modifier?(m.parent)
|
# next unless unless_modifier?(m.parent)
|
||||||
|
|||||||
@ -592,6 +592,29 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|||||||
|
|
||||||
inspect_source(cop, source)
|
inspect_source(cop, source)
|
||||||
|
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
it "with a top-level function def " do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
def test
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
class Foo < Formula
|
||||||
|
desc "foo"
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
expected_offenses = [{ message: "Define method test in the class body, not at the top-level",
|
||||||
|
severity: :convention,
|
||||||
|
line: 1,
|
||||||
|
column: 0,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(cop, source)
|
||||||
|
|
||||||
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
expect_offense(expected, actual)
|
expect_offense(expected, actual)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user