Skip to content

Commit

Permalink
Avoid altering format when parseable option is configured
Browse files Browse the repository at this point in the history
This bug was originally reported against ansible-language-server but
it proved to be caused by a bug inside the linter.

Fixes: ansible/ansible-language-server#43
  • Loading branch information
ssbarnea committed Sep 30, 2021
1 parent 213eb4d commit 1e60b6b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ansiblelint/app.py
Expand Up @@ -73,10 +73,10 @@ def choose_formatter_factory(
r = formatters.QuietFormatter
elif options_list.parseable_severity:
r = formatters.ParseableSeverityFormatter
elif options_list.parseable or options_list.format == 'pep8':
r = formatters.ParseableFormatter
elif options_list.format == 'codeclimate':
r = formatters.CodeclimateJSONFormatter
elif options_list.parseable or options_list.format == 'pep8':
r = formatters.ParseableFormatter
return r


Expand Down
19 changes: 19 additions & 0 deletions test/TestCodeclimateJSONFormatter.py
@@ -1,6 +1,8 @@
"""Test the codeclimate JSON formatter."""
import json
import pathlib
import subprocess
import sys
from typing import List, Optional

import pytest
Expand Down Expand Up @@ -86,3 +88,20 @@ def test_validate_codeclimate_schema(self) -> None:
assert single_match['location']['path'] == self.matches[0].filename
assert 'lines' in single_match['location']
assert single_match['location']['lines']['begin'] == self.matches[0].linenumber


def test_code_climate_parsable_ignored() -> None:
"""Test that -p option does not alter codeclimate format."""
cmd = [
sys.executable,
"-m",
"ansiblelint",
"-v",
"-p",
]
file = "examples/playbooks/empty_playbook.yml"
result = subprocess.run([*cmd, file], check=False)
result2 = subprocess.run([*cmd, "-p", file], check=False)

assert result.returncode == result2.returncode
assert result.stdout == result2.stdout

0 comments on commit 1e60b6b

Please sign in to comment.