class ERBLint::Linters::SpaceIndentation

Detects indentation with tabs and autocorrect them to spaces

Constants

START_SPACES

Public Instance Methods

autocorrect(_processed_source, offense) click to toggle source
# File lib/erb_lint/linters/space_indentation.rb, line 34
def autocorrect(_processed_source, offense)
  lambda do |corrector|
    corrector.replace(offense.source_range, offense.context)
  end
end
run(processed_source) click to toggle source
# File lib/erb_lint/linters/space_indentation.rb, line 16
def run(processed_source)
  lines = processed_source.file_content.split("\n", -1)
  document_pos = 0
  lines.each do |line|
    spaces = line.match(START_SPACES)&.captures&.first

    if spaces.include?("\t")
      add_offense(
        processed_source.to_source_range(document_pos...(document_pos + spaces.length)),
        "Indent with spaces instead of tabs.",
        spaces.gsub("\t", " " * @config.tab_width)
      )
    end

    document_pos += line.length + 1
  end
end