<commit_before>module SCSSLint
  class Linter::HexFormat < Linter
    include LinterRegistry

    def visit_prop(node)
      if node.value.is_a?(Sass::Script::String) &&
         node.value.type == :identifier

        node.value.value.scan(HEX_REGEX) do |match|
          add_hex_lint(node, match.first) unless valid_hex_format?(match.first)
        end
      end

      yield # Continue visiting children
    end

    def visit_script_color(node)
      return unless node.original && node.original.match(HEX_REGEX)

      unless valid_hex_format?(node.original[HEX_REGEX, 1])
        add_hex_lint(node, node.original)
      end
    end

  private

    HEX_REGEX = /(#\h{3,6})/

    def add_hex_lint(node, hex)
      add_lint(node, "Color `#{hex}` should be written as `#{shortest_hex_form(hex)}`")
    end

    def valid_hex_format?(hex)
      hex == shortest_hex_form(hex)
    end
  end
end<commit_msg>Simplify HexFormat linter string searching<commit_after>module SCSSLint
  class Linter::HexFormat < Linter
    include LinterRegistry

    def visit_script_color(node)
      return unless node.original && node.original.match(HEX_REGEX)

      unless valid_hex_format?(node.original[HEX_REGEX, 1])
        add_hex_lint(node, node.original)
      end
    end

    def visit_script_string(node)
      return unless node.type == :identifier

      node.value.scan(HEX_REGEX) do |match|
        add_hex_lint(node, match.first) unless valid_hex_format?(match.first)
      end
    end

  private

    HEX_REGEX = /(#\h{3,6})/

    def add_hex_lint(node, hex)
      add_lint(node, "Color `#{hex}` should be written as `#{shortest_hex_form(hex)}`")
    end

    def valid_hex_format?(hex)
      hex == shortest_hex_form(hex)
    end
  end
end
{'fraction_non_alphanumeric': 0.10356731875719218, 'fraction_numerical': 0.0034522439585730723, 'mean_word_length': 3.0630841121495327, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '228196', 'n_tokens_mistral': 603, 'n_tokens_neox': 588, 'n_words': 122}