Improve add_rule.py and add_plugin.py scripts (#3725)

This commit is contained in:
Jonathan Plasse 2023-03-25 17:05:39 +01:00 committed by GitHub
parent 2659336ed1
commit fec4fa39a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 126 additions and 49 deletions

View file

@ -13,5 +13,12 @@ def pascal_case(linter_name: str) -> str:
return "".join(word.title() for word in linter_name.split("-"))
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("_")
def get_indent(line: str) -> str:
return re.match(r"^\s*", line).group() # type: ignore[union-attr]