Skip to content

Commit

Permalink
feat: check for deprecated Ruff codes
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Oct 20, 2023
1 parent 80c8159 commit bc9c30c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ for family, grp in itertools.groupby(collected.checks.items(), key=lambda x: x[1
- [`RF001`](https://learn.scientific-python.org/development/guides/style#RF001): Has Ruff config
- [`RF002`](https://learn.scientific-python.org/development/guides/style#RF002): Target version must be set
- [`RF003`](https://learn.scientific-python.org/development/guides/style#RF003): src directory specified if used
- `RF004`: Deprecated config options should be avoided
- [`RF101`](https://learn.scientific-python.org/development/guides/style#RF101): Bugbear must be selected
- [`RF102`](https://learn.scientific-python.org/development/guides/style#RF102): isort must be selected
- [`RF103`](https://learn.scientific-python.org/development/guides/style#RF103): pyupgrade must be selected
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/guides/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ select = [
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
extend-ignore = [
ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
"PT004", # Use underscore for non-returning fixture (use usefixture instead)
Expand All @@ -224,8 +224,8 @@ select what you want from these. Like Flake8, plugins match by whole letter
sequences (with the special exception of pylint's "PL" shortcut), then you can
also include leading or whole error codes. Codes starting with 9 must be
selected explicitly, with at least the letters followed by a 9. You can also
ignore certain error codes via `extend-ignore`. You can also set codes per paths
to ignore in `per-file-ignores`. If you don't like certain auto-fixes, you can
ignore certain error codes via `ignore`. You can also set codes per paths to
ignore in `per-file-ignores`. If you don't like certain auto-fixes, you can
disable auto-fixing for specific error codes via `unfixable`.

There are other configuration options, such as the `src` list which tells it
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ select = [
"UP", # pyupgrade
"YTT", # flake8-2020
]
extend-ignore = [
ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
"PT004", # Incorrect check, usefixtures is the correct way to do this
Expand Down
27 changes: 21 additions & 6 deletions src/sp_repo_review/checks/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,30 @@ def check(pyproject: dict[str, Any], package: Traversable) -> bool | None:
if not package.joinpath("src").is_dir():
return None

match pyproject:
case {"tool": {"ruff": {"src": list(x)}}}:
match pyproject["tool"]["ruff"]:
case {"src": list(x)}:
return "src" in x
case _:
return False


class RF004(Ruff):
"Deprecated config options should be avoided"

requires = {"RF001"}
url = ""

@staticmethod
def check(pyproject: dict[str, Any]) -> str:
match pyproject["tool"]["ruff"]:
case {"extend-unfixable": object()}:
return "`extend-unfixable` deprecated, use `unfixable` (identical)"
case {"extend-ignore": object()}:
return "`extend-ignore` deprecated, use `ignore` (identical)"
case _:
return ""


class RuffMixin(Protocol):
code: ClassVar[str]
name: ClassVar[str]
Expand All @@ -99,10 +116,8 @@ def check(cls: type[RuffMixin], pyproject: dict[str, Any]) -> bool:
```
"""

match pyproject:
case {"tool": {"ruff": {"select": list(x)}}} | {
"tool": {"ruff": {"extend-select": list(x)}}
}:
match pyproject["tool"]["ruff"]:
case {"select": list(x)} | {"extend-select": list(x)}:
return cls.code in x or "ALL" in x
case _:
return False
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ select = [
"NPY", # NumPy specific rules
"PD", # pandas-vet
]
extend-ignore = [
ignore = [
"PLR", # Design related pylint codes
"E501", # Line too long
]
Expand Down

0 comments on commit bc9c30c

Please sign in to comment.