Repository: woylie/doggo
Pull request #312 (2024-07-22 09:26:07)

format generated story modules

coveralls: ## Pull Request Test Coverage Report for [Build f1026e0a7bee0ec8a124f927199c2b535d06f753-PR-312](https://coveralls.io/builds/68772304)


### Details

* **4** of **6**   **(66.67%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.3%**) to **89.764%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [lib/mix/tasks/dog.gen.stories.ex](https://coveralls.io/builds/68772304/source?filename=lib%2Fmix%2Ftasks%2Fdog.gen.stories.ex#L122) | 4 | 6 | 66.67%
<!-- | **Total:** | **4** | **6** | **66.67%** | -->


|  Totals | [![Coverage Status](https://coveralls.io/builds/68772304/badge)](https://coveralls.io/builds/68772304) |
| :-- | --: |
| Change from base [Build 144b6eac92bb2fef6f28425e098a6e025d153e6f](https://coveralls.io/builds/68772110): |  0.3% |
| Covered Lines: | 684 |
| Relevant Lines: | 762 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/demo/storybook/menu/menu_item_radio_group.story.exs b/demo/storybook/menu/menu_item_radio_group.story.exs
index 086da0a..20486a1 100644
--- a/demo/storybook/menu/menu_item_radio_group.story.exs
+++ b/demo/storybook/menu/menu_item_radio_group.story.exs
@@ -1,4 +1,7 @@
 defmodule Storybook.Components.MenuItemRadioGroup do
   use PhoenixStorybook.Story, :component
-  use Doggo.Storybook, module: DemoWeb.CoreComponents, name: :menu_item_radio_group
+
+  use Doggo.Storybook,
+    module: DemoWeb.CoreComponents,
+    name: :menu_item_radio_group
 end
diff --git a/lib/mix/tasks/dog.gen.stories.ex b/lib/mix/tasks/dog.gen.stories.ex
index 6a4beea..0208f12 100644
--- a/lib/mix/tasks/dog.gen.stories.ex
+++ b/lib/mix/tasks/dog.gen.stories.ex
@@ -86,8 +86,7 @@ defmodule Mix.Tasks.Dog.Gen.Stories do
 
       cond do
         !exists? || opts[:force] ->
-          File.write!(file_path, template)
-          IO.puts("Story written to #{file_path}.")
+          write_file(file_path, template)
           write_stories(rest, module, base_path, opts)
 
         exists? && opts[:skip_all] ->
@@ -120,13 +119,11 @@ defmodule Mix.Tasks.Dog.Gen.Stories do
 
     case prompt_overwrite() do
       :overwrite ->
-        File.write!(file_path, template)
-        IO.puts("Story written to #{file_path}")
+        write_file(file_path, template)
         write_stories(rest, module, base_path, opts)
 
       :overwrite_all ->
-        File.write!(file_path, template)
-        IO.puts("Story written to #{file_path}")
+        write_file(file_path, template)
         opts = Keyword.put(opts, :force, true)
         write_stories(rest, module, base_path, opts)
 
@@ -154,4 +151,10 @@ defmodule Mix.Tasks.Dog.Gen.Stories do
       _ -> prompt_overwrite()
     end
   end
+
+  defp write_file(file_path, template) do
+    {formatter, _} = Mix.Tasks.Format.formatter_for_file(file_path)
+    File.write!(file_path, formatter.(template))
+    IO.puts("Story written to #{file_path}.")
+  end
 end


Test patch:
diff --git a/test/mix/tasks/dog.gen.stories_test.exs b/test/mix/tasks/dog.gen.stories_test.exs
index 5b3e4f4..b172a90 100644
--- a/test/mix/tasks/dog.gen.stories_test.exs
+++ b/test/mix/tasks/dog.gen.stories_test.exs
@@ -33,12 +33,16 @@ defmodule Mix.Tasks.Dog.GenStoriesTest do
 
     assert File.exists?(button_path)
 
+    {formatter, _} = Mix.Tasks.Format.formatter_for_file(button_path)
+
     assert File.read!(button_path) ==
-             Doggo.Storybook.story_template(TestComponents, :button)
+             formatter.(Doggo.Storybook.story_template(TestComponents, :button))
 
     assert File.exists?(menu_path)
 
     assert File.read!(menu_path) ==
-             Doggo.Storybook.story_template(TestComponents, :context_menu)
+             formatter.(
+               Doggo.Storybook.story_template(TestComponents, :context_menu)
+             )
   end
 end