megalinter icon indicating copy to clipboard operation
megalinter copied to clipboard

devcontainer support

Open robinmordasiewicz opened this issue 2 months ago • 5 comments

We are using devcontainers and want to run megalinter from a pre-commit, but devcontainer mounts the workspace repo to a folder in the devcontainer at location "/workspace/reponame" but megalinter is not aware of this mount inside the devcontainer. Is there a way to run megalinter from a pre-commit hook within the devcontainer and pass in an environment variable with the original filesystem mount location ?

robinmordasiewicz avatar Apr 12 '24 04:04 robinmordasiewicz

The .devcontainer file in MegaLinter is an inheritance from SuperLinter and i'm not sure it ever worked

It is possible to use MegaLinter as pre-commit ( @Kurt-von-Laven does it a lot ^^ ) , according to the documentation: https://megalinter.io/latest/mega-linter-runner/#pre-commit-hook

About devcontainer + pre-commit + env variable.... as i'm not a devcontainer user, I'm sorry but on my side I have no answer :(

nvuillam avatar Apr 17 '24 10:04 nvuillam

I have written a bit of CMake code to run MegaLinter from within a devcontainer on code that is either mounted as a volume or bind mounted. The respective code can be found here: https://github.com/philips-software/amp-embedded-infra-lib/blob/main/cmake/emil_docker_tools.cmake. It should be fairly trivial to extract it to any type of language or scripting that you would like to use it in.

One detail: for the bind mount scenario you need to pass in an environment variable LOCAL_WORKSPACE_FOLDER in your devcontainer.json (I add this by default to all our devcontainers https://github.com/philips-software/amp-devcontainer).

"remoteEnv": {
      "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
    }

rjaegers avatar Apr 24 '24 09:04 rjaegers