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

Remove one false positive on pipe-fail rule #1477

Merged
merged 1 commit into from Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ansiblelint/rules/ShellWithoutPipefail.py
Expand Up @@ -20,7 +20,7 @@ class ShellWithoutPipefail(AnsibleLintRule):
tags = ['command-shell']
version_added = 'v4.1.0'

_pipefail_re = re.compile(r"^\s*set.*[+-][A-z]*o\s*pipefail")
_pipefail_re = re.compile(r"^\s*set.*[+-][A-z]*o\s*pipefail", re.M)
_pipe_re = re.compile(r"(?<!\|)\|(?!\|)")

def matchtask(self, task: Dict[str, Any]) -> Union[bool, str]:
Expand All @@ -39,6 +39,6 @@ def matchtask(self, task: Dict[str, Any]) -> Union[bool, str]:

return bool(
self._pipe_re.search(unjinjad_cmd)
and not self._pipefail_re.match(unjinjad_cmd)
and not self._pipefail_re.search(unjinjad_cmd)
and not convert_to_boolean(task['action'].get('ignore_errors', False))
)
6 changes: 6 additions & 0 deletions test/TestShellWithoutPipefail.py
Expand Up @@ -48,6 +48,12 @@
set -eo pipefail
false | cat

- name: pipeline with pipefail not at first line
shell: |
echo foo
set -eo pipefail
false | cat

- name: pipeline without pipefail, ignoring errors
shell: false | cat
ignore_errors: true
Expand Down