Add unused object detection, negation substitution, and XR comment support#213
Merged
Add unused object detection, negation substitution, and XR comment support#213
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UnusedObjectRuleandReferenceLocationmodels,unused_objects()method onHConfig, XR driver rules for ACLs, prefix-sets, community-sets, and route-policies!comment lines are attached to the next sibling'scommentsset via apost_load_callback, rather than being stripped. Also runspost_load_callbacksinget_hconfig_fast_loadper_line_subfeature to remediation #101: Negation regex substitution — newNegationSubRulemodel andnegation_substep innegate()for platform-specific negation transformations (e.g., truncating SNMP user removal)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 integrationtests/test_negation_sub.py(4 tests): SNMP user truncation, prefix-list truncation, no-match fallback, full remediationtests/test_xr_comments.py(6 tests): comment attachment, multiple comments, no comment children, delimiter stripping, fast_load preservation, hash comment strippingTest plan
poetry run ./scripts/build.py lint-and-test— full suite passes (linting, type checking, 95%+ coverage)🤖 Generated with Claude Code