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

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

Open
Fl4m3Ph03n1x opened this issue Aug 21, 2023 · 8 comments · May be fixed by #473
Open

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

Fl4m3Ph03n1x opened this issue Aug 21, 2023 · 8 comments · May be fixed by #473
Labels

Comments

@Fl4m3Ph03n1x
Copy link

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
Copy link
Owner

pantajoe commented Jun 2, 2024

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
Copy link
Author

Fl4m3Ph03n1x commented Jun 4, 2024

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

@Fl4m3Ph03n1x
Copy link
Author

Fl4m3Ph03n1x commented Jun 6, 2024

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 pantajoe added has workaround bug Something isn't working and removed waiting for reply labels Jun 9, 2024
@pantajoe
Copy link
Owner

pantajoe commented Jun 9, 2024

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.

const projectFolder = documentUri ? CredoUtils.getProjectFolder(documentUri) : undefined
const found = projectFolder
? [path.join(projectFolder, configFilePath), path.join(projectFolder, 'config', configFilePath)].filter(
(fullPath: string) => fs.existsSync(fullPath),
)
: []

@Fl4m3Ph03n1x
Copy link
Author

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
Copy link

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
Copy link
Owner

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

  • parent_folder/
    • mix.exs
    • credo.exs / config/credo.exs
    • apps/
      • app1/
        • mix.exs
      • app2/
        • mix.exs

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

const projectFolder = documentUri ? CredoUtils.getProjectFolder(documentUri) : undefined
const found = projectFolder
? [path.join(projectFolder, configFilePath), path.join(projectFolder, 'config', configFilePath)].filter(
(fullPath: string) => fs.existsSync(fullPath),
)
: []

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 pantajoe linked a pull request Jun 18, 2024 that will close this issue
@pantajoe
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants