Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/impactguard/languages/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -353,15 +355,7 @@ def _extract_with_regex(
}
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -435,10 +429,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:
Interface unions (``A | B``) introduced in Go 1.18 generics are handled
by splitting on ``|``.
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────────────
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
_TREE_SITTER_AVAILABLE,
call_re,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
Expand All @@ -35,6 +36,7 @@
make_signature_dict,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -355,15 +357,7 @@ def _extract_with_regex(
)
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -432,10 +426,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:
Java does not have union types natively; returns a singleton frozenset
unless the type contains ``|`` (as used in multi-catch clauses).
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────────────────────────────
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -344,15 +346,7 @@ def _extract_with_regex(
}
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -424,10 +418,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:

Splits on ``|`` for union types.
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/kotlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -312,15 +314,7 @@ def _extract_with_regex(
}
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -392,10 +386,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:

Splits on ``|`` (nullable ``T?`` becomes ``T | null``).
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────────────────────
Expand Down
24 changes: 24 additions & 0 deletions src/impactguard/languages/lib/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@ def make_call_dict(
}


def dedupe_signatures_by_fqname(
signatures: list[dict[str, Any]],
) -> list[dict[str, Any]]:
"""Deduplicate signature dicts by ``fqname`` and return sorted output."""
seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in signatures:
fqname = sig["fqname"]
if fqname not in seen:
seen.add(fqname)
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique


def split_pipe_union_members(type_str: str) -> frozenset[str]:
"""Split ``A | B`` style unions, or return a singleton member set."""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})


def _extract_call_name(
node: Any,
source: bytes,
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/ruby.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -343,15 +345,7 @@ def _extract_with_regex(
}
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -425,10 +419,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:
Type unions written with ``|`` (e.g. in Sorbet/RBS annotations) are
split by ``|``.
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────────────
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -301,15 +303,7 @@ def _extract_with_regex(
}
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -383,10 +377,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:
singleton frozenset. If ``|`` appears (e.g. in pattern matching
contexts), each branch is returned as a separate member.
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -340,15 +342,7 @@ def _extract_with_regex(
}
)

seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -420,10 +414,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:

Splits on ``|`` for union/enum types.
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────────────
Expand Down
17 changes: 4 additions & 13 deletions src/impactguard/languages/typescript.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
from .lib.shared import (
_TREE_SITTER_AVAILABLE,
child_of_type,
dedupe_signatures_by_fqname,
extract_calls_with_tree_sitter,
has_ignore_comment_fallback,
make_parser,
node_text,
register_extractor,
split_pipe_union_members,
warn_if_no_tree_sitter,
)

Expand Down Expand Up @@ -700,15 +702,7 @@ def _extract_with_regex(
)

# De-duplicate by fqname (regex patterns may overlap for some forms)
seen: set[str] = set()
unique: list[dict[str, Any]] = []
for sig in all_funcs:
if sig["fqname"] not in seen:
seen.add(sig["fqname"])
unique.append(sig)

unique.sort(key=lambda x: x["fqname"])
return unique
return dedupe_signatures_by_fqname(all_funcs)


def _extract_calls_with_regex(path: Path) -> list[dict[str, Any]]:
Expand Down Expand Up @@ -781,10 +775,7 @@ def parse_union_members(self, type_str: str) -> frozenset[str]:
Handles ``X | Y | null | undefined`` syntax. Each member is
returned as-is (whitespace-stripped).
"""
s = type_str.strip()
if "|" in s:
return frozenset(p.strip() for p in s.split("|"))
return frozenset({s})
return split_pipe_union_members(type_str)


# ── Self-registration ─────────────────────────
Expand Down
Loading