refactor(SaveInterface): extract duplicated strings to constants#5190
Conversation
|
✅ All Jest tests passed! This PR is ready to merge. |
|
I wonder if it would make more sense to put the translated strings into the constants so we don't have to repeatedly translate them? |
|
✅ All Jest tests passed! This PR is ready to merge. |
Thanks, got to know something new today and you were right, I've reflected upon your suggestion. |
|
I am not crazy about obscuring these strings: It makes the code less clear, IMHO. But I am fine with the strings exposed to the interface. |
2f0b0db to
0e6d39f
Compare
|
✅ All Jest tests passed! This PR is ready to merge. |
0e6d39f to
b1d210b
Compare
|
✅ All Jest tests passed! This PR is ready to merge. |
|
@walterbender I've updated the PR. I've extracted the user-facing strings into constants (STR_MY_PROJECT, STR_SHOW, STR_HIDE) but kept internal identifiers like "showhide" inline for clarity as you suggested. |
|
@WillyEverGreen Since these constants call _() at file load time, are we certain translations are fully initialized before this script executes? I just want to confirm this won’t cause issues if language initialization happens later or if language switching is supported at runtime. |
|
Should be OK |
Overview
This PR addresses multiple Code Quality issues identified by SonarJS and ESLint regarding duplicated string literals in
js/SaveInterface.js.Changes Made
STR_MY_PROJECTfor"My Project"STR_SHOWfor"Show"STR_HIDEfor"Hide"STR_SHOWHIDEfor the"showhide"element idhtmlSaveTemplateto use these constants.sonarjs/no-duplicate-string.Benefits
Verification
npm run lintand confirmedsonarjs/no-duplicate-stringwarnings are resolved forjs/SaveInterface.js.npx prettierto ensure consistent formatting.