mirror of https://github.com/astral-sh/ruff
Update .pre-commit-config.yml (#2139)
This commit is contained in:
parent
0cac1a0d21
commit
82d7814101
|
|
@ -3,6 +3,8 @@ repos:
|
||||||
rev: v0.0.233
|
rev: v0.0.233
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
|
args: [--fix]
|
||||||
|
exclude: ^resources
|
||||||
|
|
||||||
- repo: https://github.com/abravalheri/validate-pyproject
|
- repo: https://github.com/abravalheri/validate-pyproject
|
||||||
rev: v0.10.1
|
rev: v0.10.1
|
||||||
|
|
@ -13,6 +15,6 @@ repos:
|
||||||
hooks:
|
hooks:
|
||||||
- id: cargo-fmt
|
- id: cargo-fmt
|
||||||
name: cargo fmt
|
name: cargo fmt
|
||||||
entry: cargo fmt --
|
entry: cargo +nightly fmt --
|
||||||
language: rust
|
language: rust
|
||||||
types: [rust]
|
types: [rust]
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
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:
|
def dir_name(linter_name: str) -> str:
|
||||||
|
|
@ -15,4 +14,4 @@ def pascal_case(linter_name: str) -> str:
|
||||||
|
|
||||||
|
|
||||||
def get_indent(line: 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 argparse
|
||||||
import os
|
|
||||||
|
|
||||||
from _utils import ROOT_DIR, dir_name, get_indent, pascal_case
|
from _utils import ROOT_DIR, dir_name, get_indent, pascal_case
|
||||||
|
|
||||||
|
|
||||||
def main(*, plugin: str, url: str, prefix_code: str) -> None:
|
def main(*, plugin: str, url: str, prefix_code: str) -> None:
|
||||||
|
"""Generate boilerplate for a new plugin."""
|
||||||
# Create the test fixture folder.
|
# Create the test fixture folder.
|
||||||
os.makedirs(
|
(ROOT_DIR / "resources/test/fixtures" / dir_name(plugin)).mkdir(
|
||||||
ROOT_DIR / "resources/test/fixtures" / dir_name(plugin),
|
|
||||||
exist_ok=True,
|
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
|
# Create a subdirectory for rules and create a `mod.rs` placeholder
|
||||||
|
|
@ -84,7 +83,7 @@ mod tests {
|
||||||
fp.write(f"{indent}// {plugin}")
|
fp.write(f"{indent}// {plugin}")
|
||||||
fp.write("\n")
|
fp.write("\n")
|
||||||
|
|
||||||
elif line.strip() == '/// Ruff-specific rules':
|
elif line.strip() == "/// Ruff-specific rules":
|
||||||
fp.write(f"/// [{plugin}]({url})\n")
|
fp.write(f"/// [{plugin}]({url})\n")
|
||||||
fp.write(f'{indent}#[prefix = "{prefix_code}"]\n')
|
fp.write(f'{indent}#[prefix = "{prefix_code}"]\n')
|
||||||
fp.write(f"{indent}{pascal_case(plugin)},")
|
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:
|
def snake_case(name: str) -> str:
|
||||||
"""Convert from PascalCase to snake_case."""
|
"""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:
|
def main(*, name: str, code: str, linter: str) -> None:
|
||||||
|
"""Generate boilerplate for a new rule."""
|
||||||
# Create a test fixture.
|
# 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
|
pass
|
||||||
|
|
||||||
plugin_module = ROOT_DIR / "src/rules" / dir_name(linter)
|
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():
|
for line in content.splitlines():
|
||||||
if line.strip() == "fn rules(rule_code: Rule, path: &Path) -> Result<()> {":
|
if line.strip() == "fn rules(rule_code: Rule, path: &Path) -> Result<()> {":
|
||||||
indent = get_indent(line)
|
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("\n")
|
||||||
|
|
||||||
fp.write(line)
|
fp.write(line)
|
||||||
fp.write("\n")
|
fp.write("\n")
|
||||||
|
|
||||||
# Add the exports
|
# Add the exports
|
||||||
rules_dir = plugin_module / "rules"
|
rules_dir = plugin_module / "rules"
|
||||||
rules_mod = rules_dir / "mod.rs"
|
rules_mod = rules_dir / "mod.rs"
|
||||||
|
|
||||||
|
|
@ -83,14 +90,14 @@ impl Violation for %s {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
% (name, name)
|
% (name, name),
|
||||||
)
|
)
|
||||||
fp.write("\n")
|
fp.write("\n")
|
||||||
fp.write(
|
fp.write(
|
||||||
f"""
|
f"""
|
||||||
/// {code}
|
/// {code}
|
||||||
pub fn {rule_name_snake}(checker: &mut Checker) {{}}
|
pub fn {rule_name_snake}(checker: &mut Checker) {{}}
|
||||||
"""
|
""",
|
||||||
)
|
)
|
||||||
fp.write("\n")
|
fp.write("\n")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
select = ["ALL"]
|
select = ["ALL"]
|
||||||
ignore = [
|
ignore = [
|
||||||
"S101", # assert-used
|
"E501", # line-too-long
|
||||||
"PLR2004", # magic-value-comparison
|
"INP001", # implicit-namespace-package
|
||||||
|
"PLR2004", # magic-value-comparison
|
||||||
|
"S101", # assert-used
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.ruff.pydocstyle]
|
[tool.ruff.pydocstyle]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue