Skip to content

Add unused object detection, negation substitution, and XR comment support#213

Merged
jtdub merged 4 commits intomasterfrom
issues-15-30-101
Mar 20, 2026
Merged

Add unused object detection, negation substitution, and XR comment support#213
jtdub merged 4 commits intomasterfrom
issues-15-30-101

Conversation

@jtdub
Copy link
Contributor

@jtdub jtdub commented Mar 20, 2026

Summary

New tests (15 total)

  • tests/test_unused_objects.py (5 tests): unused ACL detection, used ACL not detected, empty rules, multiple reference locations, XR driver integration
  • tests/test_negation_sub.py (4 tests): SNMP user truncation, prefix-list truncation, no-match fallback, full remediation
  • tests/test_xr_comments.py (6 tests): comment attachment, multiple comments, no comment children, delimiter stripping, fast_load preservation, hash comment stripping

Test plan

  • All 15 new tests pass
  • poetry run ./scripts/build.py lint-and-test — full suite passes (linting, type checking, 95%+ coverage)

🤖 Generated with Claude Code

jtdub and others added 4 commits March 19, 2026 20:44
…fix pyproject.toml

Features:
- Unused object detection (#15): Add UnusedObjectRule and ReferenceLocation
  models, unused_objects() method on HConfig, and XR driver rules for ACLs,
  prefix-sets, community-sets, and route-policies.
- Negation substitution (#101): Add NegationSubRule model and negation_sub
  step in negate() for regex-based negation transformations.
- XR comment preservation (#30): Narrow per_line_sub to only strip empty !
  delimiters, add post_load_callback to attach ! comments to next sibling's
  comments set. Also run post_load_callbacks in get_hconfig_fast_load.
- Fix pyproject.toml (#190): Close author email brackets, remove duplicate
  pylint extension, fix "Coverred" typos.
- Update CLAUDE.md with TDD principles.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move unused object detection to opt-in only — not enabled in any driver
by default to avoid unintended consequences. Add unused_objects and
negation_sub processing to load_hconfig_v2_options. Update drivers
documentation with examples for extending drivers with unused object
detection and negation substitution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix _fixup_xr_comments to use removeprefix("!").lstrip(" ") instead
  of lstrip("! ") to avoid stripping chars from comment body
- Add test for comment with leading ! in body (e.g., "!important")
- Add test for negation_sub via load_hconfig_v2_options
- Add test for name_re that doesn't match (safely skipped)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jtdub jtdub merged commit 082959a into master Mar 20, 2026
5 checks passed
@jtdub jtdub deleted the issues-15-30-101 branch March 20, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant