module RuboCop::Cop::Lint::Syntax
This is actually not a cop and inspects nothing. It just provides methods to repack Parser's diagnostics/errors into RuboCop's offenses.
Constants
- COP_NAME
- ERROR_SOURCE_RANGE
- PseudoSourceRange
Public Class Methods
offense_from_diagnostic(diagnostic, ruby_version)
click to toggle source
# File lib/rubocop/cop/lint/syntax.rb, line 30 def self.offense_from_diagnostic(diagnostic, ruby_version) Offense.new( diagnostic.level, diagnostic.location, "#{diagnostic.message}\n(Using Ruby #{ruby_version} parser; " 'configure using `TargetRubyVersion` parameter, under `AllCops`)', COP_NAME ) end
offense_from_error(error)
click to toggle source
# File lib/rubocop/cop/lint/syntax.rb, line 40 def self.offense_from_error(error) message = beautify_message(error.message) Offense.new(:fatal, ERROR_SOURCE_RANGE, message, COP_NAME) end
offenses_from_processed_source(processed_source)
click to toggle source
# File lib/rubocop/cop/lint/syntax.rb, line 15 def self.offenses_from_processed_source(processed_source) offenses = [] if processed_source.parser_error offenses << offense_from_error(processed_source.parser_error) end processed_source.diagnostics.each do |diagnostic| offenses << offense_from_diagnostic(diagnostic, processed_source.ruby_version) end offenses end
Private Class Methods
beautify_message(message)
click to toggle source
# File lib/rubocop/cop/lint/syntax.rb, line 45 def self.beautify_message(message) message = message.capitalize message << '.' unless message.end_with?('.') message end