Sha256: ff9cac1968f719752b58189245bc1b4b4ef87ba6cbacb249a7fb123e762e54c9

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Enforces that Ruby source files are not empty.
      #
      # @example
      #   # bad
      #   # Empty file
      #
      #   # good
      #   # File containing non commented source lines
      #
      # @example AllowComments: true (default)
      #   # good
      #   # File consisting only of comments
      #
      # @example AllowComments: false
      #   # bad
      #   # File consisting only of comments
      #
      class EmptyFile < Base
        MSG = 'Empty file detected.'

        def on_new_investigation
          add_global_offense(MSG) if offending?
        end

        private

        def offending?
          empty_file? || (!cop_config['AllowComments'] && contains_only_comments?)
        end

        def empty_file?
          processed_source.buffer.source.empty?
        end

        def contains_only_comments?
          processed_source.lines.all? { |line| line.blank? || comment_line?(line) }
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/cop/lint/empty_file.rb
rubocop-1.69.2 lib/rubocop/cop/lint/empty_file.rb
rubocop-1.69.1 lib/rubocop/cop/lint/empty_file.rb
rubocop-1.69.0 lib/rubocop/cop/lint/empty_file.rb