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.crConstant 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)
Returns
false
(other can only be aValue
here). -
#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
NOTE Annotations are sorted so that reconstructing the annotation
text via #to_s
is deterministic.
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
Separates annotation lines from code lines. Tracks the real code line number that each annotation corresponds to.
Instance Method Detail
Returns false
(other can only be a Value
here).
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.
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