Custom Phoenix generator templates

almirsarajcic

almirsarajcic

Created 15 days ago

Suppose you have strict Credo rules in your app. After running Phoenix generators like mix phx.gen.live, you probably have to fix many code style issues before moving on. That’s because the default Phoenix generator templates didn’t consider Credo.

We see value in Credo checks, but they slow us down when creating new resources. We noticed we were wasting a lot of time fixing the same issues over and over. That’s why we’ve decided to fix these issues once in templates, and then use them every time we generate new resources.

# Include the templates in the app
git submodule add \
  https://github.com/optimumBA/optimum_templates \
  priv/templates

# Run some Phoenix generator
mix phx.gen.context \
  Accounts User users name:string age:integer

Now, we don’t see any Credo issues.

Source code: https://github.com/optimumBA/optimum_templates