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

PyImportSortBear.py: Show incorrectly sorted imports #886

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wimpykid26
Copy link

This will ensure that coala is
able to display the import statements
that are sorted incorrectly.

Closes #397

@gitmate-bot
Copy link
Collaborator

Thanks for your contribution!

Reviewing pull requests take really a lot of time and we're all volunteers. Please make sure you go through the following check list and complete them all before pinging someone for a review.

As you learn things over your Pull Request please help others on the chat and on PRs to get their stuff right as well!

@gitmate-bot
Copy link
Collaborator

Comment on 30cbdbc.

Shortlog of HEAD commit is 2 character(s) longer than the limit (52 > 50).

GitCommitBear, severity NORMAL, section commit.

@wimpykid26
Copy link
Author

@sils could you please review ?

@sils
Copy link
Member

sils commented Oct 10, 2016

#886 (comment) ?

@sils
Copy link
Member

sils commented Oct 10, 2016

build's red

@adtac
Copy link
Member

adtac commented Oct 11, 2016

tests failing; marking as WIP till then

Copy link
Member

@adtac adtac left a comment

Choose a reason for hiding this comment

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

Okay I don't know about the Diff class enough to review the rest, sorry.

@@ -182,7 +184,19 @@ def run(self, filename, file,

if new_file != tuple(file):
diff = Diff.from_string_arrays(file, new_file)
all_imports = ''
diff = Diff.from_string_arrays(file, new_file)
Copy link
Member

Choose a reason for hiding this comment

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

Line 188 and Line 186 do the same thing

@wimpykid26
Copy link
Author

Could anyone please review?

@sils
Copy link
Member

sils commented Oct 12, 2016

@wimpykid26 please help us reviewing other PRs so you can get faster reviews. Also note that on many other big organizations you have average waiting times of weeks to months for patches.

@@ -182,7 +184,18 @@ def run(self, filename, file,

if new_file != tuple(file):
diff = Diff.from_string_arrays(file, new_file)
all_imports = ''
for line_nr in sorted(diff._changes):
Copy link
Member

Choose a reason for hiding this comment

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

_changes is a "protected" member, you shouldn't access it^^

Copy link
Member

Choose a reason for hiding this comment

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

there's probably another member that allows you to iterate over the changes 👍

Copy link
Author

Choose a reason for hiding this comment

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

@Makman2 Thanks for pointing that out :). Should I use the range function to get the range of the diff and then use the _get_changes function for parsing?

list_of_imports[0].lstrip()
list_of_imports.sort()
string_of_imports = ' '.join(list_of_imports)
all_imports = all_imports + " " + string_of_imports
Copy link
Member

Choose a reason for hiding this comment

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

you can do this a bit more elegant :)
Make all_imports above to a list and change this line to:

all_imports = []
for line_nr in sorted(diff._changes):
    #....
    all_imports.append(string_of_imports)

Copy link
Member

Choose a reason for hiding this comment

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

ah and below doing

"Imports " + " ".join(all_imports) + " are sorted incorrectly"

or you could use format():

"Imports {} are sorted incorrectly.".format(" ".join(...))

@@ -182,7 +184,18 @@ def run(self, filename, file,

if new_file != tuple(file):
diff = Diff.from_string_arrays(file, new_file)
all_imports = ''
for line_nr in sorted(diff._changes):
linediff = diff._file[max(line_nr - 1, 0)]
Copy link
Member

Choose a reason for hiding this comment

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

here too, please don't access _file, I think we have actually a file property, don't we?

for line_nr in sorted(diff._changes):
linediff = diff._file[max(line_nr - 1, 0)]
list_of_imports = re.split(', +',
linediff.rstrip())
Copy link
Member

Choose a reason for hiding this comment

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

fits into a single line (improves readability because of the comma inside the quotes, that's kinda confusing :3)

yield Result(self,
"Imports can be sorted.",
"Imports" + all_imports + " are sorted incorrectly",
Copy link
Member

Choose a reason for hiding this comment

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

Missing space after Imports and missing period at end of message

list_of_imports = re.split(', +',
linediff.rstrip())
if list_of_imports[0].startswith('import'):
list_of_imports[0] = list_of_imports[0].lstrip('import')
Copy link
Member

Choose a reason for hiding this comment

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

lstrip doesn't work like this, for example this string
importimoopX
would expand to
X
as lstrip strips each character away, not a complete string in the given order. You can use str.replace or if you need additional whitespace stripping, you can use regexes and their replacement functions

@Makman2
Copy link
Member

Makman2 commented Oct 12, 2016

unack 151cb89

@@ -182,7 +184,19 @@ def run(self, filename, file,

if new_file != tuple(file):
diff = Diff.from_string_arrays(file, new_file)
all_imports = []
for line_nr in range(diff.range(filename).start.line, diff.range(filename).end.line + 1):
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. (101 > 79)

LineLengthBear, severity NORMAL, section linelength.

@@ -182,7 +184,20 @@ def run(self, filename, file,

if new_file != tuple(file):
diff = Diff.from_string_arrays(file, new_file)
all_imports = []
for line_nr in range(diff.range(filename).start.line,
diff.range(filename).end.line + 1):
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/bears/python/PyImportSortBear.py
+++ b/bears/python/PyImportSortBear.py
@@ -186,7 +186,7 @@
             diff = Diff.from_string_arrays(file, new_file)
             all_imports = []
             for line_nr in range(diff.range(filename).start.line,
-            diff.range(filename).end.line + 1):
+                                 diff.range(filename).end.line + 1):
                 if(diff._get_change(line_nr).change is not False):
                     line_diff = diff._get_change(line_nr).change[0]
                     list_of_imports = re.split(', +', line_diff.rstrip())

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

28 similar comments
@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

@gitmate-bot
Copy link
Collaborator

Hey! This pull request hasn't been updated for a while :/ It would be nice if we could get this going again!

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.

7 participants