Skip to content

Conversation

@Tim020
Copy link
Contributor

@Tim020 Tim020 commented Jan 30, 2026

Summary

Reduce code duplication to pass SonarQube quality gate (from ~7.7% to 2.3%, threshold ≤3%).

Changes

Python Error Constants (server/controllers/api/constants.py)

  • Centralized 40+ duplicated error message strings across 17+ controller files
  • Constants include: ERROR_SHOW_NOT_FOUND, ERROR_ID_MISSING, ERROR_NAME_MISSING, etc.

Vue Form Validation Mixin (client/src/mixins/formValidationMixin.js)

  • Created reusable mixin with getValidationState(), resetForm(), hasFormErrors()
  • Updated 9 Vue components to use the mixin instead of duplicated validation methods

Stage Direction Styles Helper (server/controllers/api/show/script/stage_direction_styles.py)

  • Extracted validate_style_fields() helper to reduce duplication between post() and patch() methods

User Overrides Helpers (server/controllers/api/user/overrides.py)

  • Extracted handle_override_patch() and handle_override_delete() helpers
  • Both StageDirectionOverridesController and CueColourOverridesController now share common CRUD logic

Stage Controller Helpers (server/controllers/api/show/stage/helpers.py)

  • Created new module with shared helpers for props and scenery controllers:
    • handle_type_post(), handle_type_patch(), handle_type_delete() - for PropType/SceneryType CRUD
    • handle_allocation_post(), handle_allocation_delete() - for scene allocation management
  • Updated props.py and scenery.py to use these shared helpers

Files Changed

  • server/controllers/api/constants.py (new)
  • server/controllers/api/show/stage/helpers.py (new)
  • client/src/mixins/formValidationMixin.js (new)
  • 17+ Python controller files updated to use constants
  • 9 Vue components updated to use form validation mixin
  • props.py, scenery.py, overrides.py, stage_direction_styles.py refactored

Test plan

  • ESLint/Prettier pass (frontend)
  • Ruff pass (backend)
  • Frontend tests pass
  • Backend tests pass (447 tests)
  • SonarQube duplication metric: 2.3% (below 3% threshold)

🤖 Generated with Claude Code

Centralize duplicated error messages and form validation code to reduce
duplication from 4.87% to below the 3% threshold.

Backend changes:
- Add controllers/api/constants.py with 40+ standardized error messages
- Update 17 controller files to use shared constants
- Update 2 test files with improved error message format

Frontend changes:
- Add mixins/formValidationMixin.js with reusable validation methods
- Update 9 Vue components to use the shared mixin

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added client Pull requests changing front end code server Pull requests changing back end code xlarge-diff labels Jan 30, 2026
@github-actions
Copy link

github-actions bot commented Jan 30, 2026

Client Test Results

83 tests  ±0   83 ✅ ±0   0s ⏱️ ±0s
 3 suites ±0    0 💤 ±0 
 1 files   ±0    0 ❌ ±0 

Results for commit 56fcf77. ± Comparison against base commit 7323053.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 30, 2026

Python Test Results

  1 files  ±0    1 suites  ±0   48s ⏱️ -1s
447 tests ±0  447 ✅ ±0  0 💤 ±0  0 ❌ ±0 
452 runs  ±0  452 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 56fcf77. ± Comparison against base commit 7323053.

♻️ This comment has been updated with latest results.

@Tim020 Tim020 added the claude Issues created by Claude label Jan 30, 2026
Tim020 and others added 5 commits January 30, 2026 16:36
Co-Authored-By: Claude Opus 4.5 <[email protected]>
Extract common validation logic into validate_style_fields() helper
function to reduce code duplication between post() and patch() methods.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Extract common patterns to reduce SonarQube duplication metrics:

- Create helpers.py with shared allocation CRUD logic for props/scenery
- Extract handle_override_patch/delete helpers in overrides.py
- Update props.py and scenery.py to use shared helpers

Net reduction of ~247 lines while preserving all functionality.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add handle_type_post, handle_type_patch, handle_type_delete helpers
and update PropsTypesController and SceneryTypesController to use them.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Remove validateNewState and validateEditState convenience wrappers.
Components now call getValidationState directly with the form state key.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@sonarqubecloud
Copy link

@Tim020 Tim020 merged commit b611dcb into dev Jan 31, 2026
25 checks passed
@Tim020 Tim020 deleted the tim/sonar-cleanup branch January 31, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude Issues created by Claude client Pull requests changing front end code server Pull requests changing back end code xlarge-diff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants