Sha256: 60b35a93bc0b5380f1ba3be3ebef2e9981f7d32dbd012d3cbf1c75bf4016b4f0

Contents?: true

Size: 1.57 KB

Versions: 48

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

# rubocop:disable Lint/RedundantCopDisableDirective
# rubocop:disable Style/DoubleCopDisableDirective

module RuboCop
  module Cop
    module Style
      # Detects double disable comments on one line. This is mostly to catch
      # automatically generated comments that need to be regenerated.
      #
      # @example
      #   # bad
      #   def f # rubocop:disable Style/For # rubocop:disable Metrics/AbcSize
      #   end
      #
      #   # good
      #   # rubocop:disable Metrics/AbcSize
      #   def f # rubocop:disable Style/For
      #   end
      #   # rubocop:enable Metrics/AbcSize
      #
      #   # if both fit on one line
      #   def f # rubocop:disable Style/For, Metrics/AbcSize
      #   end
      #
      class DoubleCopDisableDirective < Base
        extend AutoCorrector

        # rubocop:enable Style/For, Style/DoubleCopDisableDirective
        # rubocop:enable Lint/RedundantCopDisableDirective, Metrics/AbcSize
        MSG = 'More than one disable comment on one line.'

        def on_new_investigation
          processed_source.comments.each do |comment|
            next unless comment.text.scan(/# rubocop:(?:disable|todo)/).size > 1

            add_offense(comment) do |corrector|
              prefix = if comment.text.start_with?('# rubocop:disable')
                         '# rubocop:disable'
                       else
                         '# rubocop:todo'
                       end

              corrector.replace(comment, comment.text[/#{prefix} \S+/])
            end
          end
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 5 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.18.3 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.18.2 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.18.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.18.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.17.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.16.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.16.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.15.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
cocRb-0.1.0 .bundle/ruby/3.0.0/gems/rubocop-1.14.0/lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.14.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.13.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.12.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.12.0 lib/rubocop/cop/style/double_cop_disable_directive.rb