From baae556a7adb99426c764f982a9b027a9e4cb55f Mon Sep 17 00:00:00 2001 From: Saksham Bansal Date: Sun, 8 Apr 2018 17:51:31 +0530 Subject: [PATCH] PrettierLintBear.py: Fix syntax error regex Fixes https://github.com/coala/coala-bears/issues/2365 --- bears/js/PrettierLintBear.py | 12 ++++++++---- tests/js/PrettierLintBearTest.py | 10 +++++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/bears/js/PrettierLintBear.py b/bears/js/PrettierLintBear.py index e078a7c8b9..b253a18fed 100644 --- a/bears/js/PrettierLintBear.py +++ b/bears/js/PrettierLintBear.py @@ -23,13 +23,17 @@ class PrettierLintBear: 'Multi-line objects'} SEE_MORE = 'https://prettier.io/' - regex = re.compile(r'L(?P\d+)C(?P\d+): (?P.*)') + regex = re.compile( + r'(?PSyntaxError:.*) ' + r'\((?P\d+):(?P\d+)\)') def process_output(self, output, filename, file): stdout, stderr = output - yield from self.process_output_corrected(stdout, filename, file) - yield from self.process_output_regex(stderr, filename, file, - self.regex) + if stdout == '\n': + yield from self.process_output_regex(stderr, filename, file, + self.regex) + else: + yield from self.process_output_corrected(stdout, filename, file) @staticmethod def create_arguments(filename, file, config_file): diff --git a/tests/js/PrettierLintBearTest.py b/tests/js/PrettierLintBearTest.py index 2e58409f81..cb87921f2b 100644 --- a/tests/js/PrettierLintBearTest.py +++ b/tests/js/PrettierLintBearTest.py @@ -26,7 +26,10 @@ bad_quotes = """const a = () => 'Foo bar';""" -bad_parentheses = """function b(){ +bad_syntax_function = """function b(){ +""" + +bad_syntax_if = """if x y """ good_parentheses = """function b() {} @@ -47,5 +50,6 @@ good_indent,), invalid_files=(bad_file, bad_quotes, - bad_parentheses, - bad_indent,)) + bad_indent, + bad_syntax_if, + bad_syntax_function,))