mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
CyclomaticCompexity: report onle def name
This commit is contained in:
parent
54706192d2
commit
b868d88a85
2 changed files with 14 additions and 4 deletions
|
@ -33,8 +33,8 @@ module Ameba::Rule::Metrics
|
|||
|
||||
issue = source.issues.first
|
||||
issue.rule.should eq subject
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.end_location.to_s.should eq "source.cr:12:3"
|
||||
issue.location.to_s.should eq "source.cr:1:5"
|
||||
issue.end_location.to_s.should eq "source.cr:1:10"
|
||||
issue.message.should eq "Cyclomatic complexity too high [8/5]"
|
||||
end
|
||||
|
||||
|
|
|
@ -24,9 +24,19 @@ module Ameba::Rule::Metrics
|
|||
def test(source, node : Crystal::Def)
|
||||
complexity = AST::CountingVisitor.new(node).count
|
||||
|
||||
if complexity > max_complexity
|
||||
issue_for(node, MSG % {complexity, max_complexity})
|
||||
if complexity > max_complexity && (location = node.name_location)
|
||||
issue_for(
|
||||
location,
|
||||
def_name_end_location(node),
|
||||
MSG % {complexity, max_complexity}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
private def def_name_end_location(node)
|
||||
return unless location = node.name_location
|
||||
line_number, column_number = location.line_number, location.column_number
|
||||
Crystal::Location.new(location.filename, line_number, column_number + node.name.size)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue