mirror of
https://github.com/codespell-project/codespell.git
synced 2025-08-06 18:24:41 +08:00
Fix ruff alerts (currently) not caught by pre-commit (#3162)
This commit is contained in:

committed by
GitHub

parent
81e47b5c31
commit
4587d788a7
2
.github/workflows/codespell-private.yml
vendored
2
.github/workflows/codespell-private.yml
vendored
@ -12,7 +12,7 @@ jobs:
|
||||
test:
|
||||
env:
|
||||
REQUIRE_ASPELL: true
|
||||
RUFF_FORMAT: github
|
||||
RUFF_OUTPUT_FORMAT: github
|
||||
# Make sure we're using the latest aspell dictionary
|
||||
runs-on: ubuntu-22.04
|
||||
timeout-minutes: 10
|
||||
|
@ -44,7 +44,7 @@ from ._version import ( # type: ignore[import-not-found]
|
||||
__version__ as VERSION, # noqa: N812
|
||||
)
|
||||
|
||||
word_regex_def = r"[\w\-'’]+"
|
||||
word_regex_def = r"[\w\-'’]+" # noqa: RUF001
|
||||
# While we want to treat characters like ( or " as okay for a starting break,
|
||||
# these may occur unescaped in URIs, and so we are more restrictive on the
|
||||
# endpoint. Emails are more restrictive, so the endpoint remains flexible.
|
||||
@ -54,7 +54,7 @@ uri_regex_def = (
|
||||
)
|
||||
# Pass all misspellings through this translation table to generate
|
||||
# alternative misspellings and fixes.
|
||||
alt_chars = (("'", "’"),)
|
||||
alt_chars = (("'", "’"),) # noqa: RUF001
|
||||
USAGE = """
|
||||
\t%prog [OPTIONS] [file1 file2 ... fileN]
|
||||
"""
|
||||
@ -287,8 +287,9 @@ class FileOpener:
|
||||
else:
|
||||
break
|
||||
else:
|
||||
# reading with encoding "iso-8859-1" cannot fail with UnicodeDecodeError
|
||||
msg = "Unknown encoding"
|
||||
raise Exception(msg)
|
||||
raise RuntimeError(msg) # pragma: no cover
|
||||
|
||||
return lines, encoding
|
||||
|
||||
@ -309,10 +310,7 @@ class NewlineHelpFormatter(argparse.HelpFormatter):
|
||||
for part in parts:
|
||||
# Eventually we could allow others...
|
||||
indent_start = "- "
|
||||
if part.startswith(indent_start):
|
||||
offset = len(indent_start)
|
||||
else:
|
||||
offset = 0
|
||||
offset = len(indent_start) if part.startswith(indent_start) else 0
|
||||
part = part[offset:]
|
||||
part = self._whitespace_matcher.sub(" ", part).strip()
|
||||
parts = textwrap.wrap(part, width - offset)
|
||||
@ -519,7 +517,7 @@ def parse_options(
|
||||
help="set interactive mode when writing changes:\n"
|
||||
"- 0: no interactivity.\n"
|
||||
"- 1: ask for confirmation.\n"
|
||||
"- 2: ask user to choose one fix when more than one is available.\n" # noqa: E501
|
||||
"- 2: ask user to choose one fix when more than one is available.\n"
|
||||
"- 3: both 1 and 2",
|
||||
)
|
||||
|
||||
@ -738,8 +736,8 @@ def build_dict(
|
||||
translate_tables = [(x, str.maketrans(x, y)) for x, y in alt_chars]
|
||||
for line in f:
|
||||
[key, data] = line.split("->")
|
||||
# TODO for now, convert both to lower. Someday we can maybe add
|
||||
# support for fixing caps.
|
||||
# TODO: For now, convert both to lower.
|
||||
# Someday we can maybe add support for fixing caps.
|
||||
key = key.lower()
|
||||
data = data.lower()
|
||||
if key not in ignore_words:
|
||||
@ -1219,10 +1217,7 @@ def main(*args: str) -> int:
|
||||
if not options.colors:
|
||||
colors.disable()
|
||||
|
||||
if options.summary:
|
||||
summary = Summary()
|
||||
else:
|
||||
summary = None
|
||||
summary = Summary() if options.summary else None
|
||||
|
||||
context = None
|
||||
if options.context is not None:
|
||||
|
@ -41,7 +41,7 @@ class MainWrapper:
|
||||
) -> Union[int, Tuple[int, str, str]]:
|
||||
args = tuple(str(arg) for arg in args)
|
||||
if count:
|
||||
args = ("--count",) + args
|
||||
args = ("--count", *args)
|
||||
code = cs_.main(*args)
|
||||
frame = inspect.currentframe()
|
||||
assert frame is not None
|
||||
@ -76,8 +76,7 @@ def run_codespell(
|
||||
encoding="utf-8",
|
||||
check=False,
|
||||
)
|
||||
count = int(proc.stderr.split("\n")[-2])
|
||||
return count
|
||||
return int(proc.stderr.split("\n")[-2])
|
||||
|
||||
|
||||
def test_command(tmp_path: Path) -> None:
|
||||
@ -159,7 +158,8 @@ def test_basic(
|
||||
assert isinstance(result, tuple)
|
||||
code, stdout, stderr = result
|
||||
assert code == 0
|
||||
assert not stdout and not stderr
|
||||
assert not stdout
|
||||
assert not stderr
|
||||
assert cs.main(tmp_path) == 0
|
||||
|
||||
# empty directory
|
||||
@ -177,9 +177,9 @@ def test_default_word_parsing(
|
||||
assert cs.main(fname) == 1, "bad"
|
||||
|
||||
fname = tmp_path / "apostrophe"
|
||||
fname.write_text("woudn't\n", encoding="utf-8") # U+0027 (')
|
||||
fname.write_text("woudn't\n", encoding="utf-8") # U+0027
|
||||
assert cs.main(fname) == 1, "misspelling containing typewriter apostrophe U+0027"
|
||||
fname.write_text("woudn’t\n", encoding="utf-8") # U+2019 (’)
|
||||
fname.write_text("woudn’t\n", encoding="utf-8") # U+2019 # noqa: RUF001
|
||||
assert cs.main(fname) == 1, "misspelling containing typographic apostrophe U+2019"
|
||||
|
||||
|
||||
@ -300,7 +300,8 @@ def test_summary(
|
||||
assert isinstance(result, tuple)
|
||||
code, stdout, stderr = result
|
||||
assert code == 0
|
||||
assert not stdout and not stderr, "no output"
|
||||
assert not stdout
|
||||
assert not stderr, "no output"
|
||||
result = cs.main(fname, "--summary", std=True)
|
||||
assert isinstance(result, tuple)
|
||||
code, stdout, stderr = result
|
||||
@ -473,7 +474,8 @@ def test_encoding(
|
||||
assert isinstance(result, tuple)
|
||||
code, stdout, stderr = result
|
||||
assert code == 0
|
||||
assert not stdout and not stderr
|
||||
assert not stdout
|
||||
assert not stderr
|
||||
result = cs.main("-q", "0", fname, std=True, count=False)
|
||||
assert isinstance(result, tuple)
|
||||
code, stdout, stderr = result
|
||||
@ -594,9 +596,9 @@ def test_check_hidden(
|
||||
#
|
||||
# tmp_path
|
||||
# ├── .abandonned
|
||||
# │ ├── .abandonned.txt
|
||||
# │ └── subdir
|
||||
# │ └── .abandonned.txt
|
||||
# │ ├── .abandonned.txt
|
||||
# │ └── subdir
|
||||
# │ └── .abandonned.txt
|
||||
# └── .abandonned.txt
|
||||
#
|
||||
assert cs.main(tmp_path) == 0
|
||||
@ -626,9 +628,9 @@ def test_check_hidden(
|
||||
#
|
||||
# tmp_path
|
||||
# ├── .abandonned
|
||||
# │ ├── .abandonned.txt
|
||||
# │ └── subdir
|
||||
# │ └── .abandonned.txt
|
||||
# │ ├── .abandonned.txt
|
||||
# │ └── subdir
|
||||
# │ └── .abandonned.txt
|
||||
# ├── .abandonned.txt
|
||||
# └── subdir
|
||||
# └── .abandonned
|
||||
@ -1150,7 +1152,7 @@ def test_ill_formed_ini_config_file(
|
||||
assert "ill-formed config file" in stderr
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", ("cfg", "toml", "toml_list"))
|
||||
@pytest.mark.parametrize("kind", ["cfg", "toml", "toml_list"])
|
||||
def test_config_toml(
|
||||
tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str],
|
||||
@ -1260,8 +1262,7 @@ def run_codespell_stdin(
|
||||
)
|
||||
output = proc.stdout
|
||||
# get number of lines
|
||||
count = output.count("\n")
|
||||
return count
|
||||
return output.count("\n")
|
||||
|
||||
|
||||
def test_stdin(tmp_path: Path) -> None:
|
||||
|
@ -191,7 +191,7 @@ def _check_err_rep(
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"err, rep, match",
|
||||
("err", "rep", "match"),
|
||||
[
|
||||
("a a", "bar", "has whitespace"),
|
||||
("a,a", "bar", "has a comma"),
|
||||
@ -222,7 +222,7 @@ def test_error_checking(err: str, rep: str, match: str) -> None:
|
||||
|
||||
@pytest.mark.skipif(not spellers, reason="requires aspell-en")
|
||||
@pytest.mark.parametrize(
|
||||
"err, rep, err_aspell, rep_aspell, match",
|
||||
("err", "rep", "err_aspell", "rep_aspell", "match"),
|
||||
[
|
||||
# This doesn't raise any exceptions, so skip for now:
|
||||
# pytest.param('a', 'uvw, bar,', None, None, 'should be in aspell'),
|
||||
|
@ -113,6 +113,9 @@ ignore = [
|
||||
"ANN101",
|
||||
"B904",
|
||||
"PLW2901",
|
||||
"RET505",
|
||||
"SIM105",
|
||||
"SIM115",
|
||||
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
|
||||
"W191",
|
||||
"E111",
|
||||
@ -142,8 +145,13 @@ select = [
|
||||
"PLC",
|
||||
"PLE",
|
||||
"PLR",
|
||||
"PT",
|
||||
"PLW",
|
||||
"RET",
|
||||
"RUF",
|
||||
"S",
|
||||
"SIM",
|
||||
"TRY",
|
||||
"U",
|
||||
"UP",
|
||||
"W",
|
||||
|
Reference in New Issue
Block a user