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

PrettierLintBear.py: Fix syntax error regex #2414

Merged
merged 1 commit into from
Apr 21, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bears/js/PrettierLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ class PrettierLintBear:
CAN_FIX = {'Formatting'}
SEE_MORE = 'https://prettier.io/'

regex = re.compile(r'L(?P<line>\d+)C(?P<column>\d+): (?P<message>.*)')
regex = re.compile(
r'(?P<message>SyntaxError:.*) '
r'\((?P<line>\d+):(?P<column>\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':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this if needed?

Copy link
Contributor Author

@saksham189 saksham189 Apr 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is a syntax error stdout has a \n. So we should only show the syntax error result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the regex being applied to stdout will ignore the \n..?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no we are using process_output_corrected since the bear prints corrected output to stdout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That feels like a bug in process_output_corrected. If there was an error, the linter can only emit \n on stdout. It shouldnt decide that means the file should be blanked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Expand Down
10 changes: 7 additions & 3 deletions tests/js/PrettierLintBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -47,5 +50,6 @@
good_indent,),
invalid_files=(bad_file,
bad_quotes,
bad_parentheses,
bad_indent,))
bad_indent,
bad_syntax_if,
bad_syntax_function,))