pantajoe / vscode-elixir-credo

VSCode support for Elixir Linter 'Credo'.
https://marketplace.visualstudio.com/items?itemName=pantajoe.vscode-elixir-credo
MIT License
30 stars 8 forks source link

“.credo.exs file does not exist” in Umbrella project #462

Open Fl4m3Ph03n1x opened 1 year ago

Fl4m3Ph03n1x commented 1 year ago

Background

I have an umbrella app with the following structure:

:.
├───mix.exs
├───.mix.lock
├───.credo.exs
├───apps
│   └───app1
...

When working with my umbrella project, I usually open the root folder of the project and work in the desired application from there.

My .credo.exs. file is the default one generated by mix credo gen.config and I have {:credo, "~> 1.6", only: [:dev, :test], runtime: false}, in my root's mix.exs file.

I have also installed credo and its dependencies using:

mix archive.install hex credo
mix archive.install hex bunt
mix archive.install hex jason

So I am sure I have all the dependencies installed.

I also launch VSCode with code . using Windows cmd to make sure I get all the ENV vars from the shell loaded.

Problem

The issue here is that no matter what I do, I always get the .credo.exs file does not exist. Ignoring .... no matter what I do.

To try and fix my issues I read this post:

https://elixirforum.com/t/configure-credo-to-use-global-credo-exs-file/2707

However this wont do it for me. Not only do I still get the error once I get inside the individual applications, it also does not fit with my workflow, as I mostly work with the root directory open.

Questions

How can I fix this?

pantajoe commented 5 months ago

Thanks for submitting this issue! Apologies for the late reply, but I'm trying to pick this project up again!

Just to clarify, have to you tried to create a .vscode/settings.json and set the option elixir.credo.configurationFile to an absolute path?

Fl4m3Ph03n1x commented 5 months ago

I didnt know this was an option! I will let you know once I try ! Happy to have you back !

Fl4m3Ph03n1x commented 5 months ago

When I added the complete path it fixed the issue:

settings.json for user:

{
    "workbench.colorTheme": "Catppuccin Mocha",
    "workbench.iconTheme": "catppuccin-mocha",
    "editor.fontFamily": "Fira Code",
    "editor.fontLigatures": true,
    "editor.formatOnSave": true,
    "redhat.telemetry.enabled": true,
    "editor.rulers": [
        120
    ],
    "workbench.colorCustomizations": {
        "editorRuler.foreground": "#009999"
    },
    "elixir.credo.configurationFile": "/home/user/workspace/my_app/.credo.exs"
}

This held true for both the User settings and Workspace settings.

Perhaps there is an issue when credo is building the path to find the file?

pantajoe commented 5 months ago

Okay, great that we have a workaround for this issue! 👍🏽

I think, the main problem is that the extension searchs for the credo configuration inside the folder of the mix project of the active elixir file. And since in each directory, there is a mix.exs file, it assumes that the project folder has been found and tries to look for the credo.exs there instead of one directory further up.

https://github.com/pantajoe/vscode-elixir-credo/blob/39383cb2c773bf899752a4fa6c94e41ec31589e6/src/credo-utils.ts#L70-L75

Fl4m3Ph03n1x commented 5 months ago

If that is the case, then perhaps the mix.exs file itself can help. Here is an example of a mix.exs file from a typical Phoenix application:

  def project do
    [
      app: :my_app,
      version: "0.1.0",
      elixir: "~> 1.16",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      aliases: aliases(),
      deps: deps(),
      compilers: [:yecc] ++ Mix.compilers()
      ]
    ]
  end

And this is the mix.exs file from an umbrella app:

  def project do
    [
      app: :auction_house,
      version: "3.0.1",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.16",
      elixirc_paths: elixirc_paths(Mix.env()),
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      test_coverage: [tool: ExCoveralls],
      preferred_cli_env: preferred_cli_env(),
      aliases: aliases()
    ]
  end

Notice we have specific fields, such as build_path, config_path, deps_path, etc.

Perhaps we can leverage this? If no .credo.exs file is found in the current directory, we could try to follow the build_path, for example.

ppeerttu commented 5 months ago

I would love to get this fixed, and happy to even contribute if needed. How about we use the lockfile path? I'm not sure if people tend to change any of these configs from the defaults, but I would assume the lockfile is at least always at the project root, where the umbrella mix.exs is as well.

pantajoe commented 5 months ago

Hm, I don't think parsing the mix.exs is something we should do. Instead, Since the structure of elixir umbrella apps is always:

We just have to change the detection of this piece right here:

https://github.com/pantajoe/vscode-elixir-credo/blob/39383cb2c773bf899752a4fa6c94e41ec31589e6/src/credo-utils.ts#L70-L75

It has to support that the detected mix project folder is part of an apps directory that is an elixir project (i.e., has an own mix.exs).

pantajoe commented 5 months ago

I've drafted a PR that should fix that, I just have to find some time to fix and extend the tests: #473