Back to all reviewers

Simplify complex expressions

cypress-io/cypress
Based on 5 comments
Other

Break down complex conditional logic, nested structures, and verbose syntax into smaller, well-named functions or more concise expressions. This improves code readability and maintainability.

Code Style Other

Reviewer Prompt

Break down complex conditional logic, nested structures, and verbose syntax into smaller, well-named functions or more concise expressions. This improves code readability and maintainability.

Key practices:

  • Extract complex nested if/else statements into descriptive helper functions
  • Use modern, idiomatic JavaScript/TypeScript syntax where available
  • Replace verbose type annotations with more concise alternatives
  • Break complex boolean conditions into named predicates

Example of improvement:

// Instead of complex nested conditions:
if (err && err.showDiff !== false && err.expected !== undefined && _sameType(err.actual, err.expected)) {
  // ...
}

// Extract into named functions:
const diffCanBeShown = (err) => err && err.showDiff !== false
const hasExpectedValue = (err) => err.expected !== undefined
const hasSameTypeValues = (err) => _sameType(err.actual, err.expected)

const showDiff = (err) => diffCanBeShown(err) && hasExpectedValue(err) && hasSameTypeValues(err)

Also prefer concise TypeScript syntax:

// Instead of: const docsMenuVariant: Ref<DocsMenuVariant> = ref('main')
const docsMenuVariant = ref<DocsMenuVariant>('main')

And use idiomatic JavaScript methods:

// Instead of: indexOf() !== -1
// Use: includes()
5
Comments Analyzed
Other
Primary Language
Code Style
Category

Source Discussions