Skip to content

Refactor: Limit frontend function nesting to maximum 4 levels deep #2487

@kasya

Description

@kasya

Refactor frontend functions with more than 4 levels of nesting to improve code readability and maintainability.

Rule: typescript:S2004
Here's a full list of issues we have under this rule

Why?

  • Readability: Deeply nested functions are harder to read and follow
  • Maintainability: Difficult to modify or debug complex nested structures
  • Testing: Nested functions are harder to unit test in isolation
  • Cognitive load: Increases mental overhead for developers

How to refactor

  • Use early returns to reduce nesting depth
  • Apply guard clauses to avoid nested if statements
  • Break down complex operations into smaller, composable functions
  • Extract nested logic into separate named functions

Scope

  • These issues are mostly happening in tests, but there are a couple of application code instances too

Metadata

Metadata

Assignees

Type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions