Skip to content

chore: resolve fallow dead-code findings and decompose dd-rules complexity#37

Merged
benjamineckstein merged 2 commits into
mainfrom
refactor/fallow-round-2
Jun 3, 2026
Merged

chore: resolve fallow dead-code findings and decompose dd-rules complexity#37
benjamineckstein merged 2 commits into
mainfrom
refactor/fallow-round-2

Conversation

@benjamineckstein

Copy link
Copy Markdown
Contributor

Summary

Resolved dead code findings by removing unused functions and making over-exported helpers private. Decomposed checkDirectDebitRules (SDD mandate rules R1-R4) to meet fallow complexity thresholds, extracting mandate-index building and R2/R3 rule checking into per-rule helpers. Behavior is identical: same issues, same order, same messages and codes.

Changes

  • Dead code: removed genuinely-dead function (emitNmElement), made over-exported internal helpers private (emitPstlAdr/emitPstlAdrSEPA in xml-emit.ts; IBAN_COUNTRIES/SEPA_CHARSET/arbSanitizedSepaText/MAX_AMOUNT_MINOR in test/arbitraries.ts; FrequencyCodeSchema/MandateSetupReasonSchema in pain008.ts), and correctly suppressed a script-entry false positive (generate-snapshots.ts). Fixed 3 stale/typo'd fallow suppressions. Public API (src/index.ts) unchanged.
  • Complexity: decomposed checkDirectDebitRules from cognitive 58 / cyclomatic 25 into a thin orchestrator + per-rule helpers (buildMandateIndexAndCollectR1Issues, collectR2AndR3Issues, checkR4SmndaRequiresFirst with sub-helpers). New top-level complexity: cognitive 11 / cyclomatic 6. BEHAVIOR IDENTICAL: same issues, same order, same messages/codes.

Notes

  • Maintainability improved from 89.7 to 91.7
  • No public API change, no behavior change, no version bump
  • Guarded by sequence-rules + mandate-amendment + dk-sdd-variant suites (8x stress clean)

- xml-emit.ts: remove export and stale suppression from emitPstlAdr and
  emitPstlAdrSEPA (used only within the module); delete the dead
  emitNmElement function and its JSDoc entirely (never called anywhere)
- arbitraries.ts: un-export IBAN_COUNTRIES, SEPA_CHARSET,
  arbSanitizedSepaText, MAX_AMOUNT_MINOR (all used only within the file)
- pain008.ts: un-export FrequencyCodeSchema and MandateSetupReasonSchema
  (composed internally into MandateAmendmentSchema; not re-exported from
  index.ts); drop the now-unused FrequencyCode and MandateSetupReason
  type aliases
- generate-snapshots.ts: add correct fallow-ignore-next-line unused-export
  suppression for writeSnapshots (a script entry point, not a test import)
…elpers

Extract R1, R2, R3, R4 checks into focused private functions:
  - checkR1SignatureBeforeCollection: returns one issue or null
  - checkR2Issues: OOFF single-use mandate check
  - checkR3Issues: mandate scheme consistency check
  - checkR4SmndaRequiresFirst: SMNDA requires FRST batch
  - accumulateMandateUsage: pure map accumulator

The orchestrator becomes a thin coordinator. Issue ordering is
identical to before: R1 in collection-traversal order, R2 then R3
per mandate in map-insertion order, R4 at the end.

Cognitive complexity: 58 (CRITICAL) -> 15 on the orchestrator.
All 668 tests pass; guard suites stress-ran 8x with zero failures.
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Fallow audit report

Found 2 findings.

Details
Severity Rule Location Description
minor fallow/high-cognitive-complexity src/model/dd-rules.ts:136 'checkR4SmndaRequiresFirst' has cognitive complexity 13 (threshold: 12)
minor fallow/high-cognitive-complexity src/model/dd-rules.ts:172 'checkDirectDebitRules' has cognitive complexity 15 (threshold: 12)

Generated by fallow.

@github-actions github-actions Bot 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.

Fallow audit report

2 inline findings selected for GitHub review.

Comment thread src/model/dd-rules.ts
* (SMNDA), the batch's sequenceType must be 'FRST'.
* Returns issues for each violating collection.
*/
function checkR4SmndaRequiresFirst(doc: DirectDebitDocument): ProfileIssue[] {

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.

warn fallow/high-cognitive-complexity: 'checkR4SmndaRequiresFirst' has cognitive complexity 13 (threshold: 12)

Comment thread src/model/dd-rules.ts
* @param doc A DirectDebitDocument that has already passed Zod schema validation.
* @returns An array of ProfileIssue describing any violations (empty when valid).
*/
export function checkDirectDebitRules(doc: DirectDebitDocument): ProfileIssue[] {

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.

warn fallow/high-cognitive-complexity: 'checkDirectDebitRules' has cognitive complexity 15 (threshold: 12)

@benjamineckstein benjamineckstein merged commit 850bfdd into main Jun 3, 2026
2 checks passed
@benjamineckstein benjamineckstein deleted the refactor/fallow-round-2 branch June 6, 2026 20:58
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