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

Ignore results annotated with '# noqa' #195

Merged
merged 22 commits into from
Mar 31, 2020

Conversation

RJ722
Copy link
Contributor

@RJ722 RJ722 commented Mar 9, 2020

Hey,

Description

This PR isn't production-ready by any means, but I just wanted to have an idea about the complexity it would add to Vulture to support # noqa comments. I'd be happy to add tests and documentation, once we all settle if it would be a good idea to carry this forward.

Another change with the introduction of # noqa comments would be the introduction of issue codes (it's possible without these as well, but would hurt specificity). For now, I've just added V001, V002, ... - the nomenclature for these issue codes is another thing to think about.

Related Issue

#160, #182, #190

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation in the README file.
  • I have updated the documentation accordingly.
  • I have added an entry in CHANGELOG.md.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

vulture/core.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Mar 9, 2020

Pull Request Test Coverage Report for Build 727

  • 23 of 23 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.04%) to 98.962%

Totals Coverage Status
Change from base Build 726: 0.04%
Covered Lines: 572
Relevant Lines: 578

💛 - Coveralls

Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

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

Nice work! I think the feature doesn't add too much complexity after all. Using issue codes is a good idea, I think. We should probably print them in the normal output as well.

vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
@RJ722
Copy link
Contributor Author

RJ722 commented Mar 10, 2020

@jendrikseipp should ISSUE_CODE_MAP be a class variable for Vulture?

I'm asking because my guess is that most folks would only import Vulture, if using the API (from vulture import Vulture).

@RJ722 RJ722 force-pushed the add-noqa branch 2 times, most recently from da06b81 to 17ee6c4 Compare March 10, 2020 13:10
Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

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

Almost there :-) Obviously, this also needs tests, preferably in a new file. When writing new tests, check if pytest.mark.parametrize could be useful. Maybe there's already an example for that in the codebase.

vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
@RJ722
Copy link
Contributor Author

RJ722 commented Mar 10, 2020

Another thing I was pondering about. We don't start ignoring noqa until get_unused_code is called. What if the user bypasses it, e.g.:

from vulture import Vulture

v = Vulture()
v.scan('import this  # noqa: V004')
print(v.unused_imports)

Should we move the has_noqa logic to _define method?

@jendrikseipp
Copy link
Owner

Should we move the has_noqa logic to _define method?

Good idea! This aligns better with the existing code for ignoring things.

Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

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

I think it would be good to separate testing the regex and testing ignoring unused code. For the former, I think we can use the test cases from the flake8 comment as test cases (plus some examples we don't want to recognize).

@RJ722
Copy link
Contributor Author

RJ722 commented Mar 10, 2020

TODO:

  • One test is failing because Python3.8 onwards, the first line for property node is the same line at which the function starts.
  • Write documentation for these changes -- @jendrikseipp can you take this on, please? 😅

@RJ722 RJ722 marked this pull request as ready for review March 10, 2020 18:27
tests/test_noqa.py Outdated Show resolved Hide resolved
@jendrikseipp
Copy link
Owner

Could you also add a test that verifies that we fixed the "or vs. union" bug?

@RJ722
Copy link
Contributor Author

RJ722 commented Mar 10, 2020

Could you also add a test that verifies that we fixed the "or vs. union" bug?

The way I've added the tests is basically ensuring that an example of the same issue code is covered in both categories - all and V00X (on different lines - both before and after). If there'd have been a problem with "or v/s union", we'd have seen it by now.

@RJ722
Copy link
Contributor Author

RJ722 commented Mar 10, 2020

But, now that I come think of it, I haven't added isolated cases - just V00X, or # noqa alone. Adding them.

vulture/core.py Outdated Show resolved Hide resolved
tests/test_noqa.py Outdated Show resolved Hide resolved
tests/test_noqa.py Outdated Show resolved Hide resolved
tests/test_report.py Outdated Show resolved Hide resolved
tests/test_noqa.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
@RJ722 RJ722 force-pushed the add-noqa branch 4 times, most recently from 3646f9c to bb60ebc Compare March 14, 2020 10:53
Copy link
Owner

@jendrikseipp jendrikseipp left a comment

Choose a reason for hiding this comment

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

Nice work! Here are some more nitpicks :-)

tests/test_noqa.py Outdated Show resolved Hide resolved
tests/test_noqa.py Outdated Show resolved Hide resolved
tests/test_noqa.py Show resolved Hide resolved
tests/test_noqa.py Outdated Show resolved Hide resolved
tests/test_noqa.py Outdated Show resolved Hide resolved
tests/test_noqa.py Show resolved Hide resolved
tests/test_report.py Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
vulture/core.py Outdated Show resolved Hide resolved
@jendrikseipp
Copy link
Owner

Thanks for the additional changes! I edited README.md slightly. Could you please resolve the merge conflicts? Then I can merge the PR.

@RJ722
Copy link
Contributor Author

RJ722 commented Mar 30, 2020

@jendrikseipp, thanks for your timely reviews, and help on this! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants