Sha256: dcc0192645e4517c4d59e3cc5adf0cece2885315a2a8e583af88d95096809fed

Contents?: true

Size: 1.26 KB

Versions: 41

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop repacks Parser's diagnostics/errors
      # into RuboCop's offenses.
      class Syntax < Base
        def on_other_file
          add_offense_from_error(processed_source.parser_error) if processed_source.parser_error
          processed_source.diagnostics.each do |diagnostic|
            add_offense_from_diagnostic(diagnostic,
                                        processed_source.ruby_version)
          end
          super
        end

        private

        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(diagnostic.location,
                      message: message,
                      severity: diagnostic.level)
        end

        def add_offense_from_error(error)
          message = beautify_message(error.message)
          add_global_offense(message, severity: :fatal)
        end

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

Version data entries

41 entries across 41 versions & 4 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/syntax.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/syntax.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/syntax.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/syntax.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/syntax.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/lint/syntax.rb
rubocop-1.12.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.12.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.11.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.10.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.9.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.9.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.8.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.8.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.7.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.6.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.6.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.5.2 lib/rubocop/cop/lint/syntax.rb
rubocop-1.5.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.5.0 lib/rubocop/cop/lint/syntax.rb