class Ameba::Spec::AnnotatedSource

Overview

Parsed representation of code annotated with the # ^^^ error: Message style

Defined in:

ameba/spec/annotated_source.cr

Constant Summary

ABBREV = "[...]"
ANNOTATION_PATTERN_1 = /\A\s*(# )?(\^+|\^{})( error:)? /
ANNOTATION_PATTERN_2 = " # error: "

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(lines : Array(String), annotations : Enumerable(Tuple(Int32, String, String))) #

NOTE Annotations are sorted so that reconstructing the annotation text via #to_s is deterministic.


[View source]
def self.new(lines : Array(String), issues : Enumerable(Issue)) #

Annotates the source code with the Ameba issues provided.

NOTE Annotations are sorted so that reconstructing the annotation text via #to_s is deterministic.


[View source]

Class Method Detail

def self.parse(annotated_code) #

Separates annotation lines from code lines. Tracks the real code line number that each annotation corresponds to.


[View source]

Instance Method Detail

def ==(other) #
Description copied from class Reference

Returns false (other can only be a Value here).


[View source]
def annotations : Array(Tuple(Int32, String, String)) #

Each entry is the line number, annotation prefix, and message. The prefix is empty if the annotation is at the end of a code line.


[View source]
def lines : Array(String) #

[View source]
def to_s(io) #

Constructs an annotated source string (like what we parse).

Reconstructs a deterministic annotated source string. This is useful for eliminating semantically irrelevant annotation ordering differences.

source1 = AnnotatedSource.parse(<<-CRYSTAL)
line1
^ Annotation 1
 ^^ Annotation 2
CRYSTAL

source2 = AnnotatedSource.parse(<<-CRYSTAL)
line1
 ^^ Annotation 2
^ Annotation 1
CRYSTAL

source1.to_s == source2.to_s # => true

[View source]