Sha256: 15c9439d65cf99cd49319adbbf77f67a43b7776c3b9a5396e8528a5520ff00c4

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module SlimLint
  # Checks for uses of the `div` tag where a class name or ID shortcut was used.
  class Linter::RedundantDiv < Linter
    include LinterRegistry

    SHORTCUT_ATTRS = %w[id class]
    IMPLICIT_MESSAGE = "`div` is redundant when %s attribute shortcut is present"
    EXPLICIT_MESSAGE = "Use an explicit `div` rather than a standalone %s attribute shortcut"

    on [:html, :tag, anything, capture(:attrs, [:html, :attrs]), anything] do |sexp|
      _, _, name, value = captures[:attrs][2]
      next unless name
      next unless value[0] == :static
      next unless SHORTCUT_ATTRS.include?(name.value)

      case config["style"]
      when "implicit", "never", false, nil
        report_lint(sexp[2], IMPLICIT_MESSAGE % name) if sexp[2].value == "div"
      when "explicit", "always", true
        report_lint(sexp[2], EXPLICIT_MESSAGE % name) if sexp[2].value =~ /[#.]/
      else
        raise ArgumentError, "Unknown value for `style`; please use 'implicit' or 'explicit'"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
slim_lint_standard-0.0.2.2 lib/slim_lint/linter/redundant_div.rb