diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 104e2264a4..0198a67c5e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,18 +37,6 @@ repos: exclude_types: [json, pofile] exclude: 'changelog/|py.typed|disnake/bin/COPYING|.github/PULL_REQUEST_TEMPLATE.md|.github/CODEOWNERS|LICENSE|MANIFEST.in' - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - args: ["--profile", "black", "--extend-skip", "examples"] - name: "run isort in all files" - exclude: ^examples/ - - id: isort - args: ["--profile", "black", "--thirdparty", "disnake"] - name: "run isort in examples" - files: ^examples/ - - repo: https://github.com/psf/black-pre-commit-mirror rev: 23.9.1 hooks: @@ -56,6 +44,7 @@ repos: name: "run black in all files" - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.0.292 + rev: v0.3.4 hooks: - id: ruff + args: [--fix, --fixable=I] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e1151d59b3..60c31f2f44 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -70,7 +70,7 @@ Once PDM is installed, use the following command to initialize a virtual environ $ pdm run setup_env ``` -Other tools used in this project include [black](https://black.readthedocs.io/en/stable/) + [isort](https://pycqa.github.io/isort/) (formatters), [ruff](https://beta.ruff.rs/docs/) (linter), and [pyright](https://microsoft.github.io/pyright/#/) (type-checker). For the most part, these automatically run on every commit with no additional action required - see below for details. +Other tools used in this project include [black](https://black.readthedocs.io/en/stable/) (formatter), [ruff](https://beta.ruff.rs/docs/) (linter), and [pyright](https://microsoft.github.io/pyright/#/) (type-checker). For the most part, these automatically run on every commit with no additional action required - see below for details. All of the following checks also automatically run for every PR on GitHub, so don't worry if you're not sure whether you missed anything. A PR cannot be merged as long as there are any failing checks. diff --git a/examples/.ruff.toml b/examples/.ruff.toml new file mode 100644 index 0000000000..ae286560b9 --- /dev/null +++ b/examples/.ruff.toml @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: MIT + +extend = "../pyproject.toml" +src = ["../"] + +[lint.isort] +known-third-party = ["disnake"] diff --git a/pyproject.toml b/pyproject.toml index c103f1ee4d..a184953fdd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ tools = [ "slotscheck~=0.16.4", "python-dotenv~=1.0.0", "check-manifest==0.49", - "ruff==0.0.292", + "ruff==0.3.4", ] changelog = [ "towncrier==23.6.0", @@ -106,7 +106,6 @@ build = [ [tool.pdm.scripts] black = { composite = ["lint black"], help = "Run black" } docs = { cmd = "nox -Rs docs --", help = "Build the documentation for development" } -isort = { composite = ["lint isort"], help = "Run isort" } lint = { cmd = "nox -Rs lint --", help = "Check all files for linting errors" } pyright = { cmd = "nox -Rs pyright --", help = "Run pyright" } setup_env = { cmd = "pdm install -d -G speed -G docs -G voice", help = "Set up the local environment and all dependencies" } @@ -117,7 +116,6 @@ test = { cmd = "nox -Rs test --", help = "Run pytest" } [tool.taskipy.tasks] black = { cmd = "black", help = "Run black" } docs = { cmd = "docs", help = "Build the documentation for development" } -isort = { cmd = "isort", help = "Run isort" } lint = { cmd = "lint", help = "Check all files for linting errors" } pyright = { cmd = "pyright", help = "Run pyright" } setup_env = { cmd = "setup_env", help = "Setup the local environment and set up all dependencies" } @@ -130,16 +128,11 @@ runner = "pdm run" line-length = 100 target-version = ["py38", "py39", "py310", "py311", "py312"] -[tool.isort] -profile = "black" -py_version = 38 -line_length = 100 -combine_as_imports = true -filter_files = true - [tool.ruff] line-length = 100 target-version = "py38" + +[tool.ruff.lint] select = [ # commented out codes are intended to be enabled in future prs "F", # pyflakes @@ -169,6 +162,7 @@ select = [ # "PLR", # pylint refactor "PLW", # pylint warnings "TRY002", "TRY004", "TRY201", # tryceratops + "I", # isort ] ignore = [ # star imports @@ -200,7 +194,7 @@ ignore = [ # typevar names don't match variance (we don't always want this) "PLC0105", - # import aliases are fixed by isort + # import aliases are fixed by ruff "PLC0414", # outer loop variables are overwritten by inner assignment target, these are mostly intentional @@ -213,6 +207,9 @@ ignore = [ "TCH002", "TCH003", + "S311", # insecure RNG usage, we don't use these for security-related things + "PLE0237", # pyright seems to catch this already + # temporary disables, to fix later "D205", # blank line required between summary and description "D401", # first line of docstring should be in imperative mood @@ -224,7 +221,7 @@ ignore = [ "T201", # print statements ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "disnake/__main__.py" = ["T201"] # print statements are okay in our simple cli "disnake/i18n.py" = [ "B027", # lib bug. Excluded here because ruff does not have a --disable-noqa flag yet @@ -250,11 +247,17 @@ ignore = [ "examples/basic_voice.py" = ["S104"] # possible binding to all interfaces "examples/views/tic_tac_toe.py" = ["E741"] # ambigious variable name: `O` -[tool.ruff.flake8-pytest-style] +[tool.ruff.lint.isort] +combine-as-imports = true + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.flake8-pytest-style] fixture-parentheses = false mark-parentheses = false -[tool.ruff.flake8-tidy-imports.banned-api] +[tool.ruff.lint.flake8-tidy-imports.banned-api] "subprocess".msg = "Consider possible security implications associated with the subprocess module." # replaces S404 [tool.towncrier]