Sha256: ad3e551716f4ca8a28b98f3e055acbaec4623c34cbdcdf1c49521ff44755754d

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 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(find_offense_node_by(d),
                      location: d.location,
                      message: message,
                      severity: d.level)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 3 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.87.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.87.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.86.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/mixin/parser_diagnostic.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/mixin/parser_diagnostic.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.85.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.85.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.84.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.83.0 lib/rubocop/cop/mixin/parser_diagnostic.rb