MetaCredo.SourceFile (MetaCredo v0.1.0)

View Source

Wraps a Metastatic.Document with source text and filename for analysis.

Analogous to Credo.SourceFile, providing access to the AST, source lines, and metadata needed by checks.

Summary

Functions

Returns the MetaAST for this source file.

Returns the language of this source file.

Returns the line at the given 1-based line number.

Returns lines as [{line_no, line_content}].

Parses source code into a SourceFile.

Returns the source code as a string.

Types

t()

@type t() :: %MetaCredo.SourceFile{
  document: Metastatic.Document.t(),
  filename: String.t(),
  language: atom(),
  lines: [{pos_integer(), String.t()}],
  source: String.t(),
  status: :valid | :invalid | :timed_out
}

Functions

ast(source_file)

@spec ast(t()) :: Metastatic.AST.meta_ast()

Returns the MetaAST for this source file.

language(source_file)

@spec language(t()) :: atom()

Returns the language of this source file.

line_at(source_file, line_no)

@spec line_at(t(), pos_integer()) :: String.t() | nil

Returns the line at the given 1-based line number.

lines(source_file)

@spec lines(t()) :: [{pos_integer(), String.t()}]

Returns lines as [{line_no, line_content}].

parse(source, filename, language)

@spec parse(String.t(), String.t(), atom()) :: {:ok, t()} | {:error, term()}

Parses source code into a SourceFile.

Uses the appropriate Metastatic.Adapter for the given language to produce a Metastatic.Document, then wraps it with source metadata.

source(source_file)

@spec source(t()) :: String.t()

Returns the source code as a string.