Sha256: 7939af8b263d064c65e6711914e35bff43fab6e968f443fba772dd9603201c9f

Contents?: true

Size: 1.02 KB

Versions: 18

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for cops which processes Parser's diagnostics.
    # This mixin requires its user class to define `#relevant_diagnostic?`.
    #
    #     def relevant_diagnostic?(diagnostic)
    #       diagnostic.reason == :my_interested_diagnostic_type
    #     end
    #
    # If you want to use an alternative offense message rather than the one in
    # Parser's diagnostic, define `#alternative_message`.
    #
    #     def alternative_message(diagnostic)
    #       'My custom message'
    #     end
    module ParserDiagnostic
      def investigate(processed_source)
        processed_source.diagnostics.each do |d|
          next unless relevant_diagnostic?(d)

          message = if respond_to?(:alternative_message, true)
                      alternative_message(d)
                    else
                      d.message.capitalize
                    end

          add_offense(nil, d.location, message, d.level)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.50.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.49.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.49.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.48.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.48.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.47.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.47.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.46.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.45.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.44.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.44.0 lib/rubocop/cop/mixin/parser_diagnostic.rb