diff --git a/tests/test_cli.py b/tests/test_cli.py index 9b7801d..ca3056c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -549,6 +549,20 @@ class CommandLineTestCase(unittest.TestCase): self.assertEqual( (ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, '')) + def test_run_format_github(self): + path = os.path.join(self.wd, 'a.yaml') + + with RunContext(self) as ctx: + cli.run((path, '--format', 'github')) + expected_out = ( + '::error file=%s,line=2,col=4::[trailing-spaces] trailing' + ' spaces\n' + '::error file=%s,line=3,col=4::[new-line-at-end-of-file] no' + ' new line character at the end of file\n' + % (path, path)) + self.assertEqual( + (ctx.returncode, ctx.stdout, ctx.stderr), (1, expected_out, '')) + def test_run_read_from_stdin(self): # prepares stdin with an invalid yaml string so that we can check # for its specific error, and be assured that stdin was read diff --git a/yamllint/cli.py b/yamllint/cli.py index 311d66c..5701fa3 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -85,6 +85,19 @@ class Format(object): line += ' \033[2m(%s)\033[0m' % problem.rule return line + @staticmethod + def github(problem, filename): + line = '::' + line += problem.level + line += ' file=' + filename + ',' + line += 'line=' + format(problem.line) + ',' + line += 'col=' + format(problem.column) + line += '::' + if problem.rule: + line += '[' + problem.rule + '] ' + line += problem.desc + return line + def show_problems(problems, file, args_format, no_warn): max_level = 0 @@ -96,6 +109,8 @@ def show_problems(problems, file, args_format, no_warn): continue if args_format == 'parsable': print(Format.parsable(problem, file)) + elif args_format == 'github': + print(Format.github(problem, file)) elif args_format == 'colored' or \ (args_format == 'auto' and supports_color()): if first: @@ -131,7 +146,8 @@ def run(argv=None): action='store', help='custom configuration (as YAML source)') parser.add_argument('-f', '--format', - choices=('parsable', 'standard', 'colored', 'auto'), + choices=('parsable', 'standard', 'colored', 'github', + 'auto'), default='auto', help='format for parsing output') parser.add_argument('-s', '--strict', action='store_true',