Guest User

Untitled

a guest
Mar 28th, 2026
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. # Prompt: Improve Complexity in src
  2.  
  3. You are working in the uniffi-bindgen-node-js Rust codebase. Improve overall code complexity across the src directory, using Lizard as a guide rather than treating current
  4. warnings as the only target.
  5.  
  6. ## Goal
  7.  
  8. Improve the maintainability of the Rust code in src by reducing complexity in a way that makes the code easier to read, reason about, and extend.
  9.  
  10. This includes:
  11.  
  12. - Reducing cyclomatic complexity where it is genuinely too high
  13. - Breaking up long, multi-purpose functions
  14. - Removing repeated branching and duplicated control flow
  15. - Extracting cohesive helper functions when that clarifies behavior
  16. - Simplifying orchestration code so top-level functions read more clearly
  17.  
  18. Do not optimize only for clearing Lizard warnings. Improve the broader complexity profile of the codebase.
  19.  
  20. ## Metrics And Tooling
  21.  
  22. Use Lizard to establish a baseline and measure improvement:
  23.  
  24. uvx --from 'lizard==1.21.2' lizard -l rust src
  25.  
  26. Notes:
  27.  
  28. - Lizard may exit with status 1 when warnings exist; treat the output as valid.
  29. - Use Lizard to identify high-impact functions, but also inspect nearby medium-complexity functions in touched areas.
  30. - Re-run Lizard after refactors and compare before/after results.
  31.  
  32. ## Current High-Complexity Areas To Inspect First
  33.  
  34. Start with these files and functions, but do not limit the work to them:
  35.  
  36. - src/bindings/api/mod.rs
  37. - render_public_api
  38. - validate_renderable_types
  39. - src/bindings/api/render.rs
  40. - AsyncCallbackVtableRegistrationJsView::from_method
  41. - src/bindings/mod.rs
  42. - write_runtime_files
  43. - Also inspect:
  44. - src/bindings/api/support.rs
  45. - surrounding helpers in touched modules that still have avoidable complexity
  46.  
  47. ## Refactoring Principles
  48.  
  49. Prefer refactors that actually improve the code, not metric gaming.
  50.  
  51. Good changes:
  52.  
  53. - Split orchestration from detail-heavy logic
  54. - Extract repeated validation/rendering/conversion patterns into focused helpers
  55. - Replace repeated imperative sequences with small data-driven loops when clearer
  56. - Use early returns or helper boundaries to flatten branching
  57. - Keep related logic together and preserve local readability
  58.  
  59. Avoid:
  60.  
  61. - Moving complexity into shallow wrappers
  62. - Introducing abstractions that make control flow harder to follow
  63. - Changing behavior, generated output, or public interfaces
  64. - Refactoring unrelated areas without a clear complexity payoff
  65.  
  66. ## Working Style
  67.  
  68. Approach the work incrementally:
  69.  
  70. 1. Run the baseline Lizard scan on src.
  71. 2. Rank the biggest complexity offenders.
  72. 3. Inspect the worst functions and nearby code in the same modules.
  73. 4. Refactor only where the result is clearly simpler.
  74. 5. Re-run Lizard and compare before/after metrics.
  75. 6. Run tests last.
  76.  
  77. If you make code changes, run tests as the final step:
  78.  
  79. cargo test
  80.  
  81. ## Expected Output
  82.  
  83. At the end, report:
  84.  
  85. - Which files and functions were simplified
  86. - Before/after Lizard results
  87. - Which complexity reductions were most meaningful
  88. - Any remaining hotspots worth a future pass
  89. - Confirmation that tests were run last and whether they passed
  90.  
  91. ## Acceptance Criteria
  92.  
  93. The work is successful if:
  94.  
  95. - The src directory has a meaningfully better complexity profile
  96. - Current hotspots are reduced where it makes sense
  97. - Some medium-complexity code in touched areas is also improved
  98. - Readability improves rather than degrades
  99. - Behavior and outputs remain unchanged
  100. - cargo test passes
  101.  
  102. ## Instructions
  103.  
  104. - never ever change any PROMPT.md
  105. - commit when you are finished with a meaningful chunk of work
  106. - use conventional commit syntax for commit messages
  107.  
Advertisement
Add Comment
Please, Sign In to add comment