Metastatic.Analysis.Complexity.LoC
(Metastatic v0.10.3)
View Source
Lines of Code (LoC) metrics calculation.
Calculates logical lines of code by counting statements in the MetaAST, and extracts physical/comment lines from metadata when available.
Metrics
- Logical LoC: Count of executable statements at M2 level
- Physical LoC: Raw line count from source (from metadata)
- Comment lines: Lines containing only comments (from metadata)
- Blank lines: Physical - Logical - Comments
What Counts as Logical Line
Each statement counts as one logical line:
- Assignments
- Function calls
- Early returns
- Conditionals
- Loops
- Pattern matches
- Exception handling
Expressions within statements don't count separately.
Examples
iex> ast = {:literal, [subtype: :integer], 42}
iex> metrics = Metastatic.Analysis.Complexity.LoC.calculate(ast)
iex> metrics.logical
0
Summary
Functions
Calculates LoC metrics for a MetaAST node.
Types
@type t() :: %{ physical: non_neg_integer(), logical: non_neg_integer(), comments: non_neg_integer(), blank: non_neg_integer() }
Functions
@spec calculate(Metastatic.AST.meta_ast(), map()) :: t()
Calculates LoC metrics for a MetaAST node.
Optionally takes metadata map which may contain:
:line_count- Physical line count:comment_lines- Number of comment lines
Examples
iex> ast = {:assignment, [], [{:variable, [], "x"}, {:literal, [subtype: :integer], 5}]}
iex> metrics = Metastatic.Analysis.Complexity.LoC.calculate(ast)
iex> metrics.logical
1
iex> ast = {:block, [], [{:variable, [], "x"}, {:variable, [], "y"}]}
iex> metrics = Metastatic.Analysis.Complexity.LoC.calculate(ast)
iex> metrics.logical
0