Sha256: 5fdd92fe447992fa236422578f8af8d3c5d209a2f9b93f199e7bbc9d8665dfb2
Contents?: true
Size: 1.13 KB
Versions: 10
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true module ERBLint module Linters # Warns when a tag is not self-closed properly. class SelfClosingTagCustom < Linter include LinterRegistry SELF_CLOSING_TAGS = %w( area input param track img ) def run(processed_source) processed_source.ast.descendants(:tag).each do |tag_node| tag = BetterHtml::Tree::Tag.from_node(tag_node) next unless SELF_CLOSING_TAGS.include?(tag.name) if tag.closing? start_solidus = tag_node.children.first add_offense( start_solidus.loc, "Tag `#{tag.name}` is self-closing, it must not start with `</`.", '' ) end next if tag.self_closing? add_offense( tag_node.loc.end.offset(-1), "Tag `#{tag.name}` is self-closing, it must end with `/>`.", '/' ) end end def autocorrect(_processed_source, offense) lambda do |corrector| corrector.replace(offense.source_range, offense.context) end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems