From 0077b2b87e16dcc15cd30828a7b464bed985724a Mon Sep 17 00:00:00 2001 From: Fransiskus Febryan Date: Mon, 5 Nov 2018 12:26:31 +0700 Subject: [PATCH] GixyBear.py: Add GixyBear This commit adds GixyBear. Closes https://github.com/coala/coala-bears/issues/1724 --- bears/configfiles/GixyBear.py | 33 +++++++++++++++++++++++++++++++ tests/configfiles/GixyBearTest.py | 25 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 bears/configfiles/GixyBear.py create mode 100644 tests/configfiles/GixyBearTest.py diff --git a/bears/configfiles/GixyBear.py b/bears/configfiles/GixyBear.py new file mode 100644 index 0000000000..1a2e2110b7 --- /dev/null +++ b/bears/configfiles/GixyBear.py @@ -0,0 +1,33 @@ +import json + +from coalib.bearlib.abstractions.Linter import linter +from dependency_management.requirements.PipRequirement import PipRequirement +from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY +from coalib.results.Result import Result + + +@linter(executable='gixy') +class GixyBear: + """ + A wrapper for coala around Gixy + + see for more information about the tool + """ + REQUIREMENTS = {PipRequirement('gixy', '0.1.*')} + + severity_map = {'HIGH': RESULT_SEVERITY.MAJOR, + 'MEDIUM': RESULT_SEVERITY.NORMAL, + 'LOW': RESULT_SEVERITY.INFO} + + @staticmethod + def create_arguments(filename, file, config_file): + return ('--format=json', filename) + + def process_output(self, output, filename, file): + output = json.loads(output) if output else [] + for issue in output: + yield Result.from_values( + origin=self, + message=issue['summary'], + severity=self.severity_map[issue['severity']], + file=filename) diff --git a/tests/configfiles/GixyBearTest.py b/tests/configfiles/GixyBearTest.py new file mode 100644 index 0000000000..e8567fa9ae --- /dev/null +++ b/tests/configfiles/GixyBearTest.py @@ -0,0 +1,25 @@ + +from bears.configfiles.GixyBear import GixyBear +from coalib.testing.LocalBearTestHelper import verify_local_bear + +good_file = """ +server { + location ~ \.(gif|jpg|png)$ { + root /data/images; + } +} +""" + +bad_file = """ +http{ + server{ + location ~ /proxy/(.*)/(.*)/(.*)$ { + proxy_pass $1://$2/$3; + } + } +} +""" + +GixyBearTest = verify_local_bear(GixyBear, + valid_files=(good_file, ), + invalid_files=(bad_file, ))