Sha256: c33ec55e9da4da48cf6edf5b026be7238a0dede64e00b2b98798b3276d093cb5

Contents?: true

Size: 1.38 KB

Versions: 229

Compression:

Stored size: 1.38 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|
              corrector.replace(comment, comment.text.gsub(%r{ # rubocop:(disable|todo)}, ','))
            end
          end
        end
      end
    end
  end
end

Version data entries

229 entries across 220 versions & 22 rubygems

Version Path
rubocop-1.74.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.73.2 lib/rubocop/cop/style/double_cop_disable_directive.rb
siteimprove_api_client-1.0.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.73.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.73.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.73.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.72.2 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.72.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.72.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.71.2 lib/rubocop/cop/style/double_cop_disable_directive.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/rubocop-1.71.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.71.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.71.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.70.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.69.2 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.69.1 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.69.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.68.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.67.0 lib/rubocop/cop/style/double_cop_disable_directive.rb
rubocop-1.66.1 lib/rubocop/cop/style/double_cop_disable_directive.rb