class HamlLint::Directive

Handles linter configuration transformation via Haml comments.

Constants

DIRECTIVE_REGEXP
LINTER_REGEXP

Attributes

linters[R]

The names of the linters to act upon.

@return [String]

mode[R]

The mode of the directive. One of “disable” or “enable”.

@return [String]

Public Class Methods

from_line(source, line) click to toggle source

Constructs a directive from source code as a given line.

@param source [String] the source code to analyze @param line [Integer] the line number the source starts at @return [HamlLint::Directive]

# File lib/haml_lint/directive.rb, line 23
def self.from_line(source, line)
  match = DIRECTIVE_REGEXP.match(source)

  if match
    new(source, line, match[:mode], match[:linters].split(/\s*,\s*/))
  else
    Null.new(source, line)
  end
end
new(source, line, mode, linters) click to toggle source

Instantiates a new {HamlLint::Directive}

@api semipublic @param source [String] the source code to analyze @param line [Integer] the line number the source starts at @param mode [String] the type of directive, one of “disable” or “enable” @param linters [Array<String>] the name of the linters to act upon

# File lib/haml_lint/directive.rb, line 40
def initialize(source, line, mode, linters)
  @source = source
  @line = line
  @mode = mode
  @linters = linters
end

Public Instance Methods

==(other) click to toggle source

Checks whether a directive is equivalent to another.

@api public @param other [HamlLint::Directive] the other directive @return [true, false]

Calls superclass method
# File lib/haml_lint/directive.rb, line 62
def ==(other)
  super unless other.is_a?(HamlLint::Directive)

  mode == other.mode && linters == other.linters
end
disable?() click to toggle source

Checks whether this is a disable directive.

@return [true, false]

# File lib/haml_lint/directive.rb, line 71
def disable?
  mode == 'disable'
end
enable?() click to toggle source

Checks whether this is an enable directive.

@return [true, false]

# File lib/haml_lint/directive.rb, line 78
def enable?
  mode == 'enable'
end
inspect() click to toggle source

Formats the directive for display in a console.

@return [String]

# File lib/haml_lint/directive.rb, line 85
def inspect
  "#<HamlLint::Directive(mode=#{mode}, linters=#{linters})>"
end