Sha256: 750bb4b8935c12fa8fb4b8726924667d2bdd5b12e9426c47385bfabf3b092a81

Contents?: true

Size: 1.04 KB

Versions: 14

Compression:

Stored size: 1.04 KB

Contents

# encoding: utf-8
# 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

14 entries across 14 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.43.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.42.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.41.2 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.41.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.41.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.40.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.39.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.38.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.37.2 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.37.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.37.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.36.0 lib/rubocop/cop/mixin/parser_diagnostic.rb