Sha256: a4476dcc5d6ccc3ab1951e2255b37544e7653ad1b26818634a8ce9b9296ea6c6

Contents?: true

Size: 1.01 KB

Versions: 24

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

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

24 entries across 24 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.35.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.35.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.34.2 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.34.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.34.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.33.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.32.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.32.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.31.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.30.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.30.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.29.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.29.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.28.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.27.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.27.0 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.26.1 lib/rubocop/cop/mixin/parser_diagnostic.rb
rubocop-0.26.0 lib/rubocop/cop/mixin/parser_diagnostic.rb