Skip to content

Commit

Permalink
[gh315] Fix credo helper
Browse files Browse the repository at this point in the history
  • Loading branch information
andyduong1920 committed Mar 15, 2023
1 parent 9890876 commit ad453cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 45 deletions.
45 changes: 0 additions & 45 deletions lib/nimble_template/addons/credo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
39 changes: 39 additions & 0 deletions lib/nimble_template/helpers/credo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ defmodule NimbleTemplate.CredoHelper do
|> disable_rules(@do_single_expression_rule_name)

disable_on_core_components(project)

edit_web_entry(project)
end

@spec suppress_credo_warnings_for_phoenix_api_project(Project.t()) :: :ok
Expand Down Expand Up @@ -89,4 +91,41 @@ 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

0 comments on commit ad453cc

Please sign in to comment.