class ERBLint::Linters::BaseLinter

def counter_correct?(processed_source)

def counter_correct?(processed_source)
  comment_node = nil
  expected_count = 0
  rule_name = self.class.name.match(/:?:?(\w+)\Z/)[1]
  processed_source.parser.ast.descendants(:erb).each do |node|
    indicator_node, _, code_node, = *node
    indicator = indicator_node&.loc&.source
    comment = code_node&.loc&.source&.strip
    if indicator == "#" && comment.start_with?("erblint:count") && comment.match(rule_name)
      comment_node = node
      expected_count = comment.match(/\s(\d+)\s?$/)[1].to_i
    end
  end
  # Unless explicitly set, we don't want to mark correctable offenses if the counter is correct.
  if !@config.override_ignores_if_correctable? && expected_count == @total_offenses
    clear_offenses
    return false
  end
  if @offenses_not_corrected.zero?
    # have to adjust to get `\n` so we delete the whole line
    add_offense(processed_source.to_source_range(comment_node.loc.adjust(end_pos: 1)), "Unused erblint:count comment for #{rule_name}", "") if comment_node
    return false
  end
  first_offense = @offenses[0]
  if comment_node.nil?
    add_offense(processed_source.to_source_range(first_offense.source_range), "#{rule_name}: If you must, add <%# erblint:counter #{rule_name} #{@offenses_not_corrected} %> to bypass this check.", "<%# erblint:counter #{rule_name} #{@offenses_not_corrected} %>")
  elsif expected_count != @offenses_not_corrected
    add_offense(processed_source.to_source_range(comment_node.loc), "Incorrect erblint:counter number for #{rule_name}. Expected: #{expected_count}, actual: #{@offenses_not_corrected}.", "<%# erblint:counter #{rule_name} #{@offenses_not_corrected} %>")
  # the only offenses remaining are not autocorrectable, so we can ignore them
  elsif expected_count == @offenses_not_corrected && @offenses.size == @offenses_not_corrected
    clear_offenses
  end
end