-
Notifications
You must be signed in to change notification settings - Fork 581
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
StandardBear: Add fixing capabilities #1984
Conversation
tests/js/JSStandardBearTest.py
Outdated
@@ -68,7 +71,7 @@ | |||
} | |||
""" | |||
|
|||
JSStandardBearTest = verify_local_bear(JSStandardBear, | |||
JSStandardBearTestFiles = verify_local_bear(JSStandardBear, | |||
valid_files=(good_file,), | |||
invalid_files=(bad_file_indent, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E128 continuation line under-indented for visual indent'
PycodestyleBear (E128), severity NORMAL, section autopep8
.
tests/js/JSStandardBearTest.py
Outdated
@@ -68,7 +71,7 @@ | |||
} | |||
""" | |||
|
|||
JSStandardBearTest = verify_local_bear(JSStandardBear, | |||
JSStandardBearTestFiles = verify_local_bear(JSStandardBear, | |||
valid_files=(good_file,), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E128 continuation line under-indented for visual indent'
PycodestyleBear (E128), severity NORMAL, section autopep8
.
tests/js/JSStandardBearTest.py
Outdated
@@ -68,7 +71,7 @@ | |||
} | |||
""" | |||
|
|||
JSStandardBearTest = verify_local_bear(JSStandardBear, | |||
JSStandardBearTestFiles = verify_local_bear(JSStandardBear, | |||
valid_files=(good_file,), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code does not comply to PEP8.
PEP8Bear, severity NORMAL, section autopep8
.
The issue can be fixed by applying the following patch:
--- a/tests/js/JSStandardBearTest.py
+++ b/tests/js/JSStandardBearTest.py
@@ -72,14 +72,14 @@
"""
JSStandardBearTestFiles = verify_local_bear(JSStandardBear,
- valid_files=(good_file,),
- invalid_files=(bad_file_indent,
- bad_file_quote,
- bad_file_semicolon,
- bad_file_infix,
- bad_file_undef,
- bad_file_ifelse,
- bad_file_func_name,))
+ valid_files=(good_file,),
+ invalid_files=(bad_file_indent,
+ bad_file_quote,
+ bad_file_semicolon,
+ bad_file_infix,
+ bad_file_undef,
+ bad_file_ifelse,
+ bad_file_func_name,))
class JSStandardBearTest(LocalBearTestHelper):
25f29f0
to
88ae03a
Compare
tests/js/JSStandardBearTest.py
Outdated
bad_file_infix, | ||
bad_file_undef, | ||
bad_file_ifelse, | ||
bad_file_func_name,)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E501 line too long (80 > 79 characters)'
PycodestyleBear (E501), severity NORMAL, section autopep8
.
tests/js/JSStandardBearTest.py
Outdated
bad_file_infix, | ||
bad_file_undef, | ||
bad_file_ifelse, | ||
bad_file_func_name,)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than allowed. (80 > 79)
LineLengthBear, severity NORMAL, section linelength
.
b63b6ad
to
00390c5
Compare
This PR is ready for review. Anybody? |
hey @Alexander-N can you add a testcase that actually tests that the patch is correct? Like if there's multiple results from |
00390c5
to
9c7d939
Compare
Comment on 9c7d939. Body of HEAD commit contains too long lines. Commit body lines should not exceed 72 characters. Origin: GitCommitBear, Section: |
9c7d939
to
5c942ef
Compare
5c942ef
to
da82769
Compare
Ok, done. |
Sorry it took so long and we haven't done a review :/ We are a bit out of manpower in general for such things, so I hope you can understand :/ If you still want to give it a try, do you mind to resolve the conflicts and push again? I'm gonna review this then 👍 |
acc69bf
to
ef60ad5
Compare
Get the corrected code by piping to "standard". If there are several issues in a single line, the messages are displayed together to to make it possible to understand the fix. Closes coala#1952
ef60ad5
to
d66d7d3
Compare
No Problem, lets do this :-) Conflicts resolved. |
""" | ||
p = Popen( | ||
('standard', '--stdin', '--fix'), | ||
stdin=PIPE, stdout=PIPE, stderr=PIPE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have to execute standard
twice to get the corrected code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want the messages and the corrected code I see no other way.
('standard', '--stdin', '--fix'), | ||
stdin=PIPE, stdout=PIPE, stderr=PIPE) | ||
p.stdin.write(bytes(''.join(old_code), 'UTF-8')) | ||
out, err = p.communicate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to be careful, this can deadlock if the buffers get full (and because we might operate with larger files, this can happen). Are there alternatives that take care of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe temporary files instead? I checked some bigger files, standard itself is failing if ~500kB files are piped. I should also check the return code at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be special functions somewhere to call a program with stdin and retrieve stdout and stderr without deadlocking.
I should also check the return code at this point.
Oh yeah good point 👍
from bears.js.JSStandardBear import JSStandardBear | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change ;)
diff = None | ||
if corrected_code: | ||
diff = Diff(file) | ||
diff.modify_line(line_number, corrected_code[line_number-1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can a patch span multiple lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that I'm aware of.
But looking at this again, it's not robust at all. If standards "--fix" would remove a line and add one at some other place, the patches could be wrong.
I'm doubtful if it is worth moving on with this. What do you think? Are there any alternatives I'm not seeing? |
Hm this worries me a bit:
I don't know the tools behaviour, so I can't say what edge cases might occur. What's actually best is if the tool itself would print out a format that assigns patches to issue messages, something like
Usually tools don't have something like this sadly (could be actually worth to define one - or maybe a few - such formats in a coala cEP). This would be the optimal solution, having an upstream contribution doing this (then we also don't have to invoke |
Yes I agree. Close, since the approach seems problematic. |
The corrected code is retrieved by piping to JSStandard. If there
several issues in a single line, the messages are displayed together to
make it easy to understand the proposed fix.
Closes #1952