mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-07 21:25:08 +00:00
Standardise ruff config (#15558)
This commit is contained in:
parent
c616650dfa
commit
023c52d82b
5 changed files with 77 additions and 81 deletions
|
@ -174,7 +174,7 @@ def write_owned_enum(out: list[str], groups: list[Group]) -> None:
|
||||||
""")
|
""")
|
||||||
for node in group.nodes:
|
for node in group.nodes:
|
||||||
out.append(
|
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("""
|
out.append("""
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ def write_ref_enum(out: list[str], groups: list[Group]) -> None:
|
||||||
""")
|
""")
|
||||||
for node in group.nodes:
|
for node in group.nodes:
|
||||||
out.append(
|
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("""
|
out.append("""
|
||||||
}
|
}
|
||||||
|
@ -311,7 +311,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None:
|
||||||
""")
|
""")
|
||||||
for node in group.nodes:
|
for node in group.nodes:
|
||||||
out.append(
|
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("""
|
out.append("""
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None:
|
||||||
""")
|
""")
|
||||||
for node in group.nodes:
|
for node in group.nodes:
|
||||||
out.append(
|
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("""
|
out.append("""
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None:
|
||||||
for group in groups:
|
for group in groups:
|
||||||
for node in group.nodes:
|
for node in group.nodes:
|
||||||
out.append(
|
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("""
|
out.append("""
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ def write_anynoderef(out: list[str], groups: list[Group]) -> None:
|
||||||
for group in groups:
|
for group in groups:
|
||||||
for node in group.nodes:
|
for node in group.nodes:
|
||||||
out.append(
|
out.append(
|
||||||
f"""AnyNodeRef::{node.name}(node) => node.visit_source_order(visitor),"""
|
f"AnyNodeRef::{node.name}(node) => node.visit_source_order(visitor),"
|
||||||
)
|
)
|
||||||
out.append("""
|
out.append("""
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"""See CONTRIBUTING.md"""
|
"""See CONTRIBUTING.md"""
|
||||||
|
|
||||||
# %%
|
# %%
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
@ -34,8 +35,8 @@ nodes = []
|
||||||
for node_line in node_lines:
|
for node_line in node_lines:
|
||||||
node = node_line.split("(")[1].split(")")[0].split("::")[-1].removeprefix("&'a ")
|
node = node_line.split("(")[1].split(")")[0].split("::")[-1].removeprefix("&'a ")
|
||||||
# `FString` has a custom implementation while the formatting for
|
# `FString` has a custom implementation while the formatting for
|
||||||
# `FStringLiteralElement`, `FStringFormatSpec` and `FStringExpressionElement` are handled by the `FString`
|
# `FStringLiteralElement`, `FStringFormatSpec` and `FStringExpressionElement` are
|
||||||
# implementation.
|
# handled by the `FString` implementation.
|
||||||
if node in (
|
if node in (
|
||||||
"FStringLiteralElement",
|
"FStringLiteralElement",
|
||||||
"FStringExpressionElement",
|
"FStringExpressionElement",
|
||||||
|
@ -112,7 +113,7 @@ for group, group_nodes in nodes_grouped.items():
|
||||||
write!(f, [verbatim_text(item)])
|
write!(f, [verbatim_text(item)])
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
""".strip() # noqa: E501
|
""".strip()
|
||||||
|
|
||||||
node_path.write_text(rustfmt(code))
|
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_formatter::{FormatOwnedWithRule, FormatRefWithRule, FormatResult, FormatRule};
|
||||||
use ruff_python_ast as ast;
|
use ruff_python_ast as ast;
|
||||||
|
|
||||||
""" # noqa: E501
|
"""
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
text = f"""
|
text = f"""
|
||||||
impl FormatRule<ast::{node}, PyFormatContext<'_>>
|
impl FormatRule<ast::{node}, PyFormatContext<'_>>
|
||||||
|
@ -169,7 +170,7 @@ for node in nodes:
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
""" # noqa: E501
|
"""
|
||||||
generated += text
|
generated += text
|
||||||
|
|
||||||
out.write_text(rustfmt(generated))
|
out.write_text(rustfmt(generated))
|
||||||
|
|
106
pyproject.toml
106
pyproject.toml
|
@ -11,31 +11,31 @@ readme = "README.md"
|
||||||
requires-python = ">=3.7"
|
requires-python = ">=3.7"
|
||||||
license = { file = "LICENSE" }
|
license = { file = "LICENSE" }
|
||||||
keywords = [
|
keywords = [
|
||||||
"automation",
|
"automation",
|
||||||
"flake8",
|
"flake8",
|
||||||
"pycodestyle",
|
"pycodestyle",
|
||||||
"pyflakes",
|
"pyflakes",
|
||||||
"pylint",
|
"pylint",
|
||||||
"clippy",
|
"clippy",
|
||||||
]
|
]
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 5 - Production/Stable",
|
||||||
"Environment :: Console",
|
"Environment :: Console",
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
"Programming Language :: Python",
|
"Programming Language :: Python",
|
||||||
"Programming Language :: Python :: 3.7",
|
"Programming Language :: Python :: 3.7",
|
||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
"Programming Language :: Python :: 3.12",
|
"Programming Language :: Python :: 3.12",
|
||||||
"Programming Language :: Python :: 3.13",
|
"Programming Language :: Python :: 3.13",
|
||||||
"Programming Language :: Python :: 3 :: Only",
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
"Programming Language :: Rust",
|
"Programming Language :: Rust",
|
||||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
"Topic :: Software Development :: Quality Assurance",
|
"Topic :: Software Development :: Quality Assurance",
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
|
@ -50,31 +50,51 @@ module-name = "ruff"
|
||||||
python-source = "python"
|
python-source = "python"
|
||||||
strip = true
|
strip = true
|
||||||
exclude = [
|
exclude = [
|
||||||
"crates/ruff_linter/resources/test/fixtures/**/*",
|
"crates/ruff_linter/resources/test/fixtures/**/*",
|
||||||
"crates/ruff_linter/src/rules/*/snapshots/**/*"
|
"crates/ruff_linter/src/rules/*/snapshots/**/*"
|
||||||
]
|
]
|
||||||
include = [
|
include = [
|
||||||
"rust-toolchain.toml"
|
"rust-toolchain.toml"
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
|
target-version = "py38"
|
||||||
extend-exclude = [
|
extend-exclude = [
|
||||||
"crates/red_knot_vendored/vendor/",
|
"crates/red_knot_vendored/vendor/",
|
||||||
"crates/ruff/resources/",
|
"crates/ruff/resources/",
|
||||||
"crates/ruff_linter/resources/",
|
"crates/ruff_linter/resources/",
|
||||||
"crates/ruff_python_formatter/resources/",
|
"crates/ruff_python_formatter/resources/",
|
||||||
"crates/ruff_python_parser/resources/"
|
"crates/ruff_python_parser/resources/"
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ruff.lint]
|
[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 = [
|
ignore = [
|
||||||
# Conflicts with the formatter
|
# only relevant if you run a script with `python -0`,
|
||||||
"COM812", "ISC001"
|
# which seems unlikely for any of the scripts in this repo
|
||||||
]
|
"B011",
|
||||||
extend-select = [
|
# Leave it to the formatter to split long lines and
|
||||||
"I",
|
# the judgement of all of us.
|
||||||
|
"E501"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[tool.ruff.lint.isort]
|
||||||
|
required-imports = ["from __future__ import annotations"]
|
||||||
|
|
||||||
[tool.black]
|
[tool.black]
|
||||||
force-exclude = '''
|
force-exclude = '''
|
||||||
/(
|
/(
|
||||||
|
@ -112,11 +132,11 @@ changelog_sections.__unknown__ = "Other changes"
|
||||||
changelog_contributors = false
|
changelog_contributors = false
|
||||||
|
|
||||||
version_files = [
|
version_files = [
|
||||||
"README.md",
|
"README.md",
|
||||||
"docs/integrations.md",
|
"docs/integrations.md",
|
||||||
"docs/tutorial.md",
|
"docs/tutorial.md",
|
||||||
"crates/ruff/Cargo.toml",
|
"crates/ruff/Cargo.toml",
|
||||||
"crates/ruff_linter/Cargo.toml",
|
"crates/ruff_linter/Cargo.toml",
|
||||||
"crates/ruff_wasm/Cargo.toml",
|
"crates/ruff_wasm/Cargo.toml",
|
||||||
"scripts/benchmarks/pyproject.toml",
|
"scripts/benchmarks/pyproject.toml",
|
||||||
]
|
]
|
||||||
|
|
|
@ -449,7 +449,7 @@ async def main(
|
||||||
|
|
||||||
if matches is None:
|
if matches is None:
|
||||||
# Handle case where there are no regex matches e.g.
|
# 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
|
# Which was found in local testing
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
@ -8,29 +8,4 @@ requires-python = ">=3.11"
|
||||||
line-length = 88
|
line-length = 88
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
line-length = 88
|
extend = "../pyproject.toml"
|
||||||
|
|
||||||
[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"]
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue