Skip to content

Commit

Permalink
Merge pull request #256 from nimblehq/chore/credo-public-private-func…
Browse files Browse the repository at this point in the history
…-order

[Chore] Update credo config to support check private vs public functions order
  • Loading branch information
byhbt authored Sep 8, 2022
2 parents c1b9b36 + 65f2158 commit 9b323c1
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 74 deletions.
3 changes: 2 additions & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
{Credo.Check.Readability.StrictModuleLayout,
[
order:
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback/a
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback public_fun private_fun/a,
ignore: ~w/callback_impl/a
]},
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
Expand Down
12 changes: 6 additions & 6 deletions lib/nimble_template/addons/variants/phoenix/api/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do
edit_files(project)
end

defp edit_files(%Project{} = project) do
edit_config_prod(project)

project
end

def edit_config_prod(%Project{otp_app: otp_app, web_module: web_module} = project) do
Generator.delete_content(
"config/prod.exs",
Expand Down Expand Up @@ -42,4 +36,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do

project
end

defp edit_files(%Project{} = project) do
edit_config_prod(project)

project
end
end
12 changes: 6 additions & 6 deletions lib/nimble_template/addons/variants/phoenix/api/json_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApi do
edit_files(project)
end

defp edit_files(%Project{} = project) do
project
|> inject_mix_dependency()
|> edit_config()
end

def inject_mix_dependency(project) do
Generator.inject_mix_dependency({:jsonapi, latest_package_version(:jsonapi)})

Expand All @@ -37,4 +31,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApi do

project
end

defp edit_files(%Project{} = project) do
project
|> inject_mix_dependency()
|> edit_config()
end
end
28 changes: 14 additions & 14 deletions lib/nimble_template/addons/variants/phoenix/ex_machina.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do
|> edit_files()
end

def edit_mix_elixirc_paths(%Project{} = project) do
Generator.replace_content(
"mix.exs",
"""
defp elixirc_paths(:test), do: ["lib", "test/support"]
""",
"""
defp elixirc_paths(:test), do: ["lib", "test/support", "test/factories"]
"""
)

project
end

defp copy_files(%Project{base_module: base_module} = project) do
Generator.copy_file([{:eex, "test/support/factory.ex.eex", "test/support/factory.ex"}],
base_module: base_module
Expand All @@ -34,20 +48,6 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do
project
end

def edit_mix_elixirc_paths(%Project{} = project) do
Generator.replace_content(
"mix.exs",
"""
defp elixirc_paths(:test), do: ["lib", "test/support"]
""",
"""
defp elixirc_paths(:test), do: ["lib", "test/support", "test/factories"]
"""
)

project
end

defp edit_test_helper(%Project{} = project) do
Generator.replace_content(
"test/test_helper.exs",
Expand Down
16 changes: 8 additions & 8 deletions lib/nimble_template/addons/variants/phoenix/web/core_js.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do
edit_files(project)
end

defp edit_files(%Project{} = project) do
project
|> edit_package_json()
|> edit_app_js()

project
end

def edit_package_json(%Project{} = project) do
Generator.replace_content(
"assets/package.json",
Expand Down Expand Up @@ -47,4 +39,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do

project
end

defp edit_files(%Project{} = project) do
project
|> edit_package_json()
|> edit_app_js()

project
end
end
28 changes: 14 additions & 14 deletions lib/nimble_template/addons/variants/phoenix/web/es_lint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do
|> copy_files()
end

def edit_app_js(%Project{live_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(%Project{web_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(project), do: project

defp edit_files(%Project{} = project) do
project
|> edit_assets_package()
Expand Down Expand Up @@ -80,20 +94,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do
project
end

def edit_app_js(%Project{live_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(%Project{web_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(project), do: project

defp update_topbar_js_variables do
Generator.replace_content(
"assets/js/app.js",
Expand Down
36 changes: 18 additions & 18 deletions lib/nimble_template/addons/variants/phoenix/web/wallaby.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do
|> edit_files()
end

def edit_endpoint(%Project{otp_app: otp_app} = project) do
Generator.replace_content(
"lib/#{otp_app}_web/endpoint.ex",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
""",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
if Application.get_env(:#{otp_app}, :sql_sandbox) do
plug Phoenix.Ecto.SQL.Sandbox
end
"""
)

project
end

defp copy_files(
%Project{web_module: web_module, base_module: base_module, web_test_path: web_test_path} =
project
Expand Down Expand Up @@ -69,24 +87,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do
project
end

def edit_endpoint(%Project{otp_app: otp_app} = project) do
Generator.replace_content(
"lib/#{otp_app}_web/endpoint.ex",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
""",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
if Application.get_env(:#{otp_app}, :sql_sandbox) do
plug Phoenix.Ecto.SQL.Sandbox
end
"""
)

project
end

defp edit_test_config(%Project{otp_app: otp_app} = project) do
Generator.replace_content(
"config/test.exs",
Expand Down
12 changes: 6 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
"mime": {:hex, :mime, "2.0.2", "0b9e1a4c840eafb68d820b0e2158ef5c49385d17fb36855ac6e7e087d4b1dcc5", [:mix], [], "hexpm", "e6a3f76b4c277739e36c2e21a2c640778ba4c3846189d5ab19f97f126df5f9b7"},
"mime": {:hex, :mime, "2.0.3", "3676436d3d1f7b81b5a2d2bd8405f412c677558c81b1c92be58c00562bb59095", [:mix], [], "hexpm", "27a30bf0db44d25eecba73755acf4068cbfe26a4372f9eb3e4ea3a45956bff6b"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"mimic": {:hex, :mimic, "1.5.1", "085f7ebfeb5b579a13a167aec3c712d71fecfc6cb8b298c0dd3056f97ea2c2a0", [:mix], [], "hexpm", "33a50ef9ff38f8f24b2586d52e529981a3ba2b8d061c872084aff0e993bf4bd5"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.2", "b99ca56bbce410e9d5ee4f9155a212e942e224e259c7ebbf8f2c86ac21d4fa3c", [:mix], [], "hexpm", "98d51bd64d5f6a2a9c6bb7586ee8129e27dfaab1140b5a4753f24dac0ba27d2f"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"phoenix": {:hex, :phoenix, "1.6.6", "281c8ce8dccc9f60607346b72cdfc597c3dde134dd9df28dff08282f0b751754", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "807bd646e64cd9dc83db016199715faba72758e6db1de0707eef0a2da4924364"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"},
"phoenix": {:hex, :phoenix, "1.6.12", "f8f8ac077600f84419806dd53114b2e77aedde7a502e74181a7d886355aa0643", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d6cf5583c9c20f7103c40e6014ef802d96553b8e5d6585ad6e627bd5ddb0d12"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
"phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"},
"plug": {:hex, :plug, "1.13.3", "93b299039c21a8b82cc904d13812bce4ced45cf69153e8d35ca16ffb3e8c5d98", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "98c8003e4faf7b74a9ac41bee99e328b08f069bf932747d4a7532e97ae837a17"},
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
"plug": {:hex, :plug, "1.13.6", "187beb6b67c6cec50503e940f0434ea4692b19384d47e5fdfd701e93cadb4cc2", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "02b9c6b9955bce92c829f31d6284bf53c591ca63c4fb9ff81dfd0418667a34ff"},
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
3 changes: 2 additions & 1 deletion priv/templates/nimble_template/.credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@
{Credo.Check.Readability.StrictModuleLayout,
[
order:
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback/a
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback public_fun private_fun/a,
ignore: ~w/callback_impl/a
]},
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, false},
Expand Down

0 comments on commit 9b323c1

Please sign in to comment.