Class: Mdlint::Linter::Rules::NoMultipleSpacesAfterHash

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



88
89
90
91
92
93
94
95
# File 'lib/mdlint/linter/rules/source_style.rb', line 88

def check(_tokens, source)
  source.each_line.with_index(1) do |line, line_number|
    next unless line.chomp.match?(/\A {0,3}#+ {2,}\S/)

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

#fix(_tokens, source) ⇒ Object



97
98
99
# File 'lib/mdlint/linter/rules/source_style.rb', line 97

def fix(_tokens, source)
  source.each_line.map { |line| line.sub(/\A( {0,3}#+) {2,}/, '\\1 ') }.join
end