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

lint silently ignores content outside current directory even when passed as argument #3284

Closed
cidrblock opened this issue Apr 13, 2023 · 1 comment · Fixed by #3507
Closed
Assignees
Labels

Comments

@cidrblock
Copy link
Contributor

Given the following dir structure

.
├── other_dir
└── stuff
    └── lint
        ├── borked
        │   ├── playbook.yml
        │   └── roles
        │       ├── uh-huh
        │       │   └── tasks
        │       │       └── main.yml
        │       └── yep
        │           └── tasks
        │               └── main.yml
        └── no_errors
            ├── playbook.yml
            └── roles
                └── no-errors-here
                    └── tasks
                        └── main.yml

Running ansible-lint from other_dir reports no errors

other_dir pwd && ansible-lint /home/bthornto/github/lint_bug/stuff 
/home/bthornto/github/lint_bug/other_dir

Passed with production profile: 0 failure(s), 0 warning(s) on 0 files.

Running from /tmp reports no errors

(venv) m910x ➜  /tmp pwd && ansible-lint /home/bthornto/github/lint_bug/stuff
/tmp

Passed with production profile: 0 failure(s), 0 warning(s) on 0 files.

Running from $HOME is fine (in a parent of the dest to linted)

pwd && ansible-lint /home/bthornto/github/lint_bug/stuff
/home/bthornto
WARNING  Listing 12 violation(s) that are fatal

Tested with volume mounts in creator ee as well

@ssbarnea ssbarnea added the bug label Apr 14, 2023
@ssbarnea
Copy link
Member

While it looks like a bug, it appears to be just a side effect of current logic.

In absence of a config file or git repository, which do defined the location of the project_dir, the linter will assume CWD as being the current project.

This means that if your are inside user home and try to lint a file from outside like /tmp the linter will not do anything as it will skip the file.

The logic about ignoring any files outside the current project makes sense as we never wanted to lint code that the user cannot fix.

Still passing a single folder to linter might make people think that this should only chdir to it and run from there.

What if user is passing more than one argument, ansible-lint /tmp/foo /var/foo? We cannot have more than one project_dir.

As a safety measure, we should probably make the linter return an error code if it did finish without linting any files (everything was skipped). At least it should prevent accidents. Still, this will not fix this issue.

I could add some code that would detect if only one argument was given that is a folder outside current directory and assume that this is a project_dir and chdir to it. I should mention that we already have a --project-dir argument in linter, but almost nobody is using it. For example the current bug can be avoided if linter would be called with ansible-lint --project-dir=/tmp/foo /tmp/foo/playbook.yml.

Any suggestions?

@ssbarnea ssbarnea changed the title lint only lints if in directory ancestory lint silently ignores content outside current directory even when passed as argument Apr 14, 2023
@ssbarnea ssbarnea self-assigned this Apr 18, 2023
ssbarnea added a commit that referenced this issue Apr 18, 2023
This change will make the linter return a special exit code when
no files are analyzed. This should prevent accidents related to
misconfiguration via config file excludes or wrong arguments being
passed to it. The returned exit code is unique and returned only
for this special case.

Related: #3284
ssbarnea added a commit that referenced this issue Apr 18, 2023
This change will make the linter return a special exit code when
no files are analyzed. This should prevent accidents related to
misconfiguration via config file excludes or wrong arguments being
passed to it. The returned exit code is unique and returned only
for this special case.

Related: #3284
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants