-
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
VultureBear: Make use of vulture API #2000
Conversation
tests/python/VultureBearTest.py
Outdated
item.affected_code[0].end.line, | ||
item.confidence)) | ||
for item in self.get_results(test_case)) | ||
self.assertEqual(detected, expected) |
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.
W291 trailing whitespace'
PycodestyleBear (W291), severity NORMAL, section autopep8
.
tests/python/VultureBearTest.py
Outdated
@@ -41,86 +41,117 @@ def prep_file(): | |||
stack.enter_context(prep_file()) | |||
|
|||
return list(self.uut.run()) | |||
|
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.
W293 blank line contains whitespace'
PycodestyleBear (W293), severity NORMAL, section autopep8
.
tests/python/VultureBearTest.py
Outdated
item.affected_code[0].end.line, | ||
item.confidence)) | ||
for item in self.get_results(test_case)) | ||
self.assertEqual(detected, expected) |
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/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 = """\
tests/python/VultureBearTest.py
Outdated
@@ -41,86 +41,117 @@ def prep_file(): | |||
stack.enter_context(prep_file()) | |||
|
|||
return list(self.uut.run()) | |||
|
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/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,
tests/python/VultureBearTest.py
Outdated
item.affected_code[0].end.line, | ||
item.confidence)) | ||
for item in self.get_results(test_case)) | ||
self.assertEqual(detected, expected) |
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 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 = """\
tests/python/VultureBearTest.py
Outdated
@@ -41,86 +41,117 @@ def prep_file(): | |||
stack.enter_context(prep_file()) | |||
|
|||
return list(self.uut.run()) | |||
|
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 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,
ebe94e9
to
7a23b1b
Compare
bear-requirements.txt
Outdated
@@ -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 |
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 we use 0.25? It should make integration even easier.
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 new Item
class is so cool. Native support for coala
;-)
tests/python/VultureBearTest.py
Outdated
def test_unreachable_else(self): | ||
bad_file = """\ | ||
if True: | ||
print("Reachanle") |
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.
typo
tests/python/VultureBearTest.py
Outdated
good_file = """ | ||
x = 2 | ||
print(x) | ||
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.
instead of good_file
and bad_file
, can we just use 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.
Yeah! That indeed looks irrelevant! 🤔
Congratulations on getting PR number 2000 :-) |
adf4385
to
2a1d0c1
Compare
i think this looks good right now, what do you say @jendrikseipp ? |
I'll have a look :-) |
|
||
|
||
class VultureBear(GlobalBear): | ||
LANGUAGES = {'Python', 'Python 3'} | ||
REQUIREMENTS = {PipRequirement('vulture', '0.14.0')} | ||
REQUIREMENTS = {PipRequirement('vulture', '0.25.0')} |
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.
Is it normal that we have to list the requirement in two different places?
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.
I remember doing it previously. FWIW I have asked in the gitter channel.
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.
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 👍
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.
@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)
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.
@sils Thanks for clarifying!
tests/python/VultureBearTest.py
Outdated
print('Hello World') | ||
def __init__(self, name): | ||
self.name = name | ||
self.sur_name = 'Something' |
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.
sur_name -> surname
tests/python/VultureBearTest.py
Outdated
def test_unreachable_else(self): | ||
code = """\ | ||
if True: | ||
print("Reachanle") |
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.
typo
tests/python/VultureBearTest.py
Outdated
class Name: | ||
def test_class(self): | ||
code = """\ | ||
class 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.
Can you please remove this empty line?
bears/python/VultureBear.py
Outdated
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): |
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.
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.
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.
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) |
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.
Is it already possible to pass a minimum confidence to coala? If not, we should create an issue for 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.
I don't know!
CC @jayvdb
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 plan to support this, I think there should be somewhere an issue 👍 (can't find it right now)
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.
otherwise feel free to file one ;)
bears/python/VultureBear.py
Outdated
return (item.filename.lower(), item.lineno) | ||
|
||
vulture = Vulture() | ||
vulture = Vulture(verbose=True) |
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.
I don't think we should be verbose.
968107c
to
5ddd09e
Compare
Interesting. Have you checked if there is a new version of alex which has new rules preventing 'his' ? |
@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? |
566dcb9
to
5378955
Compare
tests/python/VultureBearTest.py
Outdated
result = self.get_results(bad_file) | ||
self.assertEqual(len(result), 1) | ||
self.assertEqual(result[0].confidence, 70) | ||
code = load_testfile('unused_variable.py') |
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.
I'd pass the filename to self.verify_results()
.
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.
Thanks for the suggestion 😄 Done!
Looks good to me :-) |
It seems the tests are still failing. Is there something we can do about that? |
phew CI is going crazy... try a rebase, we recently merged some fix for CI. |
but yeah commit looks also fine to me :) |
@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`)
Done rebasing. Praying starts. 🙏 |
reack 58a3999 |
@rultor merge |
yeah 💥 tough PR, but we got it :D |
Checklist
them.
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:
cobot mark wip <URL>
to get it outof the review queue.
The more you review, the more your score will grow at coala.io and we will
review your PRs faster!