adrienverge / yamllint

A linter for YAML files.
GNU General Public License v3.0
2.82k stars 266 forks source link

Can `ignore-from-file` not error if file not found? #611

Open paddyroddy opened 9 months ago

paddyroddy commented 9 months ago

I'm aware this might sound like a rogue request, but I have a set of "master" pre-commit hooks where I have something like this as my args https://github.com/paddyroddy/.github/blob/2134df78ef3834b8af751fadc172a72ad3992d17/precommit/general/general-hooks.yml#L2-L16. However, when I use this in a repo without the .yamlignore file, I get FileNotFoundError: [Errno 2] No such file or directory: '.yamlignore'. Makes perfect sense, but what if I don't mind?

adrienverge commented 9 months ago

If I understood correctly, I assume you meant .yamlignore instead of .yamllint, and you want yamllint not to care if this file is referenced from the config file, but doesn't exist on disk.

This use-case is interesting, but I guess most users prefer yamllint to warn them if something from their conf file is wrong or missing.

If possible, I suggest dynamically adding ignore-from-file: .yamlignore in your --config-data depending whether the file exists or not.

paddyroddy commented 9 months ago

If I understood correctly, I assume you meant .yamlignore instead of .yamllint, and you want yamllint not to care if this file is referenced from the config file, but doesn't exist on disk.

Yep, sorry that was a typo, I do mean .yamlignore.

This use-case is interesting, but I guess most users prefer yamllint to warn them if something from their conf file is wrong or missing.

Completely understand why most users wouldn't want this, but I think of it akin to a missing .gitignore - generally advisable, but not required.

If possible, I suggest dynamically adding ignore-from-file: .yamlignore in your --config-data depending whether the file exists or not.

Hmm... Good idea. Although not sure how I'd do it in practice.

perlpunk commented 7 months ago

I also think that in case of ignore-from-file it should not complain about a missing file. One use case is: We would like to symlink a .yamllint file from an external, common repo (either used with git-submodule or git-subrepo) that has this:

ignore-from-file: [.gitignore, .yamlignore]

and the only thing which would differ for individual repos would be the files we want to ignore. By default linking .yamllint would just work, even if .yamlignore doesn't exist. But I can understand the reasons for the current behaviour as well.

adrienverge commented 6 months ago

That's interesting, thanks for the feedback :+1:

I'm curious about what more users think about this.

42atomys commented 6 months ago

We currently facing the same "issue" when using a dynamic lint across multiples repositories how don't have .gitignore or .yamlignore file.

The only workaround actually are to dynamically provide a config-data with a check of file exist before as @adrienverge say before. For us ignore this error are the good practice, but we can think about a warn log when the file are not found to alert the user (or create a flag to toggle between error and no-error. Not a big fan for me but that is a personal opinion)