class RuboCop::Cop::Style::DisableCopsWithinSourceCodeDirective


# rubocop:enable Metrics/AbcSize
end
def foo
# rubocop:disable Metrics/AbcSize
# good
@example AllowedCops: [Metrics/AbcSize]
end
def foo
# good
# rubocop:enable Metrics/AbcSize
end
def foo
# rubocop:disable Metrics/AbcSize
# bad
@example
if this configuration is set, ‘rubocop:disable all` is still disallowed.
Specific cops can be allowed with the `AllowedCops` configuration. Note that
and not quickly disabled with a comment.
This is useful if want to make sure that every RuboCop error gets fixed
Detects comments to enable/disable RuboCop.

def allowed_cops

def allowed_cops
  Array(cop_config['AllowedCops'])
end

def any_cops_allowed?

def any_cops_allowed?
  allowed_cops.any?
end

def directive_cops(comment)

def directive_cops(comment)
  match_captures = DirectiveComment.new(comment).match_captures
  match_captures && match_captures[1] ? match_captures[1].split(',').map(&:strip) : []
end

def on_new_investigation

def on_new_investigation
  processed_source.comments.each do |comment|
    directive_cops = directive_cops(comment)
    disallowed_cops = directive_cops - allowed_cops
    next unless disallowed_cops.any?
    register_offense(comment, directive_cops, disallowed_cops)
  end
end

def register_offense(comment, directive_cops, disallowed_cops)

def register_offense(comment, directive_cops, disallowed_cops)
  message = if any_cops_allowed?
              format(MSG_FOR_COPS, cops: "`#{disallowed_cops.join('`, `')}`")
            else
              MSG
            end
  add_offense(comment, message: message) do |corrector|
    replacement = ''
    if directive_cops.length != disallowed_cops.length
      replacement = comment.text.sub(/#{Regexp.union(disallowed_cops)},?\s*/, '')
                           .sub(/,\s*$/, '')
    end
    corrector.replace(comment, replacement)
  end
end