Sha256: 52f09b031257bf77eb4afda0bf4a150d12f0c72afd9ffc82a1048b8361590ca6

Contents?: true

Size: 1.37 KB

Versions: 19

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # 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 = if LSP.enabled?
                      diagnostic.message
                    else
                      "#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " \
                        'configure using `TargetRubyVersion` parameter, under `AllCops`)'
                    end
          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

        def find_severity(_range, _severity)
          :fatal
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
rubocop-1.69.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.68.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.67.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.66.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.66.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.65.1 lib/rubocop/cop/lint/syntax.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/cop/lint/syntax.rb
rubocop-1.65.0 lib/rubocop/cop/lint/syntax.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/cop/lint/syntax.rb
rubocop-1.64.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.63.4 lib/rubocop/cop/lint/syntax.rb
rubocop-1.63.3 lib/rubocop/cop/lint/syntax.rb
rubocop-1.63.2 lib/rubocop/cop/lint/syntax.rb
rubocop-1.63.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.63.0 lib/rubocop/cop/lint/syntax.rb
bison-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.62.1/lib/rubocop/cop/lint/syntax.rb
rubocop-1.62.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.62.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.61.0 lib/rubocop/cop/lint/syntax.rb