Open jayvdb opened 6 years ago
@AbdealiJK , https://github.com/hhatto/autopep8/issues/227 gives me an idea that might be a good basis for a GSoC size project.
We can already tell autopep8
which problems to fix using a combination of --select
and --line-range
.
Therefore, we could let pycodestyle do the error detection, with the usual 'coala ignore' processing and the PycodestyleBear settings, and then pass only the resulting filtered errors to autopep8 to generate fixes only for.
The fixes could then be applied by the bear and pycodestyle re-run on the file to verify that the fixes satisfied the pycodestyle rule, and bad fixes rejected.
This might be done by chaining PycodestyleBear and PEP8Bear together, would involve serious enhancements to coala core, or PycodestyleBear could be enhanced to also use autopep8 to get fixes. Even if the former approach is designed well, it still may not be a very re-usable as it would depend on two bears having the same codes for a problem. That does occur in other languages, but probably not very frequently. (I know the markdown style tools have a set of similar codes used across different programs written in Python and Node). Invoking autopep8 in PycodestyleBear would still likely 'require' some improvements to coala core, to create fixes for error reports, but they would be less complicated.
Then the autopep8 part of the project would be to add the ability to specify column numbers with --range
in addition to line numbers.
Adding a few things:
We can safely assume that autopep8 won't expand to Pycodestyle-like error reporting capabilities anytime soon.
There already was an attempt to use Pycodestyle and autopep8 together but this approach tries to run Pycodestyle alongside autopep8 and assumes that errors detected by Pycodestyle will be in the same order as autopep8 and equal to the set of errors detected by the latter.
Pycodestyle (the library) is solely focused on detecting PEP8 violations and not fixing them. We might want to leave that behaviour as is in its bear. Instead, creating a new bear
Then the autopep8 part of the project would be to add the ability to specify column numbers with --range in addition to line numbers.
This shouldn't be required with the following workflow:
--select <error detected by pycodestyle>
on the line with the issueI don't see why implementing --col-range
should be necessary.
I don't see why implementing --col-range should be necessary.
This is because one single line could've multiple same types of errors. Through --column-range
we could select the ones for which we need a fix.
Example: If the file contains:
print( sys.path, ( 2))
Then the error would be:
test.py:1:7: E201 whitespace after '('
print( sys.path, ( 2))
^
test.py:1:19: E201 whitespace after '('
print( sys.path, ( 2))
By running autopep8 with --select=E201
it would fix both of the errors. But by specifying column-range
we could select one of them, giving even more control.
By running autopep8 with --select=E201 it would fix both of the errors. But by specifying column-range we could select one of them, giving even more control.
Yes, but PycodestyleBear and PEP8Bear generate only one result for a set of line-error pairs:
bad.py
[ 5] print(·'test'·)·
**** PycodestyleBear (E201) [Section: cli | Severity: NORMAL] ****
! ! E201 whitespace after '('
[ ] *0. Do (N)othing
[ ] 1. (O)pen file
[ ] 2. Add (I)gnore comment
[ ] Enter number (Ctrl-D to exit):
! ! The code does not comply to PEP8.
[----] /home/areebbeigh/Documents/sandbox/Python/linters/bad.py
[++++] /home/areebbeigh/Documents/sandbox/Python/linters/bad.py
[ 5] print( 'test' )
[ 5] print('test')
[ ] *0. Do (N)othing
[ ] 1. (O)pen file
[ ] 2. (A)pply patch
[ ] 3. Add (I)gnore comment
[ ] 4. Show Applied (P)atches
[ ] 5. (G)enerate patches
[ ] Enter number (Ctrl-D to exit):
So we wouldn't really be using column-range anywhere in the bears
The improvement would be for the autopep8 rather than for the bears. An attempt was already made by a GCI student https://github.com/hhatto/autopep8/pull/452.
Hm yeah, looks like column range is indeed needed here. It's only the PEP8Bear that patches multiple problems in a line at once, PycodestyleBear reports them one by one.
Please what's the status for this project
@jayvdb will you mentor this project this year?
I would like to work on this
This issue is reserved under the GSoC project Improve Generic Bear Quality.
Lots of opportunity to add fixes.