ExQuality.Init.DepInstaller (ExQuality v0.5.0)
View SourceAdds dependencies to mix.exs programmatically.
Uses line-based insertion to preserve formatting and comments. Validates syntax after editing to ensure correctness.
Summary
Functions
Adds dependencies to mix.exs.
Builds dependency lines to insert.
Extracts indentation from a line.
Finds the line number where new deps should be inserted.
Inserts lines into content at the specified line number.
Functions
Adds dependencies to mix.exs.
Inserts new deps immediately after :ex_quality dependency (or at end of deps list). Creates a backup at mix.exs.backup before modifying.
Returns
:okon success{:error, reason}on failure
Builds dependency lines to insert.
Uses recommended installation options from each tool's documentation.
Format:
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev], runtime: false},
{:excoveralls, "~> 0.18", only: :test},
Extracts indentation from a line.
Examples
extract_indent(" {:credo, "~> 1.7"}")
#=> " "
extract_indent("\t\t{:dialyxir, "~> 1.4"}")
#=> "\t\t"
@spec find_insertion_point(String.t()) :: {:ok, non_neg_integer(), String.t()} | {:error, String.t()}
Finds the line number where new deps should be inserted.
Strategy
- Look for :ex_quality dependency line
- Insert immediately BEFORE it (so new deps have commas and ex_quality comma is optional)
- If not found, insert at end of deps function (before closing bracket)
Returns
{:ok, line_number, indentation_string}on success{:error, reason}on failure
@spec insert_lines(String.t(), non_neg_integer(), [String.t()]) :: String.t()
Inserts lines into content at the specified line number.
Examples
insert_lines("line1\nline2\nline3", 2, ["new1", "new2"])
#=> "line1\nline2\nnew1\nnew2\nline3"