Class: Mdlint::Linter::Rules::ListBlankLines

Inherits:
Mdlint::Linter::Rule show all
Includes:
SourceStyleSupport
Defined in:
lib/mdlint/linter/rules/source_style.rb,
sig/internal.rbs

Constant Summary

Constants included from SourceStyleSupport

SourceStyleSupport::FENCE_REGEXP, SourceStyleSupport::LIST_MARKER_REGEXP

Instance Attribute Summary

Attributes inherited from Mdlint::Linter::Rule

#violations

Instance Method Summary collapse

Methods included from SourceStyleSupport

#fenced_lines, #inline_tokens, #line_is_blank?, #lines, #outside_fence?

Methods inherited from Mdlint::Linter::Rule

#add_violation, #fix, inherited, #initialize

Constructor Details

This class inherits a constructor from Mdlint::Linter::Rule

Instance Method Details

#check(_tokens, source) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/mdlint/linter/rules/source_style.rb', line 172

def check(_tokens, source)
  source_lines = lines(source)
  list_indexes = source_lines.each_index.select { |index| source_lines[index].match?(LIST_MARKER_REGEXP) }
  return @violations if list_indexes.empty?

  first = list_indexes.first
  last = list_indexes.last
  if first.positive? && !line_is_blank?(source_lines[first - 1])
    add_violation(message: "Add a blank line before the list", line: first + 1)
  end
  if last < source_lines.length - 1 && !line_is_blank?(source_lines[last + 1])
    add_violation(message: "Add a blank line after the list", line: last + 1)
  end
  @violations
end