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

Fixed pre-commit hooks #612

Merged
merged 1 commit into from Oct 31, 2019
Merged

Fixed pre-commit hooks #612

merged 1 commit into from Oct 31, 2019

Conversation

ssbarnea
Copy link
Member

Assures that when used as a pre-commit hook, ansible-lint is not
given each file as argument. This is needed because ansible-lint
needs to detect the code-base layout in order to figure-out which
YAML files are playbooks, tasks or vars files.

Previously the hook was passing all files that where matching its
filters and ansible-lint would assume they were playbooks. This made it
give false positives.

This change also adds the --force-color because without it ansible-lint
would fail to detect the TTY and avoid using colors.

Fixes: #611
Signed-off-by: Sorin Sbarnea ssbarnea@redhat.com

Assures that when used as a pre-commit hook, ansible-lint is not
given each file as argument. This is needed because ansible-lint
needs to detect the code-base layout in order to figure-out which
YAML files are playbooks, tasks or vars files.

Previously the hook was passing all files that where matching its
filters and ansible-lint would assume they were playbooks. This made it
give false positives.

This change also adds the --force-color because without it ansible-lint
would fail to detect the TTY and avoid using colors.

Fixes: #611
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
@ssbarnea
Copy link
Member Author

Those wanting to test it before it merges can run this:

pre-commit try-repo https://github.com/ssbarnea/ansible-lint --rev fix/pre-commit

This would call pre-commit hook from this branch.

@webknjaz
Copy link
Member

Hm... Not sure if that's what I want — it breaks the assumption that pre-commit would only lint changed bits.

Those wanting to test it before it merges

It'd be interesting to add this right to the CI.

I see it implemented as pre-commit try-repo .git

@ssbarnea
Copy link
Member Author

@webknjaz I don't think that ansible-lint is the kind of linter that can be used on files without context. What if you try to install newer version? The newer version could find bugs in files that were not touched.

And yes, the idea about adding to CI is great!

@webknjaz webknjaz merged commit 6cf42cb into ansible:master Oct 31, 2019
@webknjaz
Copy link
Member

That command for CI doesn't work as I expected. It probably needs to be reported to pre-commit.

@@ -6,6 +6,9 @@
- id: ansible-lint
name: Ansible-lint
description: This hook runs ansible-lint.
entry: ansible-lint
entry: ansible-lint --force-color .

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--force-color shouldn't be necessary as of pre-commit 1.19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in fact, it's the wrong thing to do if you're using a CI system, etc. which doesn't have color escapes

# do not pass files to ansible-lint, see:
# https://github.com/ansible/ansible-lint/issues/611
pass_filenames: false
always_run: true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this ~usually isn't the setting you want here -- this'll do a lot of unnecessary work on every commit (linting your entire codebase all the time) -- generally you want to optimize for quickness on commit and being thorough in CI (via --all-files, etc.)

@asottile
Copy link

That command for CI doesn't work as I expected. It probably needs to be reported to pre-commit.

you'd want pre-commit try-repo . --all-files or something like that

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

Successfully merging this pull request may close these issues.

when run as pre-commit hook ansible-lint silently fails to lint
3 participants