2018-06-10 21:15:12 +00:00
|
|
|
module Ameba
|
|
|
|
# Represents a module used to report issues.
|
|
|
|
module Reportable
|
|
|
|
# List of reported issues.
|
|
|
|
getter issues = [] of Issue
|
|
|
|
|
|
|
|
# Adds a new issue to the list of issues.
|
|
|
|
def add_issue(rule, location, end_location, message, status = nil)
|
2018-06-23 13:52:48 +00:00
|
|
|
status ||= :disabled if location_disabled?(location, rule)
|
2018-06-10 21:15:12 +00:00
|
|
|
issues << Issue.new rule, location, end_location, message, status
|
|
|
|
end
|
|
|
|
|
|
|
|
# Adds a new issue for AST *node*.
|
2018-11-24 17:38:13 +00:00
|
|
|
def add_issue(rule, node : Crystal::ASTNode, message, **args)
|
2018-06-10 21:15:12 +00:00
|
|
|
add_issue rule, node.location, node.end_location, message, **args
|
|
|
|
end
|
|
|
|
|
|
|
|
# Adds a new issue for Crystal *token*.
|
2018-11-24 17:38:13 +00:00
|
|
|
def add_issue(rule, token : Crystal::Token, message, **args)
|
2018-06-10 21:15:12 +00:00
|
|
|
add_issue rule, token.location, nil, message, **args
|
|
|
|
end
|
|
|
|
|
|
|
|
# Adds a new issue for *location* defined by line and column numbers.
|
|
|
|
def add_issue(rule, location : Tuple(Int32, Int32), message, **args)
|
|
|
|
location = Crystal::Location.new path, *location
|
|
|
|
add_issue rule, location, nil, message, **args
|
|
|
|
end
|
|
|
|
|
2018-11-24 22:54:25 +00:00
|
|
|
# Adds a new issue for *location* and *end_location* defined by line and column numbers.
|
|
|
|
def add_issue(rule, location : Tuple(Int32, Int32), end_location : Tuple(Int32, Int32), message, **args)
|
|
|
|
location = Crystal::Location.new path, *location
|
|
|
|
end_location = Crystal::Location.new path, *end_location
|
|
|
|
add_issue rule, location, end_location, message, **args
|
|
|
|
end
|
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
# Returns true if the list of not disabled issues is empty, false otherwise.
|
|
|
|
def valid?
|
|
|
|
issues.reject(&.disabled?).empty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|