Class: Mdlint::Linter::Rules::ListMarkerSpace

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

Instance Attribute Summary

Attributes inherited from Mdlint::Linter::Rule

#violations

Instance Method Summary collapse

Methods inherited from Mdlint::Linter::Rule

#add_violation, inherited, #initialize

Constructor Details

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

Instance Method Details

#check(_tokens, source) ⇒ Object



126
127
128
129
130
131
132
133
134
# File 'lib/mdlint/linter/rules/source_style.rb', line 126

def check(_tokens, source)
  source.each_line.with_index(1) do |line, line_number|
    match = line.chomp.match(/\A( {0,3}(?:[-+*]|\d+[.)]))([ \t]+)(\S)/)
    next unless match && match[2] != " "

    add_violation(message: "Use one space after a list marker", line: line_number, fixable: true)
  end
  @violations
end

#fix(_tokens, source) ⇒ Object



136
137
138
# File 'lib/mdlint/linter/rules/source_style.rb', line 136

def fix(_tokens, source)
  source.each_line.map { |line| line.sub(/\A( {0,3}(?:[-+*]|\d+[.)]))[ \t]+/, '\\1 ') }.join
end