Skip to content

Refactor nested ternary operators into independent statements #2520

@kasya

Description

@kasya

We need to refactor nested ternary operators into independent statements or more readable control structures, in accordance with SonarQube rule S3358. Here's a full list of issues (currently - 10).

Eliminate all nested ternary operations by extracting them into independent statements, intermediate variables, or alternative control structures like if-else statements.

For each nested ternary:

  • Evaluate the logic and determine if it can be simplified
  • Extract into intermediate variables with descriptive names
  • Consider using if-else statements for better clarity
  • Break complex conditions into multiple clear, independent statements

Important Exception

This rule does not apply to JSX expressions where ternaries are used for conditional rendering or conditional attributes, as long as the nesting occurs in separate JSX expression containers.

Tasks

  • Exclude valid JSX conditional rendering patterns (if not nested)
  • Refactor each nested ternary into independent statements
  • Use descriptive variable names for intermediate values
  • Update unit tests if necessary
  • Verify no breaking changes in functionality

Acceptance Criteria

  • All nested ternaries (except valid JSX patterns) are refactored
  • All existing tests pass

Are you going to work on implementing this?

  • Yes
  • No

Metadata

Metadata

Assignees

Type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions