Skip to content

fix: resolve all sonarjs/no-duplicate-string lint warnings - #26

Merged
leejsinclair merged 1 commit into
mainfrom
copilot/reduce-complexity-code-smells
May 16, 2026
Merged

fix: resolve all sonarjs/no-duplicate-string lint warnings#26
leejsinclair merged 1 commit into
mainfrom
copilot/reduce-complexity-code-smells

Conversation

Copilot AI commented May 16, 2026

Copy link
Copy Markdown
Contributor

Eliminates all 11 sonarjs/no-duplicate-string warnings surfaced by npm run lint by extracting repeated string literals into named constants and consolidating duplicate API key guard logic.

📝 Summary

11 sonarjs/no-duplicate-string warnings across 6 files — each caused by string literals repeated 3–8 times. Fixed by extracting constants and removing redundant inline guards in favour of the existing ensureApiKey() helper.

🔧 Changes

  • criteriaScoring.jsBULLET_PREFIX_THE_SYSTEM / BULLET_PREFIX_SYSTEM_MUST constants replace 3× inline literals each
  • llmService.jsimproveStoryWithAI and improveCriteriaWithAI now delegate to the existing ensureApiKey() helper instead of duplicating the guard; NOT_PROVIDED constant replaces 3× inline '(not provided)' in buildCriteriaPrompt
  • CriteriaScoreBreakdown.jsx — module-level COLOR_GREEN constant replaces 3× 'text-green-600'
  • criteriaScoring.test.jsBULLET_CRITERIA constant replaces 3 identical inline arrays
  • llmService.test.jsTEST_API_KEY (8 uses) and SAMPLE_CRITERION (4 uses) constants extracted
  • scoreSoThatStatement.test.jsGRADE_NEEDS_WORK constant replaces 3× 'Needs work'

Notable: the llmService.js fix also removes dead duplicate validation code — ensureApiKey() already existed at module scope and is a function declaration (hoisted), so replacing the inline guards is a pure deduplification with no behaviour change.

🎯 Motivation

npm run lint reported 11 warnings. Reducing string duplication improves maintainability: rename/update in one place rather than hunting literals.

🧪 Testing

  • npm run lint — 0 warnings (was 11)
  • npm test -- --run — 222/222 tests pass

📸 Screenshots (optional)

N/A

✅ Checklist

  • Code compiles and runs
  • Tests added or updated (if applicable)
  • Documentation updated (if needed)
  • No linting or formatting issues
  • PR title is clear and descriptive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the codebase to eliminate 11 sonarjs/no-duplicate-string lint warnings by extracting repeated string literals into named constants and removing duplicated API key guard code in favor of an existing ensureApiKey() helper.

Changes:

  • Extract repeated literals (bullet prefixes, color classes, test fixtures, grade labels) into named constants across 6 files.
  • Replace duplicated inline API key validation with ensureApiKey() helper in improveStoryWithAI / improveCriteriaWithAI.
  • No behavior change; refactor-only.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/criteriaScoring.js Extracts BULLET_PREFIX_THE_SYSTEM / BULLET_PREFIX_SYSTEM_MUST constants.
src/llmService.js Delegates to ensureApiKey(); adds NOT_PROVIDED constant.
src/components/CriteriaScoreBreakdown.jsx Adds COLOR_GREEN constant for repeated Tailwind class.
src/test/criteriaScoring.test.js Adds shared BULLET_CRITERIA fixture.
src/test/llmService.test.js Adds TEST_API_KEY and SAMPLE_CRITERION constants.
src/test/scoreSoThatStatement.test.js Adds GRADE_NEEDS_WORK constant.

@leejsinclair
leejsinclair merged commit 8c828aa into main May 16, 2026
5 checks passed
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.

3 participants