Sha256: ff98bbee3f06deb2ad56d487c0cd3293d92e4cc3559911f9be317b7f9fa00c99
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # Repacks Parser's diagnostics/errors # into RuboCop's offenses. class Syntax < Base LEVELS = %i[error fatal].freeze def on_other_file add_offense_from_error(processed_source.parser_error) if processed_source.parser_error syntax_errors = processed_source.diagnostics.select { |d| LEVELS.include?(d.level) } syntax_errors.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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubocop-1.70.0 | lib/rubocop/cop/lint/syntax.rb |