Skip to content

Releases: nanorepublica/django-deadcode

v0.9.0

11 Dec 21:38

Choose a tag to compare

v0.9.0 (2025-12-11)

Chore

Feature

  • feat: support module path for exclusions as well as namespaces (56bf8fd)

v0.8.0

04 Dec 19:48

Choose a tag to compare

v0.8.0 (2025-12-04)

Documentation

  • docs: add spec for fixing unreferenced URL detection

Root cause identified: When using nested include() with mixed path() and
re_path(), regex anchors (^ and $) end up embedded in the middle of
accumulated URL patterns. normalize_path() only strips anchors from
start/end, so patterns like 'nutritionist/^client/mfp/$' don't match
href '/nutritionist/client/mfp/'.

Fix: Change normalize_path() to use str.replace() instead of checking
startswith()/endswith().

Also adds specs for:

  • Static JavaScript file scanning (--scan-static flag)
  • Detection aggressiveness levels (--url-detection flag) (5a168bb)

Feature

  • feat: add --url-detection flag for extended URL pattern detection

Adds support for detecting URLs in JavaScript template literals when
using the 'extended' detection mode.

New CLI option:
--url-detection [basic|extended]
- basic - default - Only detect static string URLs in quotes
- extended - Also detect URLs in template literals

Features:

  • Extracts static URL prefixes from template literals before interpolation
  • Works in both template files and static JavaScript files
  • Combines with existing basic detection

Tests added for template literal detection in various scenarios. (fc2bad6)

  • feat: add --scan-static flag for JavaScript file scanning

Adds support for scanning JavaScript files in static directories for
URL references. This helps detect URLs used in external .js files that
would otherwise be reported as unreferenced.

New CLI option:
--scan-static Scan JavaScript files in static directories

Features:

  • Discovers static directories from STATICFILES_DIRS and app static folders
  • Scans .js and .mjs files for URL references
  • Skips minified files (.min.js) and vendor directories
  • Filters by BASE_DIR to exclude third-party code
  • URLs found in static files are included in href matching

New TemplateAnalyzer methods:

  • find_all_static_files(): Discover and analyze JS files
  • analyze_static_file(): Analyze a single static file
  • normalize_static_path(): Get relative path for static files

Tests added for:

  • URL extraction from JavaScript content
  • jQuery AJAX patterns (the original use case)
  • Fetch API calls
  • Comment exclusion in JS files
  • Static path normalization (6b7154e)

Fix

  • fix: handle embedded regex anchors in URL patterns

When using nested include() with mixed path() and re_path(), regex
anchors (^ and $) end up embedded in the middle of accumulated URL
patterns. For example:

path('nutritionist/', include(...)) + re_path(r'^client/mfp/$', ...)

produces the pattern: 'nutritionist/^client/mfp/$'

The previous normalize_path() only stripped ^ from start and $ from end,
so patterns like this would never match their corresponding hrefs.

Fix: Change normalize_path() to use str.replace() to strip ALL
occurrences of ^ and $ from anywhere in the pattern.

This fixes false positives where URLs used in inline JavaScript were
incorrectly reported as unreferenced because the pattern matching failed.

Tests added:

  • test_normalize_embedded_caret_anchor
  • test_normalize_embedded_dollar_anchor
  • test_normalize_multiple_embedded_anchors
  • test_normalize_real_world_nested_include_pattern
  • TestEmbeddedAnchorMatching class with integration tests (86e0959)

Style

  • style: fix linting issues from pre-commit
  • Fix trailing whitespace in CHANGELOG.md
  • Use union syntax in isinstance call (UP038)
  • Fix line length issues in test docstrings
  • Apply ruff formatting (e716bf6)

Unknown

  • Merge pull request #21 from nanorepublica/claude/fix-unreferenced-url-012EZbq8XwJPj8Ao4wWW6VAf

feat: extended url detection (8d20104)

v0.7.0

03 Dec 20:25

Choose a tag to compare

v0.7.0 (2025-12-03)

Feature

v0.6.0

29 Nov 19:57

Choose a tag to compare

v0.6.0 (2025-11-29)

Chore

  • chore: fix trailing whitespace in CHANGELOG.md (a9461e6)

Documentation

  • docs: add task list for URL detection implementation

Break down implementation into 3 task groups with 15 sub-tasks:

  • Task Group 1: Comment stripping (4 tests + implementation)
  • Task Group 2: URL pattern enhancement (6 tests + implementation)
  • Task Group 3: Test coverage review and gap analysis (527fd4b)
  • docs: add spec for expanded URL detection in templates

Add specification to detect internal URLs anywhere in HTML templates,
not just in href attributes. Includes requirements to:

  • Match URLs in JS code, data attributes, event handlers
  • Exclude URLs inside HTML and JS comments
  • Support dynamic URLs with Django template variables (6747e6b)

Feature

  • feat: release (ec03b3a)

  • feat: Reduce false positives in URL detection (2500e5e)

  • feat: expand URL detection to find URLs anywhere in templates

Instead of only detecting URLs in href attributes, now detect internal
URL strings anywhere in HTML template files. This catches URLs in:

  • JavaScript code (fetch, const url = ...)
  • Data attributes (data-url="/api/...")
  • Inline event handlers (onclick="location.href='...'")
  • JSON configs embedded in templates

Also excludes URLs inside comments:

  • HTML comments (<!-- ... -->)
  • JS single-line comments (// ...)
  • JS multi-line comments (/* ... */)

Added 10 new tests covering the expanded detection and comment stripping.
All 211 existing tests continue to pass. (88f418e)

v0.5.1

28 Nov 21:47

Choose a tag to compare

v0.5.1 (2025-11-28)

Documentation

  • docs: add task list for URL reference detection fix

Break down implementation into 4 task groups with 16 sub-tasks:

  • Task Group 1: Path normalization enhancement (strip ^, $, handle /?)
  • Task Group 2: Dynamic URL pattern matching (helper functions)
  • Task Group 3: Integration and match function enhancement
  • Task Group 4: Final verification and edge cases

Follows TDD approach with ~28-30 new tests planned. (26df666)

  • docs: add spec for fixing URL reference detection false positives

Add specification for fixing false positives when detecting unreferenced
URLs. The issue occurs because regex anchors (^ and $) and optional
trailing slashes (/?) in URL patterns aren't being stripped during
normalization, causing pattern-to-href comparison to fail.

The spec covers:

  • Enhanced normalize_path() to strip regex syntax
  • Helper functions for detecting capture groups
  • Dynamic URL matching for patterns with template variables ({{)
  • Comprehensive test cases for edge cases (1767e5e)

Fix

  • fix: fix false positives on unreferenced urls

Fix false positives in URL reference detection (ae491df)

  • fix: handle regex anchors and dynamic URLs in pattern matching

Fix false positives when detecting unreferenced URLs by properly handling
regex syntax in Django URL patterns.

Changes to url_matching.py:

  • Enhanced normalize_path() to strip ^ and $ regex anchors
  • Added support for /? optional trailing slash patterns
  • Added has_capture_groups() to detect dynamic URL patterns
  • Added extract_static_prefix() to get static portion before capture groups
  • Added is_dynamic_href() to detect {{ template syntax in hrefs
  • Modified match_href_to_pattern() to match dynamic hrefs against patterns
    with capture groups by comparing static prefixes

This fixes the issue where patterns like ^my/url$ were not matching
hrefs like /my/url, and enables matching dynamic hrefs like
/user/{{ user.id }}/ against patterns like ^user/(?P<id>\d+)/$

Added 35 new tests covering:

  • Regex anchor stripping (^, $, both)
  • Optional trailing slash handling (/?)
  • Capture group detection and prefix extraction
  • Dynamic href matching
  • Edge cases (multiple groups, groups at start, character classes)

All 201 tests pass with 100% coverage on url_matching.py. (28ba411)

Style

  • style: apply pre-commit formatting fixes (875cac7)

v0.5.0

26 Nov 21:45

Choose a tag to compare

v0.5.0 (2025-11-26)

Feature

v0.4.0

26 Nov 21:33

Choose a tag to compare

v0.4.0 (2025-11-26)

Feature

Fix

Unknown

v0.3.0

26 Nov 20:46

Choose a tag to compare

v0.3.0 (2025-11-26)

Chore

  • chore: release fix (c98af15)

  • chore(release): 0.4.0 (565ef70)

  • chore: update ruff-pre-commit version to v0.8.4 (cf66b6d)

  • chore: fix trailing whitespace in CHANGELOG.md

Applied pre-commit hook to remove trailing whitespace. (e096722)

  • chore(release): 0.3.0 (d3f9631)

  • chore: remove trailing whitespace from CHANGELOG.md (af4f702)

  • chore: initialize spec for template detection fix

Initialize spec folder for fixing unused template detection feature
where templates are incorrectly flagged as unreferenced due to
relative path handling issues. (1124d74)

Documentation

  • docs: add final verification report for URL pattern enhancements (c13edbc)

  • docs: add tasks breakdown for URL pattern enhancements (2a6b53c)

  • docs: add spec for URL pattern enhancements (b8732c9)

  • docs: add tasks breakdown for template detection fix

Create comprehensive tasks list with 36 tasks across 4 phases:

  • Phase 1: Path normalization foundation (5 tasks, CRITICAL)
  • Phase 2: Enhanced detection - CBV defaults and template variables (11 tasks)
  • Phase 3: Command integration (5 tasks)
  • Phase 4: Testing and validation (15 tasks)

Strategic organization respects dependencies, includes test-driven
approach with 18-42 targeted tests, and targets 5-day implementation. (a4bc4f9)

  • docs: add comprehensive specification for template detection fix

Create detailed specification document covering:

  • Problem statement with concrete examples
  • Root cause analysis of path mismatch bug
  • Four prioritized requirements (path normalization, CBV defaults, template variables, relationships)
  • Technical approach with architecture diagrams
  • 5-day phased implementation plan
  • Comprehensive test strategy
  • Success criteria and risk assessment (3bb6a89)
  • docs: add requirements for template detection fix

Document comprehensive requirements for fixing unused template detection:

  • Core bug: path mismatch between full paths and relative names
  • Need path normalization using Django's template loaders
  • CBV default template detection (ListView, DetailView, etc.)
  • Template variable detection (variables with 'template' in name)
  • Enhanced relationship tracking for extends/include

Success criteria and test cases included. (b12f2bb)

Feature

  • feat: release (47fd562)

  • feat: fix unreferenced URL patterns for internal links (c369b60)

  • feat: implement URL pattern enhancements with href matching and third-party exclusion

Implement two major enhancements to django-deadcode's URL pattern detection:

  1. Raw URL Pattern Matching

    • Extract internal hrefs from templates (e.g., <a href="/https/github.com/about/">)
    • Match hrefs against URL patterns using simple string matching
    • Mark matched URL patterns as referenced to reduce false positives
    • Properly handle path normalization (leading/trailing slashes)
    • Filter external protocols (http://, https://, mailto:, tel:, etc.)
  2. Third-Party URL Exclusion

    • Auto-detect third-party namespaces by checking if view modules are outside BASE_DIR
    • Exclude entire namespaces if any pattern is third-party
    • Support manual exclusions via DEADCODE_EXCLUDE_NAMESPACES setting
    • Add informational note to reports listing excluded namespaces
    • Silently remove third-party URLs from unreferenced list

Implementation Details:

  • Created utils module with module_detection, url_matching, and config utilities
  • Enhanced URLAnalyzer to store module_path and is_third_party for each pattern
  • Updated get_unreferenced_urls() to return tuple: (unreferenced, excluded_namespaces)
  • Added get_all_internal_hrefs() method to TemplateAnalyzer
  • Updated management command to integrate href matching and namespace exclusion
  • Enhanced all reporters (Console, JSON, Markdown) to show exclusion notes
  • Maintained full backwards compatibility with existing functionality

Tests:

  • Added 74 new tests across 5 new test files
  • All 172 tests pass including existing tests
  • Tests cover: third-party detection, href extraction, pattern matching,
    configuration handling, and end-to-end integration

Configuration:
Users can now configure:
DEADCODE_EXCLUDE_NAMESPACES = ['admin', 'debug_toolbar']

This addresses the common issue of third-party URLs (like Django admin)
appearing as unreferenced, and improves detection by matching raw hrefs
in templates. (ab0c5c8)

  • feat: path normalization for templates and cbv detection

Path Normalization for templates and CBV detection (84bd028)

  • feat: fix unused template detection with path normalization and enhanced detection

Implement comprehensive fix for template detection false positives across 6 task groups:

PHASE 1: Path Normalization (CRITICAL)

  • Add normalize_template_path() to convert filesystem paths to Django-relative format
  • Update TemplateAnalyzer to store templates with normalized paths
  • Ensure template relationships (extends/includes) use normalized paths
  • 8 focused tests added, all passing

PHASE 2: Enhanced Detection

  • Task Group 2: CBV Default Template Detection

    • Detect ListView, DetailView, CreateView, UpdateView, DeleteView implicit templates
    • Extract models from 'model' attribute and 'queryset' patterns
    • Infer app labels from file paths
    • Generate implicit template names following Django conventions
    • 8 focused tests added, all passing
  • Task Group 3: Template Variable Detection

    • Detect variables containing 'template' in name (case-insensitive)
    • Parse get_template_names() method returns
    • Extract string constants from assignments and returns
    • 7 focused tests added, all passing

PHASE 3: Integration

  • Task Group 4: Command Integration & Path Consistency
    • Verify _compile_analysis_data() uses normalized paths
    • Confirm transitive closure works with normalized paths
    • Validate set comparison logic eliminates false positives
    • 7 integration tests added, all passing

PHASE 4: Validation

  • Task Group 5: Test Review & Gap Analysis

    • Review 51 existing tests from Task Groups 1-4
    • Add 10 strategic tests for edge cases and error handling
    • Achieve 93% code coverage (exceeds 90% target)
  • Task Group 6: Manual Validation & Documentation

    • Create collations app validation tests (4 tests)
    • Add performance benchmarks (6 tests, <1% impact vs 10% target)
    • Update README with features, troubleshooting, changelog
    • Code cleanup and linting fixes

RESULTS:

  • 102/102 tests passing (92 original + 10 new)
  • 93% code coverage (target: >90%)
  • <1% performance impact (target: <10%)
  • Zero false positives for collations app example
  • Production-ready for v0.3.0 release

Fixes: Template detection false positives
Resolves: collations/base.html, collection_list.html, collection_detail.html incorrectly flagged (76ddd8b)

Refactor

  • refactor: remove URL REFERENCES BY TEMPLATE and TEMPLATE USAGE BY VIEWS sections

Remove these reporting sections from ConsoleReporter as they are no longer needed:

  • URL REFERENCES BY TEMPLATE
  • TEMPLATE USAGE BY VIEWS

This streamlines the console output to focus on the most important information. (c8fb0a9)

Style

  • style: apply ruff-format v0.8.4 to test files (f041320)

  • style: apply ruff-format to all files (27a670d)

  • style: fix ruff linting errors (line length and imports) (743fd0d)

  • style: apply ruff-format to test files

Apply ruff formatting improvements:

  • Consolidate function arguments on single line when they fit
  • Reformat assertion statements for better readability
  • Standardize string concatenation formatting (05b822c)
  • style: fix ruff lint issues (line length viola...
Read more

v0.2.1

13 Nov 22:42

Choose a tag to compare

v0.2.1 (2025-11-13)

Chore

  • chore: set version to 0.3.0 for PyPI release

Update package version to 0.2.3 (9cef729)

  • chore: set version to 0.3.0 for PyPI release

Update version to 0.3.0 in both pyproject.toml and init.py to
prepare for publishing to PyPI. (4bc9f91)

Ci

  • ci: trigger CI workflow

Trigger CI workflow to verify and publish version 0.3.0 to PyPI. (69b14c4)

Fix

  • fix: update README for production readiness

Claude/update pypi version 01 kxyyzljhtm6 bp8r sx vypd s (07a56a0)

  • fix: update README for production readiness

Remove experimental warning as the package has been thoroughly tested
with 62 passing tests and 93% code coverage. (89cac28)

Unknown

  • Merge pull request #13 from nanorepublica/claude/agent-os-development-011CV4fE968vXyiH6k8T9hCU

chore(release): 0.3.1 (cab09da)

  • Merge branch 'main' into claude/agent-os-development-011CV4fE968vXyiH6k8T9hCU (7669602)

v0.2.0

13 Nov 11:28

Choose a tag to compare

v0.2.0 (2025-11-13)

Feature

  • feat: improved template reporting (c7b9c87)

  • feat: implement template reporting improvements with BASE_DIR filtering and transitive detection

Implemented comprehensive template analysis improvements to reduce false
positives and false negatives in dead code detection.

Phase 1: BASE_DIR Filtering

  • Added BASE_DIR retrieval from Django settings with error handling
  • Updated TemplateAnalyzer to filter templates by BASE_DIR
  • Implemented Python 3.8+ compatible path comparison helper
  • Proper symlink handling (resolved for comparison, original path stored)

Phase 2: Include/Extends Detection

  • Implemented transitive closure algorithm for template relationship detection
  • Templates referenced via {% include %} or {% extends %} now marked as used
  • BFS-style algorithm with circular reference prevention
  • Updated dead code detection to use transitive + direct references

Phase 3: Optional Relationship Reporting

  • Added --show-template-relationships CLI flag (default: False)
  • Updated all reporters (Console, JSON, Markdown) to respect flag
  • Conditionally show/hide template relationship information
  • Backward compatible with existing output format

Phase 4: Testing & Documentation

  • Added 29 new tests (12 unit, 11 integration, 6 reporter)
  • All 62 tests passing with 93% code coverage
  • Comprehensive edge case testing (circular refs, deep chains, symlinks)
  • Updated README.md with usage examples and feature documentation
  • Updated CHANGELOG.md with comprehensive entry

Files Changed

Core Implementation:

  • django_deadcode/analyzers/template_analyzer.py
  • django_deadcode/management/commands/finddeadcode.py
  • django_deadcode/reporters/base.py

Tests:

  • tests/test_template_analyzer.py
  • tests/test_command_integration.py (new)
  • tests/test_reporters.py
  • tests/settings.py

Documentation:

  • README.md
  • CHANGELOG.md
  • agent-os/specs/2025-11-12-template-reporting-improvements/tasks.md
  • agent-os/specs/2025-11-12-template-reporting-improvements/verifications/

Test Results

  • 62/62 tests passing (100%)
  • 93% code coverage
  • No regressions detected
  • All acceptance criteria met

Backward Compatibility

No breaking changes. All existing functionality preserved.

  • New CLI flag is optional with sensible defaults
  • Output format unchanged (just fewer false positives)
  • All existing tests continue to pass (62f2bc1)
  • feat: add detailed spec and tasks for template reporting improvements

Created comprehensive specification and task breakdown for improving
template dead code detection:

  • BASE_DIR filtering to exclude external templates
  • Include/extends detection for transitive template references
  • Optional relationship reporting with CLI flag
  • Symlink handling improvements

Spec includes:

  • Current vs proposed behavior analysis
  • Implementation details with code examples
  • Testing requirements and edge cases
  • Backwards compatibility considerations

Tasks organized into 4 phases:

  1. BASE_DIR filtering implementation
  2. Include/extends transitive detection
  3. Optional relationship reporting
  4. Testing and documentation

Based on codebase exploration of django_deadcode analyzers and
user clarifications on requirements. (2bbc2dc)

  • feat: initialize spec for template reporting improvements

Initialize spec folder for improving template reporting in django-deadcode:

  • Exclude templates outside project BASE_DIR
  • Detect template references via include/extends statements
  • Make template relationship reporting optional (c7aca72)

Fix

  • fix: resolve ruff linting errors

Fixed all ruff linting issues:

  • Replaced deprecated typing.Dict/List/Set with dict/list/set
  • Converted Optional[X] to X | None syntax
  • Removed unused imports
  • Fixed line length violations (max 88 chars)

Changes:

  • django_deadcode/analyzers/template_analyzer.py: Updated type hints
  • django_deadcode/management/commands/finddeadcode.py: Updated type hints
  • django_deadcode/reporters/base.py: Fixed long docstring line
  • tests/test_template_analyzer.py: Fixed long comment line

All 62 tests still passing with 93% coverage. (3562f3c)