Ameba::Source
Inherits Ameba::Reportable < Ameba::AST::Util < Ameba::InlineComments < Reference < Object
An entity that represents a Crystal source file. Has path, lines of code and issues reported by rules.
Constructors
Creates a new source by code and path.
For example:
path = "src/source.cr"
Ameba::Source.new(File.read(path), path)
Instance methods
ast
Returns AST nodes constructed by Crystal::Parser.
source = Ameba::Source.new(code, path)
source.ast
correct!
Corrects any correctable issues and updates code.
Returns false if no issues were corrected.
lines
Returns lines of code split by new line character.
Since code is immutable and can't be changed, this
method caches lines in an instance variable, so calling
it a second time will not perform a split, but will return
lines instantly.
source = Ameba::Source.new("a = 1\nb = 2", path)
source.lines # => ["a = 1", "b = 2"]
Converts an AST location to a string position.