Ameba::Rule::Lint::TrailingRescueException
Inherits YAML::Serializable < Ameba::Rule::Base < Ameba::Config::RuleConfig < Reference < Object
A rule that prohibits the misconception about how trailing rescue statements work,
preventing Paths (exception class names or otherwise) from being used as the
trailing value. The value after the trailing rescue statement is the value
to use if an exception occurs, not the exception class to rescue from.
For example, this is considered invalid - if an exception occurs,
response will be assigned with the value of IO::Error instead of nil:
response = HTTP::Client.get("http://www.example.com") rescue IO::Error
And should instead be written as this in order to capture only IO::Error exceptions:
response = begin
HTTP::Client.get("http://www.example.com")
rescue IO::Error
"default value"
end
Or to rescue all exceptions (instead of just IO::Error):
response = HTTP::Client.get("http://www.example.com") rescue "default value"
YAML configuration example:
Lint/TrailingRescueException:
Enabled: true
Constants
Constructors
A rule that prohibits the misconception about how trailing rescue statements work,
preventing Paths (exception class names or otherwise) from being used as the
trailing value. The value after the trailing rescue statement is the value
to use if an exception occurs, not the exception class to rescue from.
For example, this is considered invalid - if an exception occurs,
response will be assigned with the value of IO::Error instead of nil:
response = HTTP::Client.get("http://www.example.com") rescue IO::Error
And should instead be written as this in order to capture only IO::Error exceptions:
response = begin
HTTP::Client.get("http://www.example.com")
rescue IO::Error
"default value"
end
Or to rescue all exceptions (instead of just IO::Error):
response = HTTP::Client.get("http://www.example.com") rescue "default value"
YAML configuration example:
Lint/TrailingRescueException:
Enabled: true
Class methods
Returns true if this rule is deprecated, false otherwise.
Returns the deprecation reason for this rule, if there is any.
Returns the documentation URL for this rule.
Ameba::Rule::Lint::Syntax.documentation_url
# => "https://crystal-ameba.org/api/master/Ameba/Rule/Lint/Syntax.html"
Returns the documentation for this rule, if there is any.
module Ameba
# This is a test rule.
# Does nothing.
class Rule::MyRule < Rule::Base
def test(source)
end
end
end
Ameba::Rule::MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."