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

Prevent parseable option from changing JSON output format #1730

Merged
merged 1 commit into from Oct 1, 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/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