mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
Update .pre-commit-config.yml (#2139)
This commit is contained in:
parent
0cac1a0d21
commit
82d7814101
5 changed files with 26 additions and 17 deletions
|
|
@ -3,6 +3,8 @@ repos:
|
|||
rev: v0.0.233
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--fix]
|
||||
exclude: ^resources
|
||||
|
||||
- repo: https://github.com/abravalheri/validate-pyproject
|
||||
rev: v0.10.1
|
||||
|
|
@ -13,6 +15,6 @@ repos:
|
|||
hooks:
|
||||
- id: cargo-fmt
|
||||
name: cargo fmt
|
||||
entry: cargo fmt --
|
||||
entry: cargo +nightly fmt --
|
||||
language: rust
|
||||
types: [rust]
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
ROOT_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
ROOT_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def dir_name(linter_name: str) -> str:
|
||||
|
|
@ -15,4 +14,4 @@ def pascal_case(linter_name: str) -> str:
|
|||
|
||||
|
||||
def get_indent(line: str) -> str:
|
||||
return re.match(r"^\s*", line).group() # pyright: ignore[reportOptionalMemberAccess]
|
||||
return re.match(r"^\s*", line).group() # type: ignore[union-attr]
|
||||
|
|
|
|||
|
|
@ -10,15 +10,14 @@ Example usage:
|
|||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from _utils import ROOT_DIR, dir_name, get_indent, pascal_case
|
||||
|
||||
|
||||
def main(*, plugin: str, url: str, prefix_code: str) -> None:
|
||||
"""Generate boilerplate for a new plugin."""
|
||||
# Create the test fixture folder.
|
||||
os.makedirs(
|
||||
ROOT_DIR / "resources/test/fixtures" / dir_name(plugin),
|
||||
(ROOT_DIR / "resources/test/fixtures" / dir_name(plugin)).mkdir(
|
||||
exist_ok=True,
|
||||
)
|
||||
|
||||
|
|
@ -56,7 +55,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
"""
|
||||
% dir_name(plugin)
|
||||
% dir_name(plugin),
|
||||
)
|
||||
|
||||
# Create a subdirectory for rules and create a `mod.rs` placeholder
|
||||
|
|
@ -84,7 +83,7 @@ mod tests {
|
|||
fp.write(f"{indent}// {plugin}")
|
||||
fp.write("\n")
|
||||
|
||||
elif line.strip() == '/// Ruff-specific rules':
|
||||
elif line.strip() == "/// Ruff-specific rules":
|
||||
fp.write(f"/// [{plugin}]({url})\n")
|
||||
fp.write(f'{indent}#[prefix = "{prefix_code}"]\n')
|
||||
fp.write(f"{indent}{pascal_case(plugin)},")
|
||||
|
|
|
|||
|
|
@ -16,12 +16,17 @@ from _utils import ROOT_DIR, dir_name, get_indent
|
|||
|
||||
def snake_case(name: str) -> str:
|
||||
"""Convert from PascalCase to snake_case."""
|
||||
return "".join(f"_{word.lower()}" if word.isupper() else word for word in name).lstrip("_")
|
||||
return "".join(
|
||||
f"_{word.lower()}" if word.isupper() else word for word in name
|
||||
).lstrip("_")
|
||||
|
||||
|
||||
def main(*, name: str, code: str, linter: str) -> None:
|
||||
"""Generate boilerplate for a new rule."""
|
||||
# Create a test fixture.
|
||||
with (ROOT_DIR / "resources/test/fixtures" / dir_name(linter) / f"{code}.py").open("a"):
|
||||
with (ROOT_DIR / "resources/test/fixtures" / dir_name(linter) / f"{code}.py").open(
|
||||
"a",
|
||||
):
|
||||
pass
|
||||
|
||||
plugin_module = ROOT_DIR / "src/rules" / dir_name(linter)
|
||||
|
|
@ -35,13 +40,15 @@ def main(*, name: str, code: str, linter: str) -> None:
|
|||
for line in content.splitlines():
|
||||
if line.strip() == "fn rules(rule_code: Rule, path: &Path) -> Result<()> {":
|
||||
indent = get_indent(line)
|
||||
fp.write(f'{indent}#[test_case(Rule::{name}, Path::new("{code}.py"); "{code}")]')
|
||||
fp.write(
|
||||
f'{indent}#[test_case(Rule::{name}, Path::new("{code}.py"); "{code}")]',
|
||||
)
|
||||
fp.write("\n")
|
||||
|
||||
fp.write(line)
|
||||
fp.write("\n")
|
||||
|
||||
# Add the exports
|
||||
# Add the exports
|
||||
rules_dir = plugin_module / "rules"
|
||||
rules_mod = rules_dir / "mod.rs"
|
||||
|
||||
|
|
@ -83,14 +90,14 @@ impl Violation for %s {
|
|||
}
|
||||
}
|
||||
"""
|
||||
% (name, name)
|
||||
% (name, name),
|
||||
)
|
||||
fp.write("\n")
|
||||
fp.write(
|
||||
f"""
|
||||
/// {code}
|
||||
pub fn {rule_name_snake}(checker: &mut Checker) {{}}
|
||||
"""
|
||||
""",
|
||||
)
|
||||
fp.write("\n")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
[tool.ruff]
|
||||
select = ["ALL"]
|
||||
ignore = [
|
||||
"S101", # assert-used
|
||||
"PLR2004", # magic-value-comparison
|
||||
"E501", # line-too-long
|
||||
"INP001", # implicit-namespace-package
|
||||
"PLR2004", # magic-value-comparison
|
||||
"S101", # assert-used
|
||||
]
|
||||
|
||||
[tool.ruff.pydocstyle]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue