mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-09 22:25:20 +00:00
many-to-one 6/9: Implement ruff_macros::map_codes
This commit is contained in:
parent
9eda286dcd
commit
c314e10e54
19 changed files with 505 additions and 271 deletions
|
@ -11,7 +11,7 @@ Example usage:
|
|||
|
||||
import argparse
|
||||
|
||||
from _utils import ROOT_DIR, dir_name, get_indent
|
||||
from _utils import ROOT_DIR, dir_name, get_indent, pascal_case
|
||||
|
||||
|
||||
def snake_case(name: str) -> str:
|
||||
|
@ -128,12 +128,24 @@ pub fn {rule_name_snake}(checker: &mut Checker) {{}}
|
|||
|
||||
if line.strip() == f"// {linter}":
|
||||
indent = get_indent(line)
|
||||
fp.write(f"{indent}{code} => rules::{dir_name(linter)}::rules::{name},")
|
||||
fp.write(f"{indent}rules::{dir_name(linter)}::rules::{name},")
|
||||
fp.write("\n")
|
||||
has_written = True
|
||||
|
||||
assert has_written
|
||||
|
||||
text = ""
|
||||
with (ROOT_DIR / "crates/ruff/src/codes.rs").open("r") as fp:
|
||||
while (line := next(fp)).strip() != f"// {linter}":
|
||||
text += line
|
||||
text += line
|
||||
linter_variant = pascal_case(linter)
|
||||
text += " "*8 + f'({linter_variant}, "{code}") => Rule::{name},\n'
|
||||
text += fp.read()
|
||||
|
||||
with (ROOT_DIR / "crates/ruff/src/codes.rs").open("w") as fp:
|
||||
fp.write(text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue