<commit_before>module Rubocop
  module Cop
    class EmptyLines < Cop
      ERROR_MESSAGE = 'Use empty lines between defs.'

      def inspect(file, source, tokens, sexp)
        each_parent_of(:def, sexp) do |parent|
          # The first def doesn't need to have an empty line above it,
          # so we iterate starting at index 1.
          parent[1..-1].each { |child|
            if child[0] == :def
              # The method name is a leaf in the sexp parse tree so it
              # will have a position.
              # Example: child[1] == [:@ident, "my_method", [3, 6]]
              name_pos = child[1][-1]
              # Any errors will be reported on the lines containing
              # the method name. Normally the def keyword will be on
              # the same line.
              line_index = name_pos[0] - 1
              (line_index - 1).downto(0).each { |ix|
                case source[ix]
                when /^#/
                  nil  # Continue searching backwards
                when /^[ \t]*$/
                  break # Empty line found, so we're ok.
                else
                  add_offence(:convention, line_index, source[line_index],
                              ERROR_MESSAGE)
                  break
                end
              }
            end
          }
        end
      end
    end
  end<commit_msg>Added public/protected/private as things that don't need an empty line.<commit_after>module Rubocop
  module Cop
    class EmptyLines < Cop
      ERROR_MESSAGE = 'Use empty lines between defs.'

      def inspect(file, source, tokens, sexp)
        each_parent_of(:def, sexp) do |parent|
          # The first def doesn't need to have an empty line above it,
          # so we iterate starting at index 1.
          parent[1..-1].each { |child|
            if child[0] == :def
              # The method name is a leaf in the sexp parse tree so it
              # will have a position.
              # Example: child[1] == [:@ident, "my_method", [3, 6]]
              name_pos = child[1][-1]
              # Any errors will be reported on the lines containing
              # the method name. Normally the def keyword will be on
              # the same line.
              line_index = name_pos[0] - 1
              (line_index - 1).downto(0).each { |ix|
                case source[ix]
                when /^[ \t]*(#|private\b|public\b|protected\b)/
                  nil  # Continue searching backwards
                when /^[ \t]*$/
                  break # Empty line found, so we're ok.
                else
                  add_offence(:convention, line_index, source[line_index],
                              ERROR_MESSAGE)
                  break
                end
              }
            end
          }
        end
      end
    end
  end
{'fraction_non_alphanumeric': 0.08501594048884166, 'fraction_numerical': 0.009210060219624512, 'mean_word_length': 1.303425774877651, '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': '1759010', 'n_tokens_mistral': 783, 'n_tokens_neox': 730, 'n_words': 263}