From 023c52d82be418cb99b190c0a6d27c2ba489ab6e Mon Sep 17 00:00:00 2001 From: Calum Young <32770960+calumy@users.noreply.github.com> Date: Tue, 21 Jan 2025 11:09:11 +0000 Subject: [PATCH] Standardise ruff config (#15558) --- crates/ruff_python_ast/generate.py | 12 +-- crates/ruff_python_formatter/generate.py | 11 +-- pyproject.toml | 106 ++++++++++++++--------- scripts/check_ecosystem.py | 2 +- scripts/pyproject.toml | 27 +----- 5 files changed, 77 insertions(+), 81 deletions(-) diff --git a/crates/ruff_python_ast/generate.py b/crates/ruff_python_ast/generate.py index 8cbeed3841..3f29aafc89 100644 --- a/crates/ruff_python_ast/generate.py +++ b/crates/ruff_python_ast/generate.py @@ -174,7 +174,7 @@ def write_owned_enum(out: list[str], groups: list[Group]) -> None: """) for node in group.nodes: out.append( - f"""{group.owned_enum_ty}::{node.variant}(node) => node.visit_source_order(visitor),""" + f"{group.owned_enum_ty}::{node.variant}(node) => node.visit_source_order(visitor)," ) out.append(""" } @@ -234,7 +234,7 @@ def write_ref_enum(out: list[str], groups: list[Group]) -> None: """) for node in group.nodes: out.append( - f"""{group.owned_enum_ty}::{node.variant}(node) => {group.ref_enum_ty}::{node.variant}(node),""" + f"{group.owned_enum_ty}::{node.variant}(node) => {group.ref_enum_ty}::{node.variant}(node)," ) out.append(""" } @@ -311,7 +311,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None: """) for node in group.nodes: out.append( - f"""{group.owned_enum_ty}::{node.variant}(node) => AnyNodeRef::{node.name}(node),""" + f"{group.owned_enum_ty}::{node.variant}(node) => AnyNodeRef::{node.name}(node)," ) out.append(""" } @@ -326,7 +326,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None: """) for node in group.nodes: out.append( - f"""{group.ref_enum_ty}::{node.variant}(node) => AnyNodeRef::{node.name}(node),""" + f"{group.ref_enum_ty}::{node.variant}(node) => AnyNodeRef::{node.name}(node)," ) out.append(""" } @@ -365,7 +365,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None: for group in groups: for node in group.nodes: out.append( - f"""AnyNodeRef::{node.name}(node) => std::ptr::NonNull::from(*node).cast(),""" + f"AnyNodeRef::{node.name}(node) => std::ptr::NonNull::from(*node).cast()," ) out.append(""" } @@ -385,7 +385,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None: for group in groups: for node in group.nodes: out.append( - f"""AnyNodeRef::{node.name}(node) => node.visit_source_order(visitor),""" + f"AnyNodeRef::{node.name}(node) => node.visit_source_order(visitor)," ) out.append(""" } diff --git a/crates/ruff_python_formatter/generate.py b/crates/ruff_python_formatter/generate.py index 4263b26c91..ba8354c2aa 100755 --- a/crates/ruff_python_formatter/generate.py +++ b/crates/ruff_python_formatter/generate.py @@ -3,6 +3,7 @@ """See CONTRIBUTING.md""" # %% +from __future__ import annotations import re from collections import defaultdict @@ -34,8 +35,8 @@ nodes = [] for node_line in node_lines: node = node_line.split("(")[1].split(")")[0].split("::")[-1].removeprefix("&'a ") # `FString` has a custom implementation while the formatting for - # `FStringLiteralElement`, `FStringFormatSpec` and `FStringExpressionElement` are handled by the `FString` - # implementation. + # `FStringLiteralElement`, `FStringFormatSpec` and `FStringExpressionElement` are + # handled by the `FString` implementation. if node in ( "FStringLiteralElement", "FStringExpressionElement", @@ -112,7 +113,7 @@ for group, group_nodes in nodes_grouped.items(): write!(f, [verbatim_text(item)]) }} }} - """.strip() # noqa: E501 + """.strip() node_path.write_text(rustfmt(code)) @@ -127,7 +128,7 @@ use crate::{AsFormat, FormatNodeRule, IntoFormat, PyFormatter}; use ruff_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule}; use ruff_python_ast as ast; -""" # noqa: E501 +""" for node in nodes: text = f""" impl FormatRule> @@ -169,7 +170,7 @@ for node in nodes: ) }} }} - """ # noqa: E501 + """ generated += text out.write_text(rustfmt(generated)) diff --git a/pyproject.toml b/pyproject.toml index 7f44cc8129..10f2e85e18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,31 +11,31 @@ readme = "README.md" requires-python = ">=3.7" license = { file = "LICENSE" } keywords = [ - "automation", - "flake8", - "pycodestyle", - "pyflakes", - "pylint", - "clippy", + "automation", + "flake8", + "pycodestyle", + "pyflakes", + "pylint", + "clippy", ] classifiers = [ - "Development Status :: 5 - Production/Stable", - "Environment :: Console", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Rust", - "Topic :: Software Development :: Libraries :: Python Modules", - "Topic :: Software Development :: Quality Assurance", + "Development Status :: 5 - Production/Stable", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Rust", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Software Development :: Quality Assurance", ] [project.urls] @@ -50,31 +50,51 @@ module-name = "ruff" python-source = "python" strip = true exclude = [ - "crates/ruff_linter/resources/test/fixtures/**/*", - "crates/ruff_linter/src/rules/*/snapshots/**/*" + "crates/ruff_linter/resources/test/fixtures/**/*", + "crates/ruff_linter/src/rules/*/snapshots/**/*" ] include = [ - "rust-toolchain.toml" + "rust-toolchain.toml" ] [tool.ruff] +target-version = "py38" extend-exclude = [ - "crates/red_knot_vendored/vendor/", - "crates/ruff/resources/", - "crates/ruff_linter/resources/", - "crates/ruff_python_formatter/resources/", - "crates/ruff_python_parser/resources/" + "crates/red_knot_vendored/vendor/", + "crates/ruff/resources/", + "crates/ruff_linter/resources/", + "crates/ruff_python_formatter/resources/", + "crates/ruff_python_parser/resources/" ] [tool.ruff.lint] +select = [ + "E", # pycodestyle (error) + "F", # pyflakes + "B", # bugbear + "B9", + "C4", # flake8-comprehensions + "SIM", # flake8-simplify + "I", # isort + "UP", # pyupgrade + "PIE", # flake8-pie + "PGH", # pygrep-hooks + "PYI", # flake8-pyi + "RUF", +] + ignore = [ - # Conflicts with the formatter - "COM812", "ISC001" -] -extend-select = [ - "I", + # only relevant if you run a script with `python -0`, + # which seems unlikely for any of the scripts in this repo + "B011", + # Leave it to the formatter to split long lines and + # the judgement of all of us. + "E501" ] +[tool.ruff.lint.isort] +required-imports = ["from __future__ import annotations"] + [tool.black] force-exclude = ''' /( @@ -112,11 +132,11 @@ changelog_sections.__unknown__ = "Other changes" changelog_contributors = false version_files = [ - "README.md", - "docs/integrations.md", - "docs/tutorial.md", - "crates/ruff/Cargo.toml", - "crates/ruff_linter/Cargo.toml", - "crates/ruff_wasm/Cargo.toml", - "scripts/benchmarks/pyproject.toml", + "README.md", + "docs/integrations.md", + "docs/tutorial.md", + "crates/ruff/Cargo.toml", + "crates/ruff_linter/Cargo.toml", + "crates/ruff_wasm/Cargo.toml", + "scripts/benchmarks/pyproject.toml", ] diff --git a/scripts/check_ecosystem.py b/scripts/check_ecosystem.py index 86729d4347..824cdcc217 100755 --- a/scripts/check_ecosystem.py +++ b/scripts/check_ecosystem.py @@ -449,7 +449,7 @@ async def main( if matches is None: # Handle case where there are no regex matches e.g. - # + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # noqa: E501 + # + "?application=AIRFLOW&authenticator=TEST_AUTH&role=TEST_ROLE&warehouse=TEST_WAREHOUSE" # Which was found in local testing continue diff --git a/scripts/pyproject.toml b/scripts/pyproject.toml index 3a597fcf83..475e14805e 100644 --- a/scripts/pyproject.toml +++ b/scripts/pyproject.toml @@ -8,29 +8,4 @@ requires-python = ">=3.11" line-length = 88 [tool.ruff] -line-length = 88 - -[tool.ruff.lint] -select = [ - "E", # pycodestyle (error) - "F", # pyflakes - "B", # bugbear - "B9", - "C4", # flake8-comprehensions - "SIM", # flake8-simplify - "I", # isort - "UP", # pyupgrade - "PIE", # flake8-pie - "PGH", # pygrep-hooks - "PYI", # flake8-pyi - "RUF", -] - -ignore = [ - # only relevant if you run a script with `python -0`, - # which seems unlikely for any of the scripts in this directory - "B011" -] - -[tool.ruff.lint.isort] -required-imports = ["from __future__ import annotations"] +extend = "../pyproject.toml"