You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Behavior-preserving refactors to reduce cognitive complexity below the 15 threshold for the 4 flagged functions, verified by the existing test suite (no behavior change).
Findings (from SonarCloud API)
File:line
Function
Complexity
src/calendar-to-sheets/src/index.js:109
syncCalendarToSheet
25
src/gmail-to-drive-by-labels/src/index.js:125
processMessageToDoc attachment loop
33
src/gmail-to-drive-by-labels/src/index.js:690
rebuildDoc
17
deploy/index.html:1846
handleDeploy
19
Implementation Checklist
src/calendar-to-sheets/src/index.js: extract upsertRows, insertNewRows, computeRowsToDelete helpers out of syncCalendarToSheet
src/gmail-to-drive-by-labels/src/index.js: extract attachment dedup/rename helpers out of the processMessageToDoc attachment loop
src/gmail-to-drive-by-labels/src/index.js: extract state-machine phase helpers out of rebuildDoc
deploy/index.html: extract resolveDeployProjectId + buildDeployErrorHtml helpers out of handleDeploy
Tests to Write
Behavior-preserving refactor: no new behavior, so no new tests required (Phase 2 exception). The existing 301 Jest tests + Playwright deploy/tests/ui.spec.js validate behavior preservation. Any newly extracted helper stays covered via its existing callers to maintain the 99% line / 85% branch coverage thresholds.
Test Command
npm test (Jest, includes coverage thresholds via npm test -- --coverage)
Behavior-preserving refactors that reduce cognitive complexity (S3776) below the 15 threshold for all 4 flagged functions. No behavior change — validated by the existing test suite (Phase 2 TDD exception applies to a pure refactor).
src/calendar-to-sheets/src/index.js: split syncCalendarToSheet into upsert/insert/delete helpers
src/gmail-to-drive-by-labels/src/index.js: split the attachment loop and rebuildDoc state machine into helpers
deploy/index.html: split handleDeploy into project-resolution and error-html helpers
Notes
Pure refactor: no NOSONAR suppressions used. All original console.log/console.error calls and produced values/HTML are preserved verbatim, so runtime behavior is unchanged.
deploy/index.html is not part of Jest coverage (covered by the Playwright deploy/tests/ui.spec.js e2e); its inline JS was validated via prettier parse + syntax review. Extracted functions live in the same <script> scope and are hoisted.
The similar attachment loop in processLabelGroup was not flagged by SonarCloud and was left untouched to avoid scope creep.
Refactor the 4 functions flagged by SonarCloud rule javascript:S3776 to reduce cognitive complexity below the 15 threshold, with no behavior change.
Findings located (verified locally with eslint-plugin-sonarjs)
File
Function
Complexity
src/gmail-to-drive-by-labels/src/index.js
attachment forEach loop in processMessageToDoc
33
src/gmail-to-drive-by-labels/src/index.js
rebuildDoc
17
src/calendar-to-sheets/src/index.js
syncCalendarToSheet
25
deploy/index.html
handleDeploy
19
Implementation Checklist
src/calendar-to-sheets/src/index.js — extract upsert loop (applyUpserts) and delete loop (collectRowsToDelete) out of syncCalendarToSheet
src/gmail-to-drive-by-labels/src/index.js — extract attachment dedup/save into a helper (processAttachment + findDuplicateFile) used by processMessageToDoc
src/gmail-to-drive-by-labels/src/index.js — extract phase bodies of rebuildDoc (clearDocumentPhase, moveEmailsPhase)
deploy/index.html — extract per-script deploy body (deployOneScript) and error-html builder (buildDeployErrorHtml) out of handleDeploy
Tests to Write
These are behavior-preserving refactors. The affected JS is already covered by the Jest suite (301 tests) and deploy/index.html by the Playwright e2e suite; both act as the regression net. No new behavior is introduced, so per the Phase 2 exception no new failing tests are added. Coverage thresholds (99% lines) will be kept green since extracted helpers sit on already-exercised paths.
Test Command
npm test (Jest + coverage); npm run test:e2e (Playwright, for deploy/index.html); complexity re-verified with eslint-plugin-sonarjs.
Refactored the 4 functions flagged by SonarCloud javascript:S3776 (cognitive complexity) so each drops below the 15 threshold, with no behavior change.
Plan Execution
src/calendar-to-sheets/src/index.js — extracted applyUpdatesAndCollectInserts (upsert loop) and collectRowsToDelete (delete loop) out of syncCalendarToSheet (25 → 0 findings)
src/gmail-to-drive-by-labels/src/index.js — extracted isDuplicateAttachment, resolveAttachmentName, processAttachment out of the processMessageToDoc attachment loop (33 → 0 findings)
src/gmail-to-drive-by-labels/src/index.js — extracted clearDocumentPhase and moveEmailsPhase out of rebuildDoc (17 → 0 findings)
deploy/index.html — extracted deployOneScript (per-script deploy body) and buildDeployErrorHtml (error status builder) out of handleDeploy (19 → 0 findings)
Verification
Cognitive complexity (re-measured with eslint-plugin-sonarjs, S3776, threshold 15): all four files now report 0 findings.
Jest: 12 suites, 301 tests passed (unchanged from baseline).
Coverage thresholds met: lines 99.37% (≥99), statements 98.92% (≥95), functions 98.13% (≥95), branches 90.19% (≥85). calendar-to-sheets/src/index.js is 100% across the board.
Lint:npm run check → 0 errors (only pre-existing unused-var warnings in test files). .dev-lead/scripts/dev-lead-lint.sh → all checks passed.
npx prettier --write applied.
Test Results
Test Suites: 12 passed, 12 total
Tests: 301 passed, 301 total
Snapshots: 0 total
deploy/tests/ui.spec.js: 65 passed (22.0s)
Cognitive complexity (eslint-plugin-sonarjs, threshold 15):
src/gmail-to-drive-by-labels/src/index.js: OK (0 findings)
src/calendar-to-sheets/src/index.js: OK (0 findings)
deploy/index.html: OK (0 findings)
Files Changed
src/calendar-to-sheets/src/index.js: extracted upsert/delete loops from syncCalendarToSheet into helpers.
src/gmail-to-drive-by-labels/src/index.js: extracted attachment dedup/save helpers from processMessageToDoc; extracted rebuildDoc phase bodies into helpers.
deploy/index.html: extracted per-script deploy and error-HTML builder from handleDeploy.
Notes
Pure behavior-preserving refactors: no observable behavior changes. All existing Jest and Playwright tests act as the regression net and remain green — so per the Phase 2 exception, no new tests were added. Log messages and control flow were preserved exactly.
Removed the now-unused Session binding from processMessageToDoc (it moved into resolveAttachmentName) to keep lint clean.
Complexity was located and verified locally with eslint-plugin-sonarjs (same S3776 rule as SonarCloud); the 4 findings map 1:1 to the issue's file counts.
Activity
don-petry commentedon Jul 7, 2026
Dev-Lead Implementation Plan
Issue: #427 — SonarCloud: cognitive complexity (S3776)
Scope
Behavior-preserving refactors to reduce cognitive complexity below the 15 threshold for the 4 flagged functions, verified by the existing test suite (no behavior change).
Findings (from SonarCloud API)
src/calendar-to-sheets/src/index.js:109syncCalendarToSheetsrc/gmail-to-drive-by-labels/src/index.js:125processMessageToDocattachment loopsrc/gmail-to-drive-by-labels/src/index.js:690rebuildDocdeploy/index.html:1846handleDeployImplementation Checklist
src/calendar-to-sheets/src/index.js: extractupsertRows,insertNewRows,computeRowsToDeletehelpers out ofsyncCalendarToSheetsrc/gmail-to-drive-by-labels/src/index.js: extract attachment dedup/rename helpers out of theprocessMessageToDocattachment loopsrc/gmail-to-drive-by-labels/src/index.js: extract state-machine phase helpers out ofrebuildDocdeploy/index.html: extractresolveDeployProjectId+buildDeployErrorHtmlhelpers out ofhandleDeployTests to Write
deploy/tests/ui.spec.jsvalidate behavior preservation. Any newly extracted helper stays covered via its existing callers to maintain the 99% line / 85% branch coverage thresholds.Test Command
npm test(Jest, includes coverage thresholds vianpm test -- --coverage)don-petry commentedon Jul 7, 2026
Dev-Lead: Implementation Complete
Behavior-preserving refactors that reduce cognitive complexity (S3776) below the 15 threshold for all 4 flagged functions. No behavior change — validated by the existing test suite (Phase 2 TDD exception applies to a pure refactor).
Plan Execution
src/calendar-to-sheets/src/index.js—syncCalendarToSheet(25→~5): extractedupsertRows,insertNewRows,shouldDeleteRow,computeRowsToDeletesrc/gmail-to-drive-by-labels/src/index.js—processMessageToDocattachment loop (33→~5): extractedisDuplicateAttachment,resolveAttachmentFileNamesrc/gmail-to-drive-by-labels/src/index.js—rebuildDoc(17→~5): extractedclearDocPhase,moveEmailsPhase(null-sentinel preserves original early-return/fall-through control flow)deploy/index.html—handleDeploy(19→~8): extractedresolveDeployProjectId,buildDeployErrorHtmlVerification
npm test— 301/301 passingnpm test -- --coverage— exit 0, global thresholds met (branches 90.22 ≥ 85, functions 98.14 ≥ 95, lines 99.37 ≥ 99, statements 98.93 ≥ 95); extracted helpers at 100% function coveragenpm run check(prettier --check + eslint) — exit 0 (only pre-existing unused-var warnings in untouched test files)bash .dev-lead/scripts/dev-lead-lint.sh— all checks passednpx prettier --write .appliednode --checkon both refactoredindex.jsfiles — OKTest Results
Files Changed
src/calendar-to-sheets/src/index.js: splitsyncCalendarToSheetinto upsert/insert/delete helperssrc/gmail-to-drive-by-labels/src/index.js: split the attachment loop andrebuildDocstate machine into helpersdeploy/index.html: splithandleDeployinto project-resolution and error-html helpersNotes
NOSONARsuppressions used. All originalconsole.log/console.errorcalls and produced values/HTML are preserved verbatim, so runtime behavior is unchanged.deploy/index.htmlis not part of Jest coverage (covered by the Playwrightdeploy/tests/ui.spec.jse2e); its inline JS was validated via prettier parse + syntax review. Extracted functions live in the same<script>scope and are hoisted.processLabelGroupwas not flagged by SonarCloud and was left untouched to avoid scope creep.don-petry commentedon Jul 14, 2026
SonarCloud Audit (2026-07-14): still open — 4 finding(s), worst severity
CRITICAL.don-petry commentedon Jul 21, 2026
SonarCloud Audit (2026-07-21): still open — 4 finding(s), worst severity
CRITICAL.don-petry commentedon Jul 21, 2026
Dev-Lead Implementation Plan
Issue: #427 — SonarCloud: cognitive complexity (S3776)
Scope
Refactor the 4 functions flagged by SonarCloud rule
javascript:S3776to reduce cognitive complexity below the 15 threshold, with no behavior change.Findings located (verified locally with
eslint-plugin-sonarjs)src/gmail-to-drive-by-labels/src/index.jsforEachloop inprocessMessageToDocsrc/gmail-to-drive-by-labels/src/index.jsrebuildDocsrc/calendar-to-sheets/src/index.jssyncCalendarToSheetdeploy/index.htmlhandleDeployImplementation Checklist
src/calendar-to-sheets/src/index.js— extract upsert loop (applyUpserts) and delete loop (collectRowsToDelete) out ofsyncCalendarToSheetsrc/gmail-to-drive-by-labels/src/index.js— extract attachment dedup/save into a helper (processAttachment+findDuplicateFile) used byprocessMessageToDocsrc/gmail-to-drive-by-labels/src/index.js— extract phase bodies ofrebuildDoc(clearDocumentPhase,moveEmailsPhase)deploy/index.html— extract per-script deploy body (deployOneScript) and error-html builder (buildDeployErrorHtml) out ofhandleDeployTests to Write
deploy/index.htmlby the Playwright e2e suite; both act as the regression net. No new behavior is introduced, so per the Phase 2 exception no new failing tests are added. Coverage thresholds (99% lines) will be kept green since extracted helpers sit on already-exercised paths.Test Command
npm test(Jest + coverage);npm run test:e2e(Playwright, fordeploy/index.html); complexity re-verified witheslint-plugin-sonarjs.don-petry commentedon Jul 21, 2026
Dev-Lead: Implementation Complete
Refactored the 4 functions flagged by SonarCloud
javascript:S3776(cognitive complexity) so each drops below the 15 threshold, with no behavior change.Plan Execution
src/calendar-to-sheets/src/index.js— extractedapplyUpdatesAndCollectInserts(upsert loop) andcollectRowsToDelete(delete loop) out ofsyncCalendarToSheet(25 → 0 findings)src/gmail-to-drive-by-labels/src/index.js— extractedisDuplicateAttachment,resolveAttachmentName,processAttachmentout of theprocessMessageToDocattachment loop (33 → 0 findings)src/gmail-to-drive-by-labels/src/index.js— extractedclearDocumentPhaseandmoveEmailsPhaseout ofrebuildDoc(17 → 0 findings)deploy/index.html— extracteddeployOneScript(per-script deploy body) andbuildDeployErrorHtml(error status builder) out ofhandleDeploy(19 → 0 findings)Verification
eslint-plugin-sonarjs, S3776, threshold 15): all four files now report 0 findings.calendar-to-sheets/src/index.jsis 100% across the board.deploy/tests/ui.spec.js, covershandleDeploy): 65 passed.npm run check→ 0 errors (only pre-existing unused-var warnings in test files)..dev-lead/scripts/dev-lead-lint.sh→ all checks passed.npx prettier --writeapplied.Test Results
Files Changed
src/calendar-to-sheets/src/index.js: extracted upsert/delete loops fromsyncCalendarToSheetinto helpers.src/gmail-to-drive-by-labels/src/index.js: extracted attachment dedup/save helpers fromprocessMessageToDoc; extractedrebuildDocphase bodies into helpers.deploy/index.html: extracted per-script deploy and error-HTML builder fromhandleDeploy.Notes
Sessionbinding fromprocessMessageToDoc(it moved intoresolveAttachmentName) to keep lint clean.eslint-plugin-sonarjs(same S3776 rule as SonarCloud); the 4 findings map 1:1 to the issue's file counts.don-petry commentedon Jul 28, 2026
SonarCloud Audit (2026-07-28): still open — 4 finding(s), worst severity
CRITICAL.don-petry commentedon Aug 4, 2026
Resolved! No open SonarCloud findings remain in this workstream as of 2026-08-04. Closing automatically.