From 03194d669c2114034a98b0150b06b2d9bd7378b2 Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Wed, 15 Mar 2023 23:30:10 +0700 Subject: [PATCH] [gh315] Fix the credo helper --- lib/nimble_template/addons/credo.ex | 45 ---------------------------- lib/nimble_template/helpers/credo.ex | 41 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/lib/nimble_template/addons/credo.ex b/lib/nimble_template/addons/credo.ex index 0a0bde19..d9e4be12 100644 --- a/lib/nimble_template/addons/credo.ex +++ b/lib/nimble_template/addons/credo.ex @@ -33,7 +33,6 @@ defmodule NimbleTemplate.Addons.Credo do project |> inject_mix_dependency!() |> edit_mix!() - |> edit_web_entry!() end defp inject_mix_dependency!(project) do @@ -60,48 +59,4 @@ defmodule NimbleTemplate.Addons.Credo do project end - - defp edit_web_entry!( - %Project{web_path: web_path, web_module: web_module, mix_project?: false} = project - ) do - Generator.replace_content( - "#{web_path}.ex", - """ - def verified_routes do - quote do - use Phoenix.VerifiedRoutes, - endpoint: #{web_module}.Endpoint, - router: #{web_module}.Router, - statics: #{web_module}.static_paths() - end - end - """, - "" - ) - - Generator.replace_content( - "#{web_path}.ex", - """ - defp html_helpers do - """, - """ - def verified_routes do - quote do - use Phoenix.VerifiedRoutes, - endpoint: #{web_module}.Endpoint, - router: #{web_module}.Router, - statics: #{web_module}.static_paths() - end - end - - defp html_helpers do - """ - ) - - project - end - - defp edit_web_entry!(project) do - project - end end diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index 74f9bb9b..6518e2af 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -23,6 +23,8 @@ defmodule NimbleTemplate.CredoHelper do |> disable_rules(@do_single_expression_rule_name) disable_on_core_components(project) + + edit_edit_web_entry(project) end @spec suppress_credo_warnings_for_phoenix_api_project(Project.t()) :: :ok @@ -89,4 +91,43 @@ defmodule NimbleTemplate.CredoHelper do ) end end + + defp edit_web_entry( + %Project{web_path: web_path, web_module: web_module} = project + ) do + Generator.delete_content!( + "#{web_path}.ex", + """ + def verified_routes do + quote do + use Phoenix.VerifiedRoutes, + endpoint: #{web_module}.Endpoint, + router: #{web_module}.Router, + statics: #{web_module}.static_paths() + end + end + """ + ) + + Generator.replace_content!( + "#{web_path}.ex", + """ + defp html_helpers do + """, + """ + def verified_routes do + quote do + use Phoenix.VerifiedRoutes, + endpoint: #{web_module}.Endpoint, + router: #{web_module}.Router, + statics: #{web_module}.static_paths() + end + end + + defp html_helpers do + """ + ) + + project + end end