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

StandardBear: Add fixing capabilities #1984

Closed
wants to merge 1 commit into from

Conversation

Alexander-N
Copy link

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

@@ -68,7 +71,7 @@
}
"""

JSStandardBearTest = verify_local_bear(JSStandardBear,
JSStandardBearTestFiles = verify_local_bear(JSStandardBear,
valid_files=(good_file,),
invalid_files=(bad_file_indent,
Copy link
Collaborator

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.

@@ -68,7 +71,7 @@
}
"""

JSStandardBearTest = verify_local_bear(JSStandardBear,
JSStandardBearTestFiles = verify_local_bear(JSStandardBear,
valid_files=(good_file,),
Copy link
Collaborator

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.

@@ -68,7 +71,7 @@
}
"""

JSStandardBearTest = verify_local_bear(JSStandardBear,
JSStandardBearTestFiles = verify_local_bear(JSStandardBear,
valid_files=(good_file,),
Copy link
Collaborator

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):

bad_file_infix,
bad_file_undef,
bad_file_ifelse,
bad_file_func_name,))
Copy link
Collaborator

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.

bad_file_infix,
bad_file_undef,
bad_file_ifelse,
bad_file_func_name,))
Copy link
Collaborator

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.

@Alexander-N Alexander-N force-pushed the jsstandardbear-fix branch 8 times, most recently from b63b6ad to 00390c5 Compare August 8, 2017 17:11
@Alexander-N
Copy link
Author

This PR is ready for review. Anybody?

@sils
Copy link
Member

sils commented Oct 16, 2017

hey @Alexander-N can you add a testcase that actually tests that the patch is correct? Like if there's multiple results from standard does it properly figure out which part of the diff belongs to the right result? That's a thing that I'd definitely want to see in the tests

@gitmate-bot
Copy link
Collaborator

Comment on 9c7d939.

Body of HEAD commit contains too long lines. Commit body lines should not exceed 72 characters.

Origin: GitCommitBear, Section: commit.

@Alexander-N
Copy link
Author

Ok, done.

@Makman2
Copy link
Member

Makman2 commented Dec 18, 2017

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 👍

@Alexander-N Alexander-N force-pushed the jsstandardbear-fix branch 3 times, most recently from acc69bf to ef60ad5 Compare December 19, 2017 21:33
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
@Alexander-N
Copy link
Author

No Problem, lets do this :-)

Conflicts resolved.

"""
p = Popen(
('standard', '--stdin', '--fix'),
stdin=PIPE, stdout=PIPE, stderr=PIPE)
Copy link
Member

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?

Copy link
Author

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()
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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


Copy link
Member

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])
Copy link
Member

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?

Copy link
Author

@Alexander-N Alexander-N Dec 26, 2017

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.

@Alexander-N
Copy link
Author

I'm doubtful if it is worth moving on with this. What do you think? Are there any alternatives I'm not seeing?

@Makman2
Copy link
Member

Makman2 commented Dec 27, 2017

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:

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 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

L3C3 Invalid identifier
-- @unified-diff patch attached --
@@ ...
<unified diff goes here>
----------
L4C4 Invalid xyz
...

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 standard twice ;D). But this is probably very time-consuming^^

@Alexander-N
Copy link
Author

Yes I agree. Close, since the approach seems problematic.

@Alexander-N Alexander-N closed this Jan 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

JSStandardBear: Add fixing capabilities
4 participants