class

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

new(code : String = "", path : String = "", project_path : String = path)

Creates a new source by code and path.

For example:

path = "src/source.cr"
Ameba::Source.new(File.read(path), path)
Source
new(code : String, *args, normalize = true, **opts)
Source

Instance methods

ast

Returns AST nodes constructed by Crystal::Parser.

source = Ameba::Source.new(code, path)
source.ast
Source
code

Crystal code (content of a source file).

Source
correct!

Corrects any correctable issues and updates code. Returns false if no issues were corrected.

Source
ecr?

Returns true if the source is an ECR template, false otherwise.

Source
fullpath

Absolute path to the source file.

Source
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"]
Source
path

Path to the source file.

Source
pos(location : Crystal::Location, end end_pos = false) : Int32

Converts an AST location to a string position.

Source
project_path

Path to the source file relative to the project root.

Source
spec?

Returns true if the source is a spec file, false otherwise.

Source

Nested types