yamllint icon indicating copy to clipboard operation
yamllint copied to clipboard

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

Open paddyroddy opened this issue 7 months ago • 5 comments

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?

paddyroddy avatar Nov 20 '23 17:11 paddyroddy

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.

adrienverge avatar Nov 21 '23 22:11 adrienverge

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.

paddyroddy avatar Nov 21 '23 22:11 paddyroddy

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.

perlpunk avatar Jan 22 '24 21:01 perlpunk

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

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

adrienverge avatar Jan 27 '24 08:01 adrienverge

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)

42atomys avatar Feb 15 '24 11:02 42atomys