Sha256: 19c1e71c5fd0f6baf1a8d6fa8ea94178467c9263ffaadcc59b834430f21e0e36

Contents?: true

Size: 1.2 KB

Versions: 30

Compression:

Stored size: 1.2 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 < Base
        extend AutoCorrector

        # rubocop:enable Lint/RedundantCopDisableDirective
        MSG = 'Comment to disable/enable RuboCop.'

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

            add_offense(comment) do |corrector|
              corrector.replace(comment, '')
            end
          end
        end

        private

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

Version data entries

30 entries across 30 versions & 3 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.8.1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.8.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.7.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.6.1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.6.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.5.2 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.5.1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.5.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.4.2 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.4.1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.4.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.3.1 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.3.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb
rubocop-1.2.0 lib/rubocop/cop/style/disable_cops_within_source_code_directive.rb