Module: RuboCop::Cop::Lint::Syntax

Defined in:
lib/rubocop/cop/lint/syntax.rb

Overview

This is actually not a cop and inspects nothing. It just provides methods to repack Parser’s diagnostics/errors into RuboCop’s offenses.

Defined Under Namespace

Classes: PseudoSourceRange

Constant Summary collapse

COP_NAME =
'Syntax'.freeze
ERROR_SOURCE_RANGE =
PseudoSourceRange.new(1, 0, '', 0, 1).freeze

Class Method Summary collapse

Class Method Details

.offense_from_diagnostic(diagnostic, ruby_version) ⇒ Object



30
31
32
33
34
35
36
37
38
# 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) ⇒ Object



40
41
42
43
# 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) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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