From e018da186ebde67559464286fd33763e422e7f71 Mon Sep 17 00:00:00 2001 From: QuentinN42 Date: Thu, 10 Feb 2022 13:35:39 +0100 Subject: [PATCH] feat: fixed some isues --- tests/test_format.py | 6 ++++-- yamllint/format.py | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/tests/test_format.py b/tests/test_format.py index 227f865..a1c4261 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -143,8 +143,8 @@ class FormatersTestCase(unittest.TestCase): (GithubFormater(True), ONE_WARNING, ""), (ColoredFormater(True), ONE_WARNING, ""), (StandardFormater(True), ONE_WARNING, ""), - (JSONFormater(True), ONE_WARNING, '[\n {\n "line": 1,\n "column": 2,\n "rule": "my-rule",\n "level": "warning",\n "message": "desc of warn",\n "path": "file1.yml"\n }\n]\n'), - (CodeclimateFormater(True), ONE_WARNING, '[\n {\n "type": "issue",\n "check_name": "my-rule",\n "description": "desc of warn",\n "content": "desc of warn (my-rule)",\n "categories": [\n "Style"\n ],\n "location": {\n "path": "file1.yml",\n "positions": {\n "begin": {\n "line": 1,\n "column": 2\n }\n }\n },\n "remediation_points": 1000,\n "severity": "minor"\n }\n]\n'), + (JSONFormater(True), ONE_WARNING, '[]\n'), + (CodeclimateFormater(True), ONE_WARNING, '[]\n'), (ParsableFormater(True), ONE_ERROR, 'file1.yml:1:2: [error] desc of error (my-rule)\n'), (GithubFormater(True), ONE_ERROR, '::group::file1.yml\n::error file=file1.yml,line=1,col=2::1:2 [my-rule] desc of error\n::endgroup::\n\n'), (ColoredFormater(True), ONE_ERROR, '\x1b[4mfile1.yml\x1b[0m\n \x1b[2m1:2\x1b[0m \x1b[31merror\x1b[0m desc of error \x1b[2m(my-rule)\x1b[0m\n\n'), @@ -154,6 +154,8 @@ class FormatersTestCase(unittest.TestCase): ) @ddt.unpack def test_all_formaters(self, inst, inp, ret): + if inst.show_problems_for_all_files(inp) != ret: + print(f"\n{inst.__class__.__name__}\n" + inst.show_problems_for_all_files(inp)) self.assertEqual( inst.show_problems_for_all_files(inp), ret diff --git a/yamllint/format.py b/yamllint/format.py index 95c7712..850bfa1 100644 --- a/yamllint/format.py +++ b/yamllint/format.py @@ -252,7 +252,16 @@ class JSONFormater(Formater): def show_problems_for_file(self, problems, file): """Show all problems of a specific file.""" - return list(map(self.show_problem, problems, [file] * len(problems))) + return list( + filter( + lambda x: x["level"] == "error" or not self.no_warn, + map( + self.show_problem, + problems, + [file] * len(problems) + ) + ) + ) def show_problem(self, problem, file): """Show all problems of a specific file. @@ -332,7 +341,16 @@ class CodeclimateFormater(Formater): def show_problems_for_file(self, problems, file): """Show all problems of a specific file.""" - return list(map(self.show_problem, problems, [file] * len(problems))) + return list( + filter( + lambda x: x["severity"] == "major" or not self.no_warn, + map( + self.show_problem, + problems, + [file] * len(problems) + ) + ) + ) def show_problem(self, problem, file): """Show all problems of a specific file.