<commit_before># frozen_string_literal: true

module RSpectre
  class SourceMap
    include Concord.new(:map)

    def initialize
      super(Hash.new { [] })
    end
    private_class_method :new

    def self.parse(file)
      self::Parser.new(file).populate(new)
    end

    def add(node)
      return unless node.loc.expression

      map[node.loc.first_line] <<= node
    end

    def find_method(target_selector, line)
      block_nodes(line).select do |node|
        send, = *node
        _receiver, selector = *send

        selector.equal?(target_selector)
      end.first
    end

    private

    def block_nodes(line)
      map.fetch(line, []).select { |node| node.type.equal?(:block) }
    end

    class Null < self
      public_class_method :new

      def find_let(_)
      end
    end
  end
end<commit_msg>Revert "Reduce warning noise (#19)" (#39)<commit_after># frozen_string_literal: true

module RSpectre
  class SourceMap
    include Concord.new(:map)

    def initialize
      super(Hash.new { [] })
    end
    private_class_method :new

    def self.parse(file)
      self::Parser.new(file).populate(new)
    end

    def add(node)
      return unless node.loc.expression

      map[node.loc.first_line] <<= node
    end

    def find_method(target_selector, line)
      candidates = find_methods(target_selector, line)

      if candidates.one?
        candidates.first
      else
        warn Color.yellow("Unable to resolve `#{target_selector}` on line #{line}.")
      end
    end

    private

    def find_methods(target_selector, line)
      block_nodes(line).select do |node|
        send, = *node
        _receiver, selector = *send

        selector.equal?(target_selector)
      end
    end

    def block_nodes(line)
      map.fetch(line, []).select { |node| node.type.equal?(:block) }
    end

    class Null < self
      public_class_method :new

      def find_let(_)
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09974160206718347, 'fraction_numerical': 0.0020671834625322996, 'mean_word_length': 2.420494699646643, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6784309', 'n_tokens_mistral': 629, 'n_tokens_neox': 602, 'n_words': 144}