module Ameba::InlineComments
Overview
A module that utilizes inline comments parsing and processing logic.
Direct including types
Defined in:
ameba/inline_comments.crConstant Summary
-
COMMENT_DIRECTIVE_REGEX =
/# ameba:(?<action>\w+) (?<rules>\w+(?:\/\w+)?(?:,? \w+(?:\/\w+)?)*)/
Instance Method Summary
-
#comment?(line_number : Int32)
Returns
true
if the line at the givenline_number
is a comment. -
#location_disabled?(location : Crystal::Location | Nil, rule)
Returns
true
if current location is disabled for a particular rule,false
otherwise. -
#parse_inline_directive(line)
Parses inline comment directive.
Instance Method Detail
def location_disabled?(location : Crystal::Location | Nil, rule)
#
Returns true
if current location is disabled for a particular rule,
false
otherwise.
Location is disabled in two cases:
- The line of the location ends with a comment directive.
- The line above the location is a comment directive.
For example, here are two examples of disabled location:
# ameba:disable Style/LargeNumbers
Time.epoch(1483859302)
Time.epoch(1483859302) # ameba:disable Style/LargeNumbers
But here are examples which are not considered as disabled location:
# ameba:disable Style/LargeNumbers
#
Time.epoch(1483859302)
if use_epoch? # ameba:disable Style/LargeNumbers
Time.epoch(1483859302)
end
def parse_inline_directive(line)
#
Parses inline comment directive. Returns a tuple that consists of an action and parsed rules if directive found, nil otherwise.
line = "# ameba:disable Rule1, Rule2"
directive = parse_inline_directive(line)
directive[:action] # => "disable"
directive[:rules] # => ["Rule1", "Rule2"]
It ignores the directive if it is commented out.
line = "# # ameba:disable Rule1, Rule2"
parse_inline_directive(line) # => nil