Metastatic.Analysis.Smells.Result
(Metastatic v0.10.4)
View Source
Result structure for code smell detection.
Contains information about detected code smells, their severity, and refactoring suggestions.
Fields
:has_smells?- Boolean indicating if any code smells were found:smells- List of detected smell details:summary- Human-readable summary of findings:total_smells- Count of detected smells:by_severity- Map of counts by severity:by_type- Map of counts by smell type
Smell Types
:long_function- Function with too many statements:deep_nesting- Excessive nesting depth:magic_number- Unexplained numeric literals:complex_conditional- Complex boolean expressions:long_parameter_list- Too many parameters:duplicate_code- Duplicated logic
Examples
iex> result = Metastatic.Analysis.Smells.Result.new([])
iex> result.has_smells?
false
iex> smells = [%{type: :long_function, severity: :high, description: "test"}]
iex> result = Metastatic.Analysis.Smells.Result.new(smells)
iex> result.has_smells?
true
iex> result.total_smells
1
Summary
Functions
Creates a new result from a list of code smells.
Creates a result with no code smells.
Converts result to JSON-compatible map.
Types
@type location() :: %{ optional(:function) => String.t(), optional(:module) => String.t(), optional(:line) => non_neg_integer(), optional(:arity) => non_neg_integer() }
@type severity() :: :critical | :high | :medium | :low
@type smell_type() ::
:long_function
| :deep_nesting
| :magic_number
| :complex_conditional
| :long_parameter_list
| :duplicate_code
@type t() :: %Metastatic.Analysis.Smells.Result{ by_severity: %{required(severity()) => non_neg_integer()}, by_type: %{required(smell_type()) => non_neg_integer()}, has_smells?: boolean(), smells: [smell()], summary: String.t(), total_smells: non_neg_integer() }
Functions
Creates a new result from a list of code smells.
Examples
iex> Metastatic.Analysis.Smells.Result.new([])
%Metastatic.Analysis.Smells.Result{has_smells?: false, summary: "No code smells detected"}
iex> smells = [%{type: :long_function, severity: :high, description: "test", suggestion: "refactor", context: nil}]
iex> result = Metastatic.Analysis.Smells.Result.new(smells)
iex> result.has_smells?
true
@spec no_smells() :: t()
Creates a result with no code smells.
Examples
iex> result = Metastatic.Analysis.Smells.Result.no_smells()
iex> result.has_smells?
false
Converts result to JSON-compatible map.
Examples
iex> result = Metastatic.Analysis.Smells.Result.new([])
iex> map = Metastatic.Analysis.Smells.Result.to_map(result)
iex> is_map(map)
true