Class: HamlLint::Directive
- Inherits:
-
Object
- Object
- HamlLint::Directive
- Defined in:
- lib/haml_lint/directive.rb
Overview
Handles linter configuration transformation via Haml comments.
Direct Known Subclasses
Defined Under Namespace
Classes: Null
Constant Summary collapse
- LINTER_REGEXP =
/(?:[A-Z]\w+)/
- DIRECTIVE_REGEXP =
/ # "haml-lint:" with optional spacing \s*haml-lint\s*:\s* # The mode - either disable or enable (?<mode>(?:dis|en)able)\b\s* # "all" or a comma-separated list (with optional spaces) of linters (?<linters>all | (?:#{LINTER_REGEXP}\s*,\s*)* #{LINTER_REGEXP}) /x
Instance Attribute Summary collapse
-
#linters ⇒ String
readonly
The names of the linters to act upon.
-
#mode ⇒ String
readonly
The mode of the directive.
Class Method Summary collapse
-
.from_line(source, line) ⇒ HamlLint::Directive
Constructs a directive from source code as a given line.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
Checks whether a directive is equivalent to another.
-
#disable? ⇒ true, false
Checks whether this is a disable directive.
-
#enable? ⇒ true, false
Checks whether this is an enable directive.
-
#initialize(source, line, mode, linters) ⇒ Directive
constructor
Instantiates a new Directive.
-
#inspect ⇒ String
Formats the directive for display in a console.
Constructor Details
#initialize(source, line, mode, linters) ⇒ Directive
Instantiates a new HamlLint::Directive
41 42 43 44 45 46 |
# File 'lib/haml_lint/directive.rb', line 41 def initialize(source, line, mode, linters) @source = source @line = line @mode = mode @linters = linters end |
Instance Attribute Details
#linters ⇒ String (readonly)
The names of the linters to act upon.
51 52 53 |
# File 'lib/haml_lint/directive.rb', line 51 def linters @linters end |
#mode ⇒ String (readonly)
The mode of the directive. One of “disable” or “enable”.
56 57 58 |
# File 'lib/haml_lint/directive.rb', line 56 def mode @mode end |
Class Method Details
.from_line(source, line) ⇒ HamlLint::Directive
Constructs a directive from source code as a given line.
24 25 26 27 28 29 30 31 32 |
# File 'lib/haml_lint/directive.rb', line 24 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 |
Instance Method Details
#==(other) ⇒ true, false
Checks whether a directive is equivalent to another.
63 64 65 66 67 |
# File 'lib/haml_lint/directive.rb', line 63 def ==(other) super unless other.is_a?(HamlLint::Directive) mode == other.mode && linters == other.linters end |
#disable? ⇒ true, false
Checks whether this is a disable directive.
72 73 74 |
# File 'lib/haml_lint/directive.rb', line 72 def disable? mode == 'disable' end |
#enable? ⇒ true, false
Checks whether this is an enable directive.
79 80 81 |
# File 'lib/haml_lint/directive.rb', line 79 def enable? mode == 'enable' end |
#inspect ⇒ String
Formats the directive for display in a console.
86 87 88 |
# File 'lib/haml_lint/directive.rb', line 86 def inspect "#<HamlLint::Directive(mode=#{mode}, linters=#{linters})>" end |