Sha256: a103d330491637467f68446f9d57871ef8cc59aee375ecb1ad4ac9c909ffd695

Contents?: true

Size: 1.22 KB

Versions: 32

Compression:

Stored size: 1.22 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

32 entries across 32 versions & 6 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/syntax.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/syntax.rb
rubocop-1.26.1 lib/rubocop/cop/lint/syntax.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/syntax.rb
rubocop-1.26.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.25.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.25.0 lib/rubocop/cop/lint/syntax.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/lint/syntax.rb
rubocop-1.24.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.24.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.23.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.22.3 lib/rubocop/cop/lint/syntax.rb
rubocop-1.22.2 lib/rubocop/cop/lint/syntax.rb
rubocop-1.22.1 lib/rubocop/cop/lint/syntax.rb
rubocop-1.22.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.21.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.20.0 lib/rubocop/cop/lint/syntax.rb
rubocop-1.19.1 lib/rubocop/cop/lint/syntax.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/rubocop-1.18.3/lib/rubocop/cop/lint/syntax.rb
rubocop-1.19.0 lib/rubocop/cop/lint/syntax.rb