Skip to content

Commit

Permalink
Update ruff settings (#3558)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos authored Oct 2, 2024
1 parent 36a6871 commit 6ed5df1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion codespell_lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ._codespell import _script_main, main
from ._version import __version__ # type: ignore[import-not-found]

__all__ = ["_script_main", "main", "__version__"]
__all__ = ["__version__", "_script_main", "main"]
18 changes: 9 additions & 9 deletions codespell_lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ def test_permission_error(
fname.write_text("abandonned\n")
result = cs.main(fname, std=True)
assert isinstance(result, tuple)
code, _, stderr = result
_, _, stderr = result
assert "WARNING:" not in stderr
fname.chmod(0o000)
result = cs.main(fname, std=True)
assert isinstance(result, tuple)
code, _, stderr = result
_, _, stderr = result
assert "WARNING:" in stderr


Expand Down Expand Up @@ -464,7 +464,7 @@ def test_inline_ignores(
expected_error_count: int,
) -> None:
d = str(tmpdir)
with open(op.join(d, "bad.txt"), "w") as f:
with open(op.join(d, "bad.txt"), "w", encoding="utf-8") as f:
f.write(content)
assert cs.main(d) == expected_error_count

Expand Down Expand Up @@ -772,7 +772,7 @@ def _helper_test_case_handling_in_fixes(
fname.write_text("early adoptor\n")
result = cs.main("-D", dictionary_name, fname, std=True)
assert isinstance(result, tuple)
code, stdout, _ = result
_, stdout, _ = result
# all suggested fixes must be lowercase too
assert "adopter, adaptor" in stdout
# the reason, if any, must not be modified
Expand All @@ -783,7 +783,7 @@ def _helper_test_case_handling_in_fixes(
fname.write_text("Early Adoptor\n")
result = cs.main("-D", dictionary_name, fname, std=True)
assert isinstance(result, tuple)
code, stdout, _ = result
_, stdout, _ = result
# all suggested fixes must be capitalized too
assert "Adopter, Adaptor" in stdout
# the reason, if any, must not be modified
Expand All @@ -794,7 +794,7 @@ def _helper_test_case_handling_in_fixes(
fname.write_text("EARLY ADOPTOR\n")
result = cs.main("-D", dictionary_name, fname, std=True)
assert isinstance(result, tuple)
code, stdout, _ = result
_, stdout, _ = result
# all suggested fixes must be uppercase too
assert "ADOPTER, ADAPTOR" in stdout
# the reason, if any, must not be modified
Expand All @@ -805,7 +805,7 @@ def _helper_test_case_handling_in_fixes(
fname.write_text("EaRlY AdOpToR\n")
result = cs.main("-D", dictionary_name, fname, std=True)
assert isinstance(result, tuple)
code, stdout, _ = result
_, stdout, _ = result
# all suggested fixes should be lowercase
assert "adopter, adaptor" in stdout
# the reason, if any, must not be modified
Expand Down Expand Up @@ -1234,7 +1234,7 @@ def test_quiet_level_32(
d = tmp_path / "files"
d.mkdir()
conf = str(tmp_path / "setup.cfg")
with open(conf, "w") as f:
with open(conf, "w", encoding="utf-8") as f:
# It must contain a "codespell" section.
f.write("[codespell]\n")
args = ("--config", conf)
Expand Down Expand Up @@ -1263,7 +1263,7 @@ def test_ill_formed_ini_config_file(
d = tmp_path / "files"
d.mkdir()
conf = str(tmp_path / "setup.cfg")
with open(conf, "w") as f:
with open(conf, "w", encoding="utf-8") as f:
# It should contain but lacks a section.
f.write("foobar =\n")
args = ("--config", conf)
Expand Down
8 changes: 4 additions & 4 deletions codespell_lib/tests/test_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,11 @@ def test_dictionary_looping(
reps = [r for r in reps if len(r)]
this_err_dict[err] = reps
# 1. check the dict against itself (diagonal)
for err in this_err_dict:
for err, reps in this_err_dict.items():
assert word_regex.fullmatch(
err
), f"error {err!r} does not match default word regex '{word_regex_def}'"
for r in this_err_dict[err]:
for r in reps:
assert r not in this_err_dict, (
f"error {err}: correction {r} is an error itself "
f"in the same dictionary file {short_fname}"
Expand All @@ -337,12 +337,12 @@ def test_dictionary_looping(
# 2. check corrections in this dict against other dicts (upper)
pair = (short_fname, other_fname)
if pair not in allowed_dups:
for err in this_err_dict:
for err, reps in this_err_dict.items():
assert err not in other_err_dict, (
f"error {err!r} in dictionary {short_fname} "
f"already exists in dictionary {other_fname}"
)
for r in this_err_dict[err]:
for r in reps:
assert r not in other_err_dict, (
f"error {err}: correction {r} from dictionary {short_fname} "
f"is an error itself in dictionary {other_fname}"
Expand Down
53 changes: 30 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,6 @@ filterwarnings = ["error"]
line-length = 88

[tool.ruff.lint]
ignore = [
"ANN101",
"B904",
"PLW2901",
"RET505",
"SIM105",
"SIM115",
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
]
select = [
"A",
"ANN",
Expand All @@ -157,6 +134,36 @@ select = [
"W",
"YTT",
]
ignore = [
"ANN101",
"B904",
"PLR0914",
"PLR6201",
"PLW2901",
"PT004", # deprecated
"PT005", # deprecated
"RET505",
"S404",
"SIM105",
"SIM115",
"UP027", # deprecated
"UP038", # https://github.com/astral-sh/ruff/issues/7871
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
]

[tool.ruff.lint.mccabe]
max-complexity = 45
Expand Down

0 comments on commit 6ed5df1

Please sign in to comment.