-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
516 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"skip_files": [ | ||
"lib/ironman.ex", | ||
"lib/mix/tasks/suit_up.ex", | ||
"lib/ironman/utils/io/default_impl.ex", | ||
"lib/ironman/utils/http_client/default_impl.ex", | ||
"lib/ironman/utils/cmd/default_impl.ex" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
defmodule Ironman.Checks.DialyzerConfig do | ||
@moduledoc false | ||
alias Ironman.{Config, Utils} | ||
|
||
@spec run(Config.t()) :: {:error, any()} | {:no | :yes | :up_to_date, Config.t()} | ||
def run(%Config{} = config) do | ||
config | ||
|> Config.starting_project_config() | ||
|> Keyword.get(:dialyzer, nil) | ||
|> case do | ||
nil -> offer_add_dialyzer_config(config) | ||
_ -> {:up_to_date, config} | ||
end | ||
end | ||
|
||
def offer_add_dialyzer_config(%Config{} = config) do | ||
Utils.ask( | ||
"Add dialyzer config to project?", | ||
fn -> do_add_config(config) end, | ||
fn -> skip_install(config) end | ||
) | ||
end | ||
|
||
def do_add_config(%Config{} = config) do | ||
config = set_dialyzer_mix_exs(config) | ||
|
||
config = add_dialyzer_ignore_file(config) | ||
|
||
config = add_plt_to_gitignore(config) | ||
|
||
{:yes, config} | ||
end | ||
|
||
defp set_dialyzer_mix_exs(config) do | ||
mix_exs = Config.mix_exs(config) | ||
mix_exs = Regex.replace(~r/def project do\n.*?\[/, mix_exs, "def project do\n [ " <> dialyzer_config(config)) | ||
Config.set_mix_exs(config, mix_exs) | ||
end | ||
|
||
defp add_dialyzer_ignore_file(config) do | ||
case Config.dialyzer_ignore(config) do | ||
nil -> | ||
Utils.puts("Adding dialyzer ignore file") | ||
Config.set_dialyzer_ignore(config, "[\n\n]") | ||
|
||
_ -> | ||
config | ||
end | ||
end | ||
|
||
defp dialyzer_config(config) do | ||
app_name = Config.app_name(config) | ||
|
||
""" | ||
dialyzer: [ | ||
ignore_warnings: ".dialyzer_ignore.exs", | ||
list_unused_filters: true, | ||
plt_file: {:no_warn, "#{app_name}.plt"} | ||
], | ||
""" | ||
end | ||
|
||
defp add_plt_to_gitignore(config) do | ||
app_name = Config.app_name(config) | ||
|
||
case Config.gitignore(config) do | ||
nil -> | ||
Utils.puts("Creating .gitignore with #{app_name}.plt") | ||
Config.set_gitignore(config, "# dialyzer plt for CI caching\n#{app_name}.plt\n") | ||
|
||
gitignore -> | ||
if String.contains?(gitignore, "#{app_name}.plt") do | ||
config | ||
else | ||
Utils.puts("Adding #{app_name}.plt to .gitignore") | ||
|
||
newlines = if String.ends_with?(gitignore, "\n"), do: "", else: "\n\n" | ||
Config.set_gitignore(config, "#{gitignore}#{newlines}# dialyzer plt\n#{app_name}.plt\n") | ||
end | ||
end | ||
end | ||
|
||
@spec skip_install(Config.t()) :: {:no, Config.t()} | ||
def skip_install(%Config{} = config) do | ||
Utils.puts("Skipping dialyzer config") | ||
{:no, config} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,79 @@ | ||
defmodule Ironman.Config do | ||
@moduledoc """ | ||
This struct represents the state of the project. It is created at the beginning of a run, passed through | ||
all the checks, where it is updated, and then mix.exs is written out at the end based on its contents. | ||
all the checks, where it is updated, and then files are written out at the end based on its contents. | ||
""" | ||
|
||
alias Ironman.Config | ||
alias Ironman.Utils.File, as: IFile | ||
|
||
@type t :: %__MODULE__{ | ||
mix_exs: String.t(), | ||
changed: boolean() | ||
mix_exs_changed: boolean(), | ||
gitignore: String.t() | nil, | ||
gitignore_changed: boolean(), | ||
dialyzer_ignore: String.t() | nil, | ||
dialyzer_ignore_changed: boolean(), | ||
starting_project_config: keyword() | ||
} | ||
defstruct mix_exs: nil, | ||
changed: false | ||
mix_exs_changed: false, | ||
gitignore: nil, | ||
gitignore_changed: false, | ||
dialyzer_ignore: nil, | ||
dialyzer_ignore_changed: false, | ||
starting_project_config: nil | ||
|
||
def new!() do | ||
%__MODULE__{ | ||
mix_exs: File.read!("mix.exs") | ||
mix_exs: file_or_nil("mix.exs"), | ||
gitignore: file_or_nil(".gitignore"), | ||
dialyzer_ignore: file_or_nil(".dialyzer_ignore.exs"), | ||
starting_project_config: Mix.Project.config() | ||
} | ||
end | ||
|
||
## Getters | ||
def starting_project_config(%Config{starting_project_config: starting_project_config}), do: starting_project_config | ||
def mix_exs(%Config{mix_exs: mix_exs}), do: mix_exs | ||
def gitignore(%Config{gitignore: gitignore}), do: gitignore | ||
def dialyzer_ignore(%Config{dialyzer_ignore: dialyzer_ignore}), do: dialyzer_ignore | ||
|
||
## Setters when not actually changed | ||
|
||
def set_mix_exs(%Config{mix_exs: mix_exs} = config, new_content) | ||
when new_content == mix_exs, | ||
do: config | ||
|
||
def set_mix_exs(%Config{} = config, new_content), | ||
do: %Config{config | mix_exs: new_content, mix_exs_changed: true} | ||
|
||
def set_gitignore(%Config{gitignore: gitignore} = config, new_content) | ||
when new_content == gitignore, | ||
do: config | ||
|
||
def set_gitignore(%Config{} = config, new_content), | ||
do: %Config{config | gitignore: new_content, gitignore_changed: true} | ||
|
||
def set_dialyzer_ignore(%Config{dialyzer_ignore: dialyzer_ignore} = config, new_content) | ||
when new_content == dialyzer_ignore, | ||
do: config | ||
|
||
def set_dialyzer_ignore(%Config{} = config, new_content), | ||
do: %Config{config | dialyzer_ignore: new_content, dialyzer_ignore_changed: true} | ||
|
||
def mix_exs_changed(%Config{mix_exs_changed: mix_exs_changed}), do: mix_exs_changed | ||
def gitignore_changed(%Config{gitignore_changed: gitignore_changed}), do: gitignore_changed | ||
def dialyzer_ignore_changed(%Config{dialyzer_ignore_changed: dialyzer_ignore_changed}), do: dialyzer_ignore_changed | ||
|
||
def app_name(%Config{starting_project_config: starting_project_config}), | ||
do: Keyword.fetch!(starting_project_config, :app) | ||
|
||
defp file_or_nil(path) do | ||
if IFile.exists?(path) do | ||
IFile.read!(path) | ||
else | ||
nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.