adrienverge / yamllint

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

ignore-from-file should use path of .yamllint.yaml as base, not current working dir #673

Open jellehelsen opened 4 months ago

jellehelsen commented 4 months ago

If there is a .yamllint.yaml at the base of the git repo, with ignore-from-file pointing to .gitignore, yamllint stops working in subdirectories. It will pickup the .yamllint.yaml file in a higher level directory, but then tries to find .gitignore in the current folder. This causes it to fail with FileNotFoundError: [Errno 2] No such file or directory: '.gitignore' .

Making this extra annoying is that editor plugins like flycheck, that use yamllint, tend to use the directory where the file is located as the working dir. So having ignore-from-file in your project level .yamllint.yaml breaks in-editor linting.

adrienverge commented 4 months ago

Hello and thanks for the report.

Yamllint doesn't handle Git repos differently than regular directories: if ignore-from-file points to a relative file, it will be searched from the current working directory. Looking for the ignore file in special locations (e.g. looking for a Git repo root in parent directories) would change current behavior and might annoy some users.

I suggest configuring flycheck to work like most Unix tools (if possible of course). Or maybe use an absolute path in ignore-from-file?

jellehelsen commented 4 months ago

It's not really git related. Imho it does not make sense use the .yamllint.yaml that is in a parent directory and then fail because it can't find the ignore-from-file that is in that same folder. Either don't use the .yamllint.yaml from a parent directory, or also find the files the .yamllint.yaml points to with a relative path. In the latter case the relative path should be relative to the .yamllint.yaml that is pointing to it. In the current implementation, yamllint breaks when you go into a child folder.