Class: Mdlint::Linter::Rules::NoHardTabs

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, inherited, #initialize

Constructor Details

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

Instance Method Details

#check(_tokens, source) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mdlint/linter/rules/source_style.rb', line 47

def check(_tokens, source)
  in_fence = false
  source.each_line.with_index(1) do |line, line_number|
    in_fence = !in_fence if line.match?(FENCE_REGEXP)
    next if in_fence && @options.fetch(:ignore_code_blocks, false)
    next unless line.include?("\t")

    add_violation(message: "Hard tab character", line: line_number, column: line.index("\t").to_i + 1, fixable: true)
  end
  @violations
end

#fix(_tokens, source) ⇒ Object



59
60
61
# File 'lib/mdlint/linter/rules/source_style.rb', line 59

def fix(_tokens, source)
  source.each_line.map { |line| line.gsub("\t", "  ") }.join
end