Fl4m3Ph03n1x

Fl4m3Ph03n1x

Credo for umbrella apps

Background

Following my question on Umbrella projects:

I know have it clear that the mix.exs file of my umbrella should be for general tooling and tasks my projects directly don’t depend on.

One such tool is credo: GitHub - rrrene/credo: A static code analysis tool for the Elixir language with a focus on code consistency and teaching. · GitHub

Problem

My projects don’t depend or need credo, but I sure like having it around. My objective would therefore be to have mix credo --strict evaluate all my umbrella applications, without me having to specifically install it in every single app.

I understand this is possible, however when I do mix credo --strict it always shows I have 0 problems, even though I have the code with TODO tags and other issue that I know trigger it.

Obviously my configuration is not set up correctly.

Configuration

This is my folder structure:

.
├── README.md
├── apps
│   ├── auction_house
│   │   ├── README.md
│   │   ├── config
│   │   ├── cover
│   │   ├── lib
│   │   ├── mix.exs
│   │   └── test
│   ├── store
│   │   ├── README.md
│   │   ├── lib
│   │   ├── mix.exs
│   │   └── test
├── config
│   ├── config.exs
│   ├── dev.exs
│   ├── prod.exs
│   └── test.exs
├── mix.exs
└── mix.lock

So as you can see, each app has its own mix.exs file which only has the very specific dependencies the projects depends on.

Then on a higher level (apps folder) I have a mix.exs file for the umbrella project. This is what that file looks like:

defmodule MarketManager.MixProject do
  use Mix.Project

  ##########
  # Public #
  ##########

  def project do
    [
      apps_path: "apps",
      version: "1.0.0",
      elixir: "~> 1.10",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      ]
  end

  def application do
    [
      extra_applications: [:logger],
      mod: {MarketManager.Application, [env: Mix.env()]} # No idea what to put here, really
    ]
  end

  ###########
  # Private #
  ###########

  defp deps do
    [
      # Testing and Dev
      {:credo, "~> 1.4", only: [:test, :dev], runtime: false}
    ]
  end

end

Question

What am I doing wrong?

Marked As Solved

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Turns out several things were wrong. To start, my umbrella mix.exs file has stuff it doesn’t need:

defmodule MarketManager.MixProject do
  use Mix.Project

  def project do
    [
      apps_path: "apps",
      version: "1.0.0",
      elixir: "~> 1.10",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      ]
  end

  defp deps do
    [
      # Testing and Dev
      {:credo, "~> 1.4", only: [:test, :dev], runtime: false}
    ]
  end

end

Done. This is all that it should have.

With that fixed, turns out my auction_house app should not have a config folder. Instead, it should use the config folder of the umbrella project itself.

With these two issues fixed, credo now works as expected !

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement