Sha256: 0acaa7faf7124da77c3a37b1e6ef404e1c5216263975788f1a66bcc60ffea55d

Contents?: true

Size: 1.87 KB

Versions: 6823

Compression:

Stored size: 1.87 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This is not actually a cop. It does not inspect anything. It just
      # provides methods to repack Parser's diagnostics/errors
      # into RuboCop's offenses.
      class Syntax < Cop
        PseudoSourceRange = Struct.new(:line, :column, :source_line, :begin_pos,
                                       :end_pos)

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

        def self.offenses_from_processed_source(processed_source,
                                                config, options)
          cop = new(config, options)

          if processed_source.parser_error
            cop.add_offense_from_error(processed_source.parser_error)
          end

          processed_source.diagnostics.each do |diagnostic|
            cop.add_offense_from_diagnostic(diagnostic,
                                            processed_source.ruby_version)
          end

          cop.offenses
        end

        def add_offense_from_diagnostic(diagnostic, ruby_version)
          message =
            "#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " \
            'configure using `TargetRubyVersion` parameter, under `AllCops`)'
          add_offense(nil,
                      location: diagnostic.location,
                      message: message,
                      severity: diagnostic.level)
        end

        def add_offense_from_error(error)
          message = beautify_message(error.message)
          add_offense(nil,
                      location: ERROR_SOURCE_RANGE,
                      message: message,
                      severity: :fatal)
        end

        private

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

Version data entries

6,823 entries across 6,798 versions & 26 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/syntax.rb