Skip to content

refactor: reduce code duplication from 11.5% to ~6-7%#38

Merged
aksOps merged 1 commit into
mainfrom
fix/reduce-duplication
Apr 4, 2026
Merged

refactor: reduce code duplication from 11.5% to ~6-7%#38
aksOps merged 1 commit into
mainfrom
fix/reduce-duplication

Conversation

@aksOps

@aksOps aksOps commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Eliminates ~530 lines of duplicated code across 22 files by extracting shared helper methods. The main pattern was detectWithAst() and detectWithRegex() duplicating identical node-creation code within each detector.

Changes

Python detectors (10 files, ~500 lines removed)

  • Auth/route detectors: Extracted private helpers for node creation in FastAPIAuth (5 helpers), DjangoAuth (4), FastAPIRoute (1), DjangoView (2), Flask (2), Celery (4)
  • Entity detectors: Extracted helpers in DjangoModel (7), SQLAlchemy (4), Pydantic (5), PythonStructures (8 + AllExports record)

Frontend detectors (3 files)

  • Created FrontendDetectorHelper with createComponentNode() and lineAt() — shared by Angular, React, Vue detectors

Java messaging detectors (4 files)

  • Created AbstractJavaMessagingDetector with CLASS_RE, extractClassName(), addMessagingEdge() — shared by JMS, IBM MQ, Tibco EMS, RabbitMQ

Scala/Kotlin structures (2 files)

  • Created StructuresDetectorHelper with addImportEdge(), createStructureNode(), edge helpers

Test plan

  • All 3219 tests pass (0 failures, 0 errors)
  • No behavioral changes — only structural deduplication
  • SonarCloud scan to confirm duplication reduction

🤖 Generated with Claude Code

…ctWithRegex duplication

Python auth/route detectors:
- FastAPIAuthDetector: 5 helpers (createDependsGuard, createSecurityGuard, etc.)
- DjangoAuthDetector: 4 helpers (createLoginRequiredGuard, etc.)
- FastAPIRouteDetector: createRouteEndpoint helper
- DjangoViewDetector: createUrlPatternEndpoint, createCbvNode helpers
- FlaskRouteDetector: createFlaskRouteEndpoint, createExposesEdge helpers
- CeleryTaskDetector: createQueueNode, createMethodNode, edge helpers

Python entity detectors:
- DjangoModelDetector: 7 helpers (createModelNode, extractMeta, addFkEdges, etc.)
- SQLAlchemyModelDetector: 4 helpers (createEntityNode, extractColumns, etc.)
- PydanticModelDetector: 5 helpers (createPydanticNode, extractConfigProps, etc.)
- PythonStructuresDetector: 8 helpers + AllExports record

Frontend detectors:
- FrontendDetectorHelper: createComponentNode, lineAt shared helpers
- Refactored Angular, React, Vue component detectors

Java messaging detectors:
- AbstractJavaMessagingDetector: CLASS_RE, extractClassName, addMessagingEdge
- Refactored JMS, IBM MQ, Tibco EMS, RabbitMQ detectors

Scala/Kotlin structures:
- StructuresDetectorHelper: addImportEdge, createStructureNode, edge helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aksOps aksOps merged commit a8f264a into main Apr 4, 2026
6 checks passed
@sonarqubecloud

sonarqubecloud Bot commented Apr 4, 2026

Copy link
Copy Markdown

@aksOps aksOps deleted the fix/reduce-duplication branch April 26, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant