Sha256: 75d226cb89012c3169e5a9bc49dd985a3b8baa03fac87ada8d9aa49f1b84af22

Contents?: true

Size: 1.23 KB

Versions: 8

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

# rubocop:disable Lint/RedundantCopDisableDirective

module RuboCop
  module Cop
    module Style
      # Detects comments to enable/disable RuboCop.
      # This is useful if want to make sure that every RuboCop error gets fixed
      # and not quickly disabled with a comment.
      #
      # @example
      #   # bad
      #   # rubocop:disable Metrics/AbcSize
      #   def f
      #   end
      #   # rubocop:enable Metrics/AbcSize
      #
      #   # good
      #   def fixed_method_name_and_no_rubocop_comments
      #   end
      #
      class DisableCopsWithinSourceCodeDirective < Cop
        # rubocop:enable Lint/RedundantCopDisableDirective
        MSG = 'Comment to disable/enable RuboCop.'

        def investigate(processed_source)
          processed_source.comments.each do |comment|
            next unless rubocop_directive_comment?(comment)

            add_offense(comment)
          end
        end

        def autocorrect(comment)
          lambda do |corrector|
            corrector.replace(comment, '')
          end
        end

        private

        def rubocop_directive_comment?(comment)
          comment.text =~ CommentConfig::COMMENT_DIRECTIVE_REGEXP
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-0.85.1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-0.85.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-0.84.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-0.83.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-0.82.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb