<commit_before>class PuppetLint::Plugins::CheckConditionals < PuppetLint::CheckPlugin
  # Public: Test the manifest tokens for any selectors embedded within resource
  # declarations and record a warning for each instance found.
  #
  # Returns nothing.
  check 'selector_inside_resource' do
    resource_indexes.each do |resource|
      resource_tokens = tokens[resource[:start]..resource[:end]].reject { |r|
        [:COMMENT, :MLCOMMENT, :WHITESPACE, :INDENT].include? r.type
      }

      resource_tokens.each_index do |resource_token_idx|
        if resource_tokens[resource_token_idx].type == :FARROW
          if resource_tokens[resource_token_idx + 1].type == :VARIABLE
            unless resource_tokens[resource_token_idx + 2].nil?
              if resource_tokens[resource_token_idx + 2].type == :QMARK
                notify :warning, {
                  :message    => 'selector inside resource block',
                  :linenumber => resource_tokens[resource_token_idx].line,
                  :column     => resource_tokens[resource_token_idx].column,
                }
              end
            end
          end
        end
      end
    end
  end

  check 'case_without_default' do
    case_indexes = []

    tokens.each_index do |token_idx|
      if tokens[token_idx].type == :CASE
        depth = 0
        tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
          idx = case_token_idx + token_idx + 1
          if tokens[idx].type == :LBRACE
            depth += 1
          elsif tokens[idx].type == :RBRACE
            depth -= 1
            if depth == 0
              case_indexes << {:start => token_idx, :end => idx}
              break
            end
          end
        end
      end
    end
<commit_msg>Document case_without_default check<commit_after>class PuppetLint::Plugins::CheckConditionals < PuppetLint::CheckPlugin
  # Public: Test the manifest tokens for any selectors embedded within resource
  # declarations and record a warning for each instance found.
  #
  # Returns nothing.
  check 'selector_inside_resource' do
    resource_indexes.each do |resource|
      resource_tokens = tokens[resource[:start]..resource[:end]].reject { |r|
        [:COMMENT, :MLCOMMENT, :WHITESPACE, :INDENT].include? r.type
      }

      resource_tokens.each_index do |resource_token_idx|
        if resource_tokens[resource_token_idx].type == :FARROW
          if resource_tokens[resource_token_idx + 1].type == :VARIABLE
            unless resource_tokens[resource_token_idx + 2].nil?
              if resource_tokens[resource_token_idx + 2].type == :QMARK
                notify :warning, {
                  :message    => 'selector inside resource block',
                  :linenumber => resource_tokens[resource_token_idx].line,
                  :column     => resource_tokens[resource_token_idx].column,
                }
              end
            end
          end
        end
      end
    end
  end

  # Public: Test the manifest tokens for any case statements that do not
  # contain a "default" case and record a warning for each instance found.
  #
  # Returns nothing.
  check 'case_without_default' do
    case_indexes = []

    tokens.each_index do |token_idx|
      if tokens[token_idx].type == :CASE
        depth = 0
        tokens[(token_idx + 1)..-1].each_index do |case_token_idx|
          idx = case_token_idx + token_idx + 1
          if tokens[idx].type == :LBRACE
            depth += 1
          elsif tokens[idx].type == :RBRACE
            depth -= 1
            if depth == 0
              case_indexes << {:start => token_idx, :end => idx}
              break
            end
          end
        end
      end
    end

{'fraction_non_alphanumeric': 0.08889489327208862, 'fraction_numerical': 0.0054039448797622265, 'mean_word_length': 2.0824313072439633, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3424919', 'n_tokens_mistral': 1070, 'n_tokens_neox': 1023, 'n_words': 264}