Skip to content

Commit

Permalink
Enable more style checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Nov 24, 2024
1 parent 609f5f2 commit 84d32ca
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion dev/make-release-notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def check(name, text):
print("*" * 60)
print(text)
print("*" * 60)
response = input("Accept this %s (Y/n)? " % name).strip().lower()
response = input(f"Accept this {name} (Y/n)? ").strip().lower()
if response and response != "y":
sys.exit(1)

Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ indent-width = 4
target-version = "py38"

[tool.ruff.lint]
# ruff enables Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# ruff enables Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = [
"F", # pyflakes
"E4", "E7", "E9", # pycodestyle
"B", # flake8-bugbear
"C4", # comprehensions
"E", # pycodestyle
"F", # pyflakes
"I001", # isort
"SIM", # flake8-simplify
"UP", # pyupgrade
]
ignore = [
"C408", # unnecessary dict call
"SIM115", # Use context handler for opening files
]

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
Unit tests for config file and CLI argument parsing.
"""

from io import BytesIO
import pathlib
from io import BytesIO
from textwrap import dedent

import pytest

from vulture.config import (
DEFAULTS,
InputError,
_check_input_config,
_parse_args,
_parse_toml,
make_config,
InputError,
)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import codecs

from . import v
from vulture.utils import ExitCode

from . import v

assert v # Silence pyflakes.


Expand Down
3 changes: 2 additions & 1 deletion tests/test_errors.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pytest

from . import v, call_vulture
from vulture.utils import ExitCode

from . import call_vulture, v

assert v # Silence pyflakes.


Expand Down
1 change: 1 addition & 0 deletions tests/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from vulture.core import ERROR_CODES
from vulture.noqa import NOQA_CODE_MAP, NOQA_REGEXP, _parse_error_codes

from . import check, v

assert v # Silence pyflakes.
Expand Down
3 changes: 1 addition & 2 deletions tests/test_reachability.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from . import check_multiple_unreachable, check_unreachable
from . import v
from . import check_multiple_unreachable, check_unreachable, v

assert v # Silence pyflakes

Expand Down
3 changes: 2 additions & 1 deletion tests/test_scavenging.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import pytest

from . import check, v
from vulture.utils import ExitCode

from . import check, v

assert v # Silence pyflakes.


Expand Down
3 changes: 2 additions & 1 deletion tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import subprocess
import sys

from . import call_vulture, REPO, WHITELISTS
from vulture.utils import ExitCode

from . import REPO, WHITELISTS, call_vulture


def test_module_with_explicit_whitelists():
assert call_vulture(["vulture/"] + WHITELISTS) == ExitCode.NoDeadCode
Expand Down
25 changes: 10 additions & 15 deletions vulture/core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import ast
from fnmatch import fnmatch, fnmatchcase
from functools import partial
from pathlib import Path
import pkgutil
import re
import string
import sys
from fnmatch import fnmatch, fnmatchcase
from functools import partial
from pathlib import Path
from typing import List

from vulture import lines
from vulture import noqa
from vulture import utils
from vulture import lines, noqa, utils
from vulture.config import InputError, make_config
from vulture.reachability import Reachability
from vulture.utils import ExitCode


DEFAULT_CONFIDENCE = 60

IGNORED_VARIABLE_NAMES = {"object", "self"}
Expand Down Expand Up @@ -161,12 +158,9 @@ def get_report(self, add_size=False):
size_report = f", {self.size:d} {line_format}"
else:
size_report = ""
return "{}:{:d}: {} ({}% confidence{})".format(
utils.format_path(self.filename),
self.first_lineno,
self.message,
self.confidence,
size_report,
return (
f"{utils.format_path(self.filename)}:{self.first_lineno:d}: "
f"{self.message} ({self.confidence}% confidence{size_report})"
)

def get_whitelist_string(self):
Expand All @@ -177,8 +171,9 @@ def get_whitelist_string(self):
prefix = ""
if self.typ in ["attribute", "method", "property"]:
prefix = "_."
return "{}{} # unused {} ({}:{:d})".format(
prefix, self.name, self.typ, filename, self.first_lineno
return (
f"{prefix}{self.name} # unused {self.typ} "
f"({filename}:{self.first_lineno:d})"
)

def _tuple(self):
Expand Down
2 changes: 1 addition & 1 deletion vulture/noqa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import defaultdict
import re
from collections import defaultdict

NOQA_REGEXP = re.compile(
# Use the same regex as flake8 does.
Expand Down
2 changes: 1 addition & 1 deletion vulture/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import ast
from enum import IntEnum
import pathlib
import sys
import tokenize
from enum import IntEnum


class VultureInputException(Exception):
Expand Down
3 changes: 1 addition & 2 deletions vulture/whitelists/ctypes_whitelist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ctypes import _CFuncPtr
from ctypes import _Pointer
from ctypes import _CFuncPtr, _Pointer

_CFuncPtr.argtypes
_CFuncPtr.errcheck
Expand Down
2 changes: 1 addition & 1 deletion vulture/whitelists/unittest_whitelist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest import mock, TestCase
from unittest import TestCase, mock

TestCase.setUp
TestCase.tearDown
Expand Down

0 comments on commit 84d32ca

Please sign in to comment.