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

VultureBear: Make use of vulture API #2000

Merged
merged 1 commit into from
Aug 29, 2017
Merged

Conversation

RJ722
Copy link
Member

@RJ722 RJ722 commented Aug 15, 2017

Checklist

  • I read the commit guidelines and I've followed
    them.
  • I ran coala over my code locally. (All commits have to pass
    individually.
    It is not sufficient to have "fixup commits" on your PR,
    our bot will still report the issues for the previous commit.) You will
    likely receive a lot of bot comments and build failures if coala does not
    pass on every single commit!

Please consider helping us by reviewing other peoples pull requests as well:

The more you review, the more your score will grow at coala.io and we will
review your PRs faster!

item.affected_code[0].end.line,
item.confidence))
for item in self.get_results(test_case))
self.assertEqual(detected, expected)
Copy link
Collaborator

Choose a reason for hiding this comment

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

W291 trailing whitespace'

PycodestyleBear (W291), severity NORMAL, section autopep8.

@@ -41,86 +41,117 @@ def prep_file():
stack.enter_context(prep_file())

return list(self.uut.run())

Copy link
Collaborator

Choose a reason for hiding this comment

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

W293 blank line contains whitespace'

PycodestyleBear (W293), severity NORMAL, section autopep8.

item.affected_code[0].end.line,
item.confidence))
for item in self.get_results(test_case))
self.assertEqual(detected, expected)
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/python/VultureBearTest.py
+++ b/tests/python/VultureBearTest.py
@@ -47,7 +47,7 @@
                                         item.affected_code[0].end.line,
                                         item.confidence))
                         for item in self.get_results(test_case))
-        self.assertEqual(detected, expected)        
+        self.assertEqual(detected, expected)
 
     def test_used_variable(self):
         good_file = """\

@@ -41,86 +41,117 @@ def prep_file():
stack.enter_context(prep_file())

return list(self.uut.run())

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/python/VultureBearTest.py
+++ b/tests/python/VultureBearTest.py
@@ -41,7 +41,7 @@
                 stack.enter_context(prep_file())
 
             return list(self.uut.run())
-    
+
     def verify_results(self, test_case, expected):
         detected = dict((item.message, (item.affected_code[0].start.line,
                                         item.affected_code[0].end.line,

item.affected_code[0].end.line,
item.confidence))
for item in self.get_results(test_case))
self.assertEqual(detected, expected)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

SpaceConsistencyBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/python/VultureBearTest.py
+++ b/tests/python/VultureBearTest.py
@@ -47,7 +47,7 @@
                                         item.affected_code[0].end.line,
                                         item.confidence))
                         for item in self.get_results(test_case))
-        self.assertEqual(detected, expected)        
+        self.assertEqual(detected, expected)
 
     def test_used_variable(self):
         good_file = """\

@@ -41,86 +41,117 @@ def prep_file():
stack.enter_context(prep_file())

return list(self.uut.run())

Copy link
Collaborator

Choose a reason for hiding this comment

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

Line contains following spacing inconsistencies:

  • Trailing whitespaces.

SpaceConsistencyBear, severity NORMAL, section python.

The issue can be fixed by applying the following patch:

--- a/tests/python/VultureBearTest.py
+++ b/tests/python/VultureBearTest.py
@@ -41,7 +41,7 @@
                 stack.enter_context(prep_file())
 
             return list(self.uut.run())
-    
+
     def verify_results(self, test_case, expected):
         detected = dict((item.message, (item.affected_code[0].start.line,
                                         item.affected_code[0].end.line,

@RJ722 RJ722 force-pushed the use-vulture-API branch 2 times, most recently from ebe94e9 to 7a23b1b Compare August 16, 2017 13:01
@@ -34,6 +34,6 @@ rstcheck~=3.1
safety~=0.5.1
scspell3k~=2.0
vim-vint~=0.3.12
vulture~=0.14.0
vulture==0.24.0

Choose a reason for hiding this comment

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

Can we use 0.25? It should make integration even easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

The new Item class is so cool. Native support for coala ;-)

def test_unreachable_else(self):
bad_file = """\
if True:
print("Reachanle")

Choose a reason for hiding this comment

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

typo

good_file = """
x = 2
print(x)
good_file = """\

Choose a reason for hiding this comment

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

instead of good_file and bad_file, can we just use code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah! That indeed looks irrelevant! 🤔

@jendrikseipp
Copy link

Congratulations on getting PR number 2000 :-)

@RJ722 RJ722 force-pushed the use-vulture-API branch 4 times, most recently from adf4385 to 2a1d0c1 Compare August 16, 2017 16:43
@Nosferatul
Copy link
Member

i think this looks good right now, what do you say @jendrikseipp ?

@jendrikseipp
Copy link

I'll have a look :-)



class VultureBear(GlobalBear):
LANGUAGES = {'Python', 'Python 3'}
REQUIREMENTS = {PipRequirement('vulture', '0.14.0')}
REQUIREMENTS = {PipRequirement('vulture', '0.25.0')}

Choose a reason for hiding this comment

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

Is it normal that we have to list the requirement in two different places?

Copy link
Member Author

Choose a reason for hiding this comment

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

I remember doing it previously. FWIW I have asked in the gitter channel.

Copy link
Member

Choose a reason for hiding this comment

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

yeah currently we need it at two places, one for CI and one for the bear itself. Once our requirement-management gets more mature we will generate that dynamically as far as possible 👍

Copy link
Member

Choose a reason for hiding this comment

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

@jendrikseipp FYI the requirements.txt above is generated and the CI always checks that it's up to date so this REQUIREMENTS attribute is the correct and important place, the requirements.txt a technical necessity currently manually managed but at least enforced by the CI (last time I checked)

Choose a reason for hiding this comment

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

@sils Thanks for clarifying!

print('Hello World')
def __init__(self, name):
self.name = name
self.sur_name = 'Something'

Choose a reason for hiding this comment

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

sur_name -> surname

def test_unreachable_else(self):
code = """\
if True:
print("Reachanle")

Choose a reason for hiding this comment

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

typo

class Name:
def test_class(self):
code = """\
class Name:

Choose a reason for hiding this comment

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

Can you please remove this empty line?

vulture.unused_props + vulture.unused_vars +
vulture.unused_attrs, key=file_lineno):
message = 'Unused {0}: {1}'.format(item.typ, item)
for item in vulture.get_unused_code(sort_by_size=True):

Choose a reason for hiding this comment

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

Is sorting helpful here? I would guess that coala has its own sorting. And if it doesn't, I think we should sort by filenames.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think coala doesn't sorts the results at all because results are yielded at runtime directly, without being stored (generally).

Also, since files would be automatically be coming in an alphabetical order, I think we won't need additional sorting. I am removing the sort_by_size=True for now. Please comment if you think else wise. :-)

confidence=CONFIDENCE_MAP[item.typ])
line=item.first_lineno,
end_line=item.last_lineno,
confidence=item.confidence)

Choose a reason for hiding this comment

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

Is it already possible to pass a minimum confidence to coala? If not, we should create an issue for this.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know!

CC @jayvdb

Copy link
Member

Choose a reason for hiding this comment

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

we plan to support this, I think there should be somewhere an issue 👍 (can't find it right now)

Copy link
Member

Choose a reason for hiding this comment

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

otherwise feel free to file one ;)

return (item.filename.lower(), item.lineno)

vulture = Vulture()
vulture = Vulture(verbose=True)

Choose a reason for hiding this comment

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

I don't think we should be verbose.

@RJ722 RJ722 force-pushed the use-vulture-API branch 3 times, most recently from 968107c to 5ddd09e Compare August 18, 2017 14:31
@jayvdb
Copy link
Member

jayvdb commented Aug 26, 2017

Interesting. Have you checked if there is a new version of alex which has new rules preventing 'his' ?

@RJ722
Copy link
Member Author

RJ722 commented Aug 26, 2017

@jayvdb I don't think that there were any upstream changes, https://github.com/azu/textlint-rule-alex/ was last updated - Nov, 16.

Should we try rebuilding without cache?

@RJ722 RJ722 force-pushed the use-vulture-API branch 4 times, most recently from 566dcb9 to 5378955 Compare August 28, 2017 06:04
result = self.get_results(bad_file)
self.assertEqual(len(result), 1)
self.assertEqual(result[0].confidence, 70)
code = load_testfile('unused_variable.py')

Choose a reason for hiding this comment

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

I'd pass the filename to self.verify_results().

Copy link
Member Author

@RJ722 RJ722 Aug 28, 2017

Choose a reason for hiding this comment

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

Thanks for the suggestion 😄 Done!

@jendrikseipp
Copy link

Looks good to me :-)

@jendrikseipp
Copy link

It seems the tests are still failing. Is there something we can do about that?

@Makman2
Copy link
Member

Makman2 commented Aug 28, 2017

phew CI is going crazy... try a rebase, we recently merged some fix for CI.

@Makman2
Copy link
Member

Makman2 commented Aug 28, 2017

but yeah commit looks also fine to me :)

@jendrikseipp
Copy link

@RJ722 Does rebasing help with the tests?

The new vulture API provides better integration with coala. It
natively supports `item.confidence`. Also, it gives precise
information about the location of dead code (`first_line, `last_line`)
@RJ722
Copy link
Member Author

RJ722 commented Aug 29, 2017

@RJ722 Does rebasing help with the tests?

Done rebasing. Praying starts. 🙏

@jendrikseipp
Copy link

@RJ722 Tests passed :-)

@Makman2 can we merge this?

@Makman2
Copy link
Member

Makman2 commented Aug 29, 2017

reack 58a3999

@Makman2
Copy link
Member

Makman2 commented Aug 29, 2017

@rultor merge

@rultor
Copy link

rultor commented Aug 29, 2017

@rultor merge

@Makman2 OK, I'll try to merge now. You can check the progress of the merge here

@rultor rultor merged commit 58a3999 into coala:master Aug 29, 2017
@rultor
Copy link

rultor commented Aug 29, 2017

@rultor merge

@Makman2 Done! FYI, the full log is here (took me 2min)

@Makman2
Copy link
Member

Makman2 commented Aug 29, 2017

yeah 💥 tough PR, but we got it :D

@RJ722 RJ722 mentioned this pull request Aug 30, 2017
2 tasks
@RJ722 RJ722 deleted the use-vulture-API branch August 30, 2017 16:11
@RJ722
Copy link
Member Author

RJ722 commented Aug 30, 2017

yeah 💥 tough PR, but we got it :D

@Makman2 Roger that!

BTW I've opened #2025

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.

9 participants