Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No sub formatter found in 0.4.5+ #154

Closed
nathany-copia opened this issue Nov 14, 2024 · 13 comments
Closed

No sub formatter found in 0.4.5+ #154

nathany-copia opened this issue Nov 14, 2024 · 13 comments
Labels
bug Something isn't working

Comments

@nathany-copia
Copy link

Describe the bug

Upgrading from Igniter 0.4.4 to 0.4.5 or 0.4.7 results in this error for the use Igniter.Mix.Task line in my mix task.

** (Rewrite.DotFormatterError) No sub formatter found in "priv/*/data_migrations"
    (rewrite 1.1.0) lib/rewrite/dot_formatter.ex:133: Rewrite.DotFormatter.read!/2
    (igniter 0.4.5) lib/igniter.ex:109: Igniter.new/0
    (copia 0.0.1) lib/mix/tasks/datafeed.gen.ex:11: Mix.Tasks.Datafeed.Gen.run/1
    (mix 1.17.3) lib/mix/task.ex:495: anonymous fn/3 in Mix.Task.run_task/5
    (mix 1.17.3) lib/mix/cli.ex:96: Mix.CLI.run_task/2
    /opt/homebrew/bin/mix:2: (file)

To Reproduce

I'm not sure what you would need. Does the existence of exs files in the priv/repo/data_migrations folder trigger this?

Expected behavior

Continue to work as in 0.4.4.

** Runtime

❯ elixir -v
Erlang/OTP 27 [erts-15.1.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Elixir 1.17.3 (compiled with Erlang/OTP 26)
  • Elixir version
  • Erlang version
  • OS - macOS 15.1
  • Igniter version 0.4.5+
  • any related extension versions

Additional context

@nathany-copia nathany-copia added the bug Something isn't working label Nov 14, 2024
@zachallaun
Copy link
Collaborator

@NickNeck Any ideas on this?

@NickNeck
Copy link
Contributor

NickNeck commented Nov 15, 2024

@nathany-copia it looks like that your .formatter.exs has the line subdirectories: ["priv/*/migrations"], but the file priv/repo/migrations/.formatter.exs is missing (the dir repo could have any other name).

Could you check this with:

find . -name .formatter.exs -not -path "./deps*"

For one of my projects I get:

./priv/repo/migrations/.formatter.exs
./.formatter.exs

Edit: Elixir's formatter does the same thing, but does not throw an error. I will check to see if Rewrite.DotFormatter can behave in the same way. My first guess is that the Elixir formatter has a fallback to the .formatter.exs in the root dir.

@NickNeck
Copy link
Contributor

One more thing. Rewrite keeps the DotFormatter up to date during an igniter run. The exception could be thrown if igniter updates the .formatter.exs before the source for the sub formatter has been created.

@zachallaun
Copy link
Collaborator

@NickNeck So to solve this, we should bump rewrite to 1.1.1 and use the new ignore_sub_formatters option everywhere we read a dotformatter?

@zachdaniel
Copy link
Contributor

(Not back yet) I think we want to ensure we write subformatters before the parent formatter, or we want to make sure that subformatters are only ignored when not present. Is that what the ignore subformatters option does?

@NickNeck
Copy link
Contributor

@zachdaniel with the ignore_missing_sub_formatters option, a missing sub-formatter will be ignored instead of returning or throwing an error. If all sub-formatter files are available, they will be read.

@epinault
Copy link

+1 one on this issue. Is the solution to create the .formatter file? I don t recall it needed in the migrations but maybe something that was added later on in Phx?

@zachdaniel
Copy link
Contributor

Sounds like the new option is the way 👍

@NickNeck
Copy link
Contributor

@epinault creating the missing .formatter.exs is one solution, but if you don't want or need a sub formatter, you can also remove the :subdirectories option from the parent .formatter.exs.

The mix phx.new ... task creates a sub formatter or several in case of an umbrella app. In a non-umbrella app it looks like this:

$> cat .formatter.exs
[
  import_deps: [:ecto, :ecto_sql, :phoenix],
  subdirectories: ["priv/*/migrations"],
  plugins: [Phoenix.LiveView.HTMLFormatter],
  inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]
$> cat priv/repo/migrations/.formatter.exs
[
  import_deps: [:ecto_sql],
  inputs: ["*.exs"]
]

@NickNeck
Copy link
Contributor

@zachdaniel I think the new ignore_missing_sub_formatters option is a good way, because mix format also does not check if the sub formatters are available.

@nathany-copia
Copy link
Author

nathany-copia commented Nov 25, 2024

Thanks for this.

@zachdaniel Sorry I missed the notification for your earlier message. I see the same thing you did:

./priv/repo/migrations/.formatter.exs
./.formatter.exs

@NickNeck
Copy link
Contributor

Thanks for this.

@zachdaniel Sorry I missed the notification for your earlier message. I see the same thing you did:

./priv/repo/migrations/.formatter.exs
./.formatter.exs

But the error message says No sub formatter found in "priv/*/data_migrations" and there is no .formatter.exs in the directory priv/*/data_migrations. There is only one sub formatter in priv/*/migrations.

@zachdaniel
Copy link
Contributor

I'm not really sure what the original root cause for the issue is, but it shouldn't matter any more right? igniter will do the right thing regardless w/ the new option from rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants