Ameba::Spec::AnnotatedSource - ameba 1.7.0

# class Ameba::Spec::AnnotatedSource

- Ameba::Spec::AnnotatedSource
- Reference
- Object

##
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

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

- .new(lines : Array(String), issues : Enumerable(Issue))

  Annotates the source code with the Ameba issues provided.

##
Class Method Summary

- .parse(annotated_code)

  Separates annotation lines from code lines.

##
Instance Method Summary

- #==(other : self)

  Returns `true` if this reference is the same as other.

- #annotations : Array(Tuple(Int32, String, String))

  Each entry is the line number, annotation prefix, and message.

- #lines : Array(String)
- #to_s(io)

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

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

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.

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

##
Instance Method Detail

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

Returns `true` if this reference is the same as other. Invokes `same?`.

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.

def lines : Array(String) #
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