Skip to content

Refactor on storage helper - #116

Open
daniaGit123 wants to merge 2 commits into
CMU-17313Q:mainfrom
daniaGit123:refactor-onStorage-helper
Open

daniaGit123 wants to merge 2 commits into
CMU-17313Q:mainfrom
daniaGit123:refactor-onStorage-helper

Conversation

@daniaGit123

Copy link
Copy Markdown

P1B: Starter Task: Refactoring PR

Use this pull request template to briefly answer the questions below in one to two sentences each.
Feel free to delete this text at the top after filling out the template.

1. Issue

Link to the associated GitHub issue: #43

Full path to the refactored file: packages/ui/src/theme/context.tsx

What do you think this file does?
(Your answer does not have to be 100% correct; give a reasonable, evidence‑based guess.)

What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.) It manages theme state and storage events for the UI, handling how themes and color schemes are loaded and applied. I refactored the load function and the onStorage handler to reduce complexity by extracting logic into a helper function.

Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.) Function with high complexity (count = 18) in load.

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability? Nested branches made the function harder to read, test, and extend.

What changes did you make to resolve the issue? I extracted the theme‑handling logic into a helper function.

How do your changes improve maintainability? Did you consider alternatives? The refactor reduces cognitive complexity, makes the function easier to follow, and isolates responsibilities. I considered leaving all logic inline, but splitting into one helper was cleaner and still achieved the same purpose.

3. Validation

How did you validate that the change is correct? I ran the test suite locally, confirmed all tests passed, and verified Qlty reported fewer smells after the refactor.

Attach a screenshot of the test coverage showing the lines were executed by the tests.

Attach a screenshot showing the tests that cover the change passing during CI

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.ts> showing fewer reported issues after the changes.

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