michaellzc / vscode-hadolint

VSCode extension to integrate hadolint, a Dockerfile linter, into VSCode
https://marketplace.visualstudio.com/items?itemName=exiasr.hadolint
MIT License
77 stars 5 forks source link

Can't add command line options #47

Closed ndepal closed 3 years ago

ndepal commented 3 years ago

I'm trying to add a command line option to the hadolint command that this extension runs. In particular, I would like to ignore a ruleset.

I have modified the vscode settings as follows:

    "hadolint.hadolintPath": "hadolint",
    "hadolint.cliOptions": [

        "--no-color",
        "--ignore DL3059"
    ]

This produces an error:

[hadolint(31995) file:///home/ndepal/my-project] Current settings: {"hadolintPath":"hadolint","cliOptions":["--no-color","--ignore DL3059"],"maxNumberOfProblems":100,"outputLevel":"warning"}
[hadolint] Running hadolint /home/ndepal/my-project/Dockerfile --no-color --ignore DL3059 in /home/ndepal/my-project
[hadolint] `--no-color` flag may not supported. Falling back...
[hadolint] Invalid option `--ignore DL3059'

Usage: hadolint [-v|--version] [--no-fail] [--no-color] [-c|--config FILENAME] 
                [-f|--format ARG] [DOCKERFILE...] [--error RULECODE] 
                [--warning RULECODE] [--info RULECODE] [--style RULECODE] 
                [--ignore RULECODE] 
                [--trusted-registry REGISTRY (e.g. docker.io)] 
                [--require-label LABELSCHEMA (e.g. maintainer:text)] 
                [--strict-labels]
  Lint Dockerfile for errors and best practices

But when I copy the command that the extension says it runs and run it manually, everything works as expected (including the specified rule being ignored):

cd /home/ndepal/my-project
hadolint /home/ndepal/my-project/Dockerfile --no-color --ignore DL3059

results in:

/home/ndepal/my-project/Dockerfile:2 DL3006 warning: Always tag the version of an image explicitly
...

I'm using hadolint version Haskell Dockerfile Linter 2.3.0-no-git and only one hadolint executable exists on my system.

Is this supposed to be a supported feature? How else can I disable specific checks?

michaellzc commented 3 years ago

This has something to do with how arguments are passed to cross-spawn, mostly due to having spaces in the argument.

The correct configuration should be something like below

{
    "hadolint.cliOptions": [
        "--no-color",
        "--ignore",
        "DL3059"
    ],
    // ... more stuff
}

or

{
    "hadolint.cliOptions": [
        "--no-color",
        "--ignore=DL3059"
    ],
    // ... more stuff
}
michaellzc commented 3 years ago

I added the sample config to README for future references https://github.com/hadolint/hadolint/blob/master/README.md#configure

ndepal commented 3 years ago

Great, thanks a lot!