Skip to content

Commit

Permalink
Merge branch 'master' into issue178
Browse files Browse the repository at this point in the history
  • Loading branch information
AgathiyanB committed May 22, 2020
2 parents 3599a22 + 8e6775c commit f799d10
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Unreleased

* Detect unreachable code in conditional expressions (Agathiyan Bragadeesh, #178).
* Support flake8 error codes F401 (unused import) and F841 (unused local
* Support flake8 noqa error codes F401 (unused import) and F841 (unused local
variable) (RJ722, #195).

# 1.4 (2020-03-30)
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ tool for higher code quality.
* tested: tests itself and has complete test coverage
* complements pyflakes and has the same output syntax
* sorts unused classes and functions by size with `--sort-by-size`
* respects `# noqa` comments
* supports Python 2.7 and Python \>= 3.5

## Installation
Expand Down Expand Up @@ -63,16 +62,23 @@ We collect whitelists for common Python modules and packages in
a whole file or directory, use the `--exclude` parameter (e.g.,
`--exclude *settings.py,docs/`).

<!-- Hide noqa docs until we decide whether we want to support it.
Another way of ignoring errors is to annotate the line causing the false
positive with `# noqa: <ERROR_CODE>` in a trailing comment (e.g., `#
noqa: V103`). The `ERROR_CODE` specifies what kind of dead code to
ignore (see the table below for the list of error codes). In case no
error code is specified, Vulture ignores all results for the line.
(Note that the line number for decorated objects is the line number of
the first decorator.)
-->

We recommend using whitelists instead of `noqa` comments, since `noqa`
comments add visual noise to the code and make it harder to read.
For compatibility with [flake8](https://flake8.pycqa.org/), Vulture
supports the [F401 and
F841](https://flake8.pycqa.org/en/latest/user/error-codes.html) error
codes for ignoring unused imports (`# noqa: F401`) and unused local
variables (`# noqa: F841`). However, we recommend using whitelists instead
of `noqa` comments, since `noqa` comments add visual noise to the code and
make it harder to read.

**Ignoring names**

Expand Down Expand Up @@ -177,6 +183,7 @@ makes Vulture ignore the `greet` method:
dead_code.py:1: V104 unused import 'os' (90% confidence)
dead_code.py:8: V106 unused variable 'message' (60% confidence)

<!-- Hide noqa docs until we decide whether we want to support it.
**Using "# noqa"**
```python
Expand Down Expand Up @@ -204,6 +211,8 @@ codes.
| V106, F841 | Unused variable |
| V201 | Unreachable code |
-->

## Exit codes

| Exit code | Description |
Expand Down
14 changes: 7 additions & 7 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def test_report(code, expected, make_whitelist=False):

def test_item_report(check_report):
expected = """\
{filename}:1: V104 unused import 'foo' (90% confidence)
{filename}:3: V102 unused class 'Foo' (60% confidence)
{filename}:7: V103 unused function 'bar' (60% confidence)
{filename}:8: V101 unused attribute 'foobar' (60% confidence)
{filename}:9: V106 unused variable 'foobar' (60% confidence)
{filename}:11: V201 unreachable code after 'return' (100% confidence)
{filename}:13: V105 unused property 'myprop' (60% confidence)
{filename}:1: unused import 'foo' (90% confidence)
{filename}:3: unused class 'Foo' (60% confidence)
{filename}:7: unused function 'bar' (60% confidence)
{filename}:8: unused attribute 'foobar' (60% confidence)
{filename}:9: unused variable 'foobar' (60% confidence)
{filename}:11: unreachable code after 'return' (100% confidence)
{filename}:13: unused property 'myprop' (60% confidence)
"""
check_report(mock_code, expected)

Expand Down
3 changes: 1 addition & 2 deletions vulture/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ def get_report(self, add_size=False):
size_report = ", {:d} {}".format(self.size, line_format)
else:
size_report = ""
return "{}:{:d}: {} {} ({}% confidence{})".format(
return "{}:{:d}: {} ({}% confidence{})".format(
utils.format_path(self.filename),
self.first_lineno,
ERROR_CODES[self.typ],
self.message,
self.confidence,
size_report,
Expand Down

0 comments on commit f799d10

Please sign in to comment.