Skip to content

Commit

Permalink
Remove one false positive on pipe-fail rule (#1477)
Browse files Browse the repository at this point in the history
Avoid triggering the rule if pipefail string is used anywhere inside
the script instead of only the first line. We can assume user knew
what to do if it used it.

Fixes: #663
  • Loading branch information
ssbarnea committed Mar 18, 2021
1 parent c4f7385 commit 470e3c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 470e3c5

Please sign in to comment.