Skip to content

Commit

Permalink
refactor: tidy codes
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Aug 17, 2024
1 parent 6bf4240 commit e98d533
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,11 @@ def merge_literals_to_regex(literals: Iterable[str]) -> str:
def merge_regexes(regexes: Iterable[str]) -> str:
"""Merge regex strings into a single regex string."""
regexes = tuple(regexes)
if len(regexes) == 0:
if not regexes:
return r"~^(?#match nothing)"
if len(regexes) == 1:
merged = regexes[0]
else:
merged = "(?:" + ")|(?:".join(regexes) + ")"
return f"(?:{merged})"
return f"(?:{regexes[0]})"
return f"(?:{'|'.join(f'(?:{regex})' for regex in regexes)})"


def parse_regex_flags(flags: Iterable[str]) -> int:
Expand Down Expand Up @@ -424,11 +422,7 @@ def get_syntax_name(syntax: sublime.Syntax) -> str:
def stringify(obj: Any) -> str:
"""Custom object-to-string converter. Just used for debug messages."""
if isinstance(obj, sublime.View):
if filepath := obj.file_name():
filepath = Path(filepath).as_posix()
else:
filepath = ""

filepath = Path(filepath).as_posix() if (filepath := obj.file_name()) else ""
return f'View({obj.id()}, "{filepath}")'

r = repr(obj)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ select = [
"I",
"UP",
"FURB",
# "SIM",
"SIM",
]
ignore = ["E203"]

Expand Down

0 comments on commit e98d533

Please sign in to comment.