Skip to content

Refactor init in public/src/admin/appearance/themes.js#11

Closed
mhk2-cmu wants to merge 2 commits into
mainfrom
p1b-refactor-themes-init-n624
Closed

Refactor init in public/src/admin/appearance/themes.js#11
mhk2-cmu wants to merge 2 commits into
mainfrom
p1b-refactor-themes-init-n624

Conversation

@mhk2-cmu

Copy link
Copy Markdown

Refactor init in public/src/admin/appearance/themes.js

Summary

This PR refactors the init function in public/src/admin/appearance/themes.js to address a high complexity code smell detected by Qlty. The original init function contained deeply nested logic for theme selection and multiple inline operations.

The refactor improves readability and maintainability by:

  • Adding a guard clause to reduce nesting (if (action !== 'use') return;).
  • Extracting a helper function getThemeInfoFrom to encapsulate DOM attribute lookups.
  • Extracting applyTheme to handle socket emission and UI updates.
  • Simplifying the main init body, which makes the control flow easier to follow.

Evidence of Improvement

Before

Qlty reported:

public/src/admin/appearance/themes.js: Function init has high complexity (count = 13).

After

After the refactor, complexity smell was removed. Qlty now reports:

public/src/admin/appearance/themes.js: Function with many returns (count = 6): init

This remaining warning is due to inline callbacks inside init (returns in nested functions). However, the structure is significantly cleaner and more maintainable.

Manual Validation

  • Rebuilt and restarted NodeBB.
  • Verified theme selection works as expected.
  • Confirmed debug log in browser console:

DEBUG: N624-debu — Themes.init triggered

Issue Link

Resolves CMU-17313Q#46

@salemadi06 salemadi06 self-assigned this Oct 9, 2025
@salemadi06 salemadi06 closed this Oct 9, 2025
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.

2 participants