class

Ameba::Spec::AnnotatedSource

Inherits Reference < Object

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

Constants

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

Constructors

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.

Source
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.

Source

Class methods

parse(annotated_code)

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

Source

Instance methods

==(other)

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

Source
annotations

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.

Source
lines
Source
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
Source