Sha256: 1b290561fed437aa257858ec734bee54925802657174a6acadb3a581e3d89850

Contents?: true

Size: 1.4 KB

Versions: 23

Compression:

Stored size: 1.4 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Lint
      # This is actually not a cop and inspects nothing. It just provides
      # methods to repack Parser's diagnostics/errors into RuboCop's offenses.
      module Syntax
        PseudoSourceRange = Struct.new(:line, :column, :source_line)

        COP_NAME = 'Syntax'.freeze
        ERROR_SOURCE_RANGE = PseudoSourceRange.new(1, 0, '').freeze

        def self.offenses_from_processed_source(processed_source)
          offenses = []

          if processed_source.parser_error
            offenses << offense_from_error(processed_source.parser_error)
          end

          processed_source.diagnostics.each do |diagnostic|
            offenses << offense_from_diagnostic(diagnostic)
          end

          offenses
        end

        def self.offense_from_diagnostic(diagnostic)
          Offense.new(
            diagnostic.level,
            diagnostic.location,
            diagnostic.message,
            COP_NAME
          )
        end

        def self.offense_from_error(error)
          message = beautify_message(error.message)
          Offense.new(:fatal, ERROR_SOURCE_RANGE, message, COP_NAME)
        end

        def self.beautify_message(message)
          message = message.capitalize
          message << '.' unless message.end_with?('.')
          message
        end

        private_class_method :beautify_message
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

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