Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import ignores from .gitignore #360

Closed
sandstrom opened this issue Feb 15, 2021 · 4 comments
Closed

Import ignores from .gitignore #360

sandstrom opened this issue Feb 15, 2021 · 4 comments

Comments

@sandstrom
Copy link

sandstrom commented Feb 15, 2021

Problem

Right now there is a lot of duplication between our yaml-lint ignore directives, and our .gitignore files. It would be neat if we could import from gitignore, via e.g. import_ignore: .gitignore.

How it could work

Something like:

# using the default rules
extends: default

# skip everything ignored by .gitignore
import_ignore: ".gitignore"

rules:
  octal-values: enable
  #

Since I think yaml-lint is using the same ignore format as .gitignore, maybe it's fairly easy to import? Would also allow keeping the ignore list in a separate file.

Open Questions

  • How should conflicting rules be solved? Ideally with "last rule wins". That way one can override or adjust directives imported from .gitignore if needed.
@adrienverge
Copy link
Owner

I understand the use-case. It could be done using a conf option ignore-from-file: .gitignore, mutually exclusive with ignore. Do you want to implement it?

@sandstrom
Copy link
Author

@adrienverge Mutually exclusive would preclude making adjustments to the ignore directives, or overriding !keep-me.file. Are there technical reasons making it more complicated to allow mixing ignore with import_ignore?

I'd love to, but I haven't spent many hours in Python. So not sure I could.

@ndrwnaguib
Copy link
Contributor

ndrwnaguib commented Feb 19, 2021

@adrienverge I'm willing to implement that. Would you assign me and give me few tips? :))

Are you sure tho that you want it to be mutually exclusive with ignore? Because, what if you want to ignore linting for specific files but not ignoring committing them (considering the .gitignore case)

I think the lines to be modified would be:

yamllint/yamllint/config.py

Lines 100 to 105 in 8f68248

if 'ignore' in conf:
if not isinstance(conf['ignore'], str):
raise YamlLintConfigError(
'invalid config: ignore should contain file patterns')
self.ignore = pathspec.PathSpec.from_lines(
'gitwildmatch', conf['ignore'].splitlines())

Confirm, please?

@adrienverge
Copy link
Owner

@adrienverge Mutually exclusive would preclude making adjustments to the ignore directives, or overriding !keep-me.file. Are there technical reasons making it more complicated to allow mixing ignore with import_ignore?

Being able to make adjustments makes sense, I'm not opposed to it. It's just that it's more complex to implement: more code and more tests are needed.

About the option name, I'd prefer staying consistent with other configuration keys. For example something like ignore-from-file: .gitignore, or even better: ignore-from-files: [.gitignore, other-file].

@adrienverge I'm willing to implement that. Would you assign me and give me few tips? :))

Great! I suggest looking carefully at a few commits that implemented new features, and reproduce the same. Note that they need documentation, test every corner case, and have a commit message that describes what they do. Please save my time and open the PR once it's 100% ready.

ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Mar 1, 2021
ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Mar 2, 2021
ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Mar 2, 2021
ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Mar 17, 2021
…y optioncloses adrienverge#360, add support for `ignore-from-file` key option
ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Mar 17, 2021
…y optioncloses adrienverge#360, add support for `ignore-from-file` key option
ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Mar 17, 2021
ndrwnaguib added a commit to ndrwnaguib/yamllint that referenced this issue Jul 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants