Sha256: 7e812db23fc6cfeeffb758c56aaed0cfea47b5e33655ebba33e300526f6eae1e

Contents?: true

Size: 1.5 KB

Versions: 26

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for missing documentation comment for public methods.
      # It can optionally be configured to also require documentation for
      # non-public methods.
      #
      # @example
      #
      #   # bad
      #
      #   class Foo
      #     def bar
      #       puts baz
      #     end
      #   end
      #
      #   module Foo
      #     def bar
      #       puts baz
      #     end
      #   end
      #
      #   def foo.bar
      #     puts baz
      #   end
      #
      #   # good
      #
      #   class Foo
      #     # Documentation
      #     def bar
      #       puts baz
      #     end
      #   end
      #
      #   module Foo
      #     # Documentation
      #     def bar
      #       puts baz
      #     end
      #   end
      #
      #   # Documentation
      #   def foo.bar
      #     puts baz
      #   end
      class DocumentationMethod < Cop
        include DocumentationComment
        include DefNode

        MSG = 'Missing method documentation comment.'.freeze

        def on_def(node)
          check(node)
        end
        alias on_defs on_def

        private

        def check(node)
          return if non_public?(node) && !require_for_non_public_methods?
          return if documentation_comment?(node)

          add_offense(node)
        end

        def require_for_non_public_methods?
          cop_config['RequireForNonPublicMethods']
        end
      end
    end
  end
end

Version data entries

26 entries across 24 versions & 3 rubygems

Version Path
rubocop-0.62.0 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.61.1 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.61.0 lib/rubocop/cop/style/documentation_method.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/documentation_method.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/documentation_method.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/documentation_method.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/documentation_method.rb
rubocop-0.60.0 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.59.2 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.59.1 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.59.0 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.58.2 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.58.1 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.58.0 lib/rubocop/cop/style/documentation_method.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/documentation_method.rb
rubocop-0.57.2 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.57.1 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.57.0 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.56.0 lib/rubocop/cop/style/documentation_method.rb
rubocop-0.55.0 lib/rubocop/cop/style/documentation_method.rb