Originally created by: Redo-San
Baseline (2026-10-06): npm run lint → 44 sonarjs/cognitive-complexity warnings (threshold is 30 per function). Worst offenders:
| Complexity |
Location |
| 117 |
Certificate/certificate.js:380 |
| 106 |
Watermark/watermark.js:197 |
| 100 |
cli/utils.js:116 |
| 84 |
Converter/converter.js:1855 |
| 81 |
Decentralized_Identity_DID/did.js:1010 |
| 78 |
Certificate/certificate_pdf.js:22 |
| 74 |
Certificate/certificate_epub.js:22 |
| 73 |
Document_Watermark/text_extractor.js:158 |
| 80 |
Document_Watermark/document_watermark_pdf.js:177 |
| 68 |
C2PA/c2pa.js:555 |
| 65 |
cli/commands/watermark.js:619 |
| 61 |
cli/commands/certificate.js:291 |
| 59 |
cli/commands/fingerprint.js:110 |
| 57 / 51 |
Assistant/assistant.js:95 / :340 |
| 56 |
cli/commands/audio_watermark.js:443 |
| 54 |
Audio_Watermark/audio_watermark.js:888, Iris_Biometric/iris_liveness.js:151 |
| 49 / 47 / 44 |
Forensic/forensic_core.js:310, Style/mpa-router.js:425, cli/commands/certificate.js:675 |
Change
Split the top offenders into small named helpers with their own tests — extraction only, no behaviour change. Start with the three 100+ functions; they are the ones that make review hard. Nothing here should be silenced with eslint-disable.
Acceptance criteria
- [ ]
npx eslint --config .tools/Developer_Toolkit/eslint.config.mjs . -f json → sonarjs/cognitive-complexity ≤ 15.
- [ ] Each extracted helper is covered by at least one assertion in an existing test file.
- [ ]
npm run check and npm run test:quick pass.
- [ ]
npm run madge:circular reports no new circular dependencies.