module Ameba::InlineComments


A module that utilizes inline comments parsing and processing logic.

Direct including types

Defined in:


Constant Summary

COMMENT_DIRECTIVE_REGEX = /# ameba:(?<action>\w+) (?<rules>\w+(?:\/\w+)?(?:,? \w+(?:\/\w+)?)*)/

Instance Method Summary

Instance Method Detail

def comment?(line_number : Int32) #

Returns true if the line at the given line_number is a comment.

[View source]
def location_disabled?(location : Crystal::Location?, rule) #

Returns true if current location is disabled for a particular rule, false otherwise.

Location is disabled in two cases:

  1. The line of the location ends with a comment directive.
  2. 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) # ameba:disable Style/LargeNumbers

But here are examples which are not considered as disabled location:

# ameba:disable Style/LargeNumbers

if use_epoch? # ameba:disable Style/LargeNumbers

[View source]
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

[View source]