Back to all reviewers

simplify nested conditionals

argoproj/argo-cd
Based on 2 comments
Other

Combine multiple nested if statements using logical operators (and/or) to improve code readability and reduce unnecessary indentation. Remove redundant nil checks when they are unnecessary, especially when subsequent checks would naturally handle the nil case.

Code Style Other

Reviewer Prompt

Combine multiple nested if statements using logical operators (and/or) to improve code readability and reduce unnecessary indentation. Remove redundant nil checks when they are unnecessary, especially when subsequent checks would naturally handle the nil case.

Instead of deeply nested conditions:

if obj.status ~= nil then
  if obj.status.conditions ~= nil then
    for i, condition in ipairs(obj.status.conditions) do
      if condition.type ~= nil then
        if condition.type == "Ready" then
          if condition.status ~= nil and condition.reason ~= nil then
            -- logic here
          end
        end
      end
    end
  end
end

Consolidate into cleaner, more readable code:

if obj.status and obj.status.conditions then
  for i, condition in ipairs(obj.status.conditions) do
    if condition.type == "Ready" and condition.status == "True" and condition.reason == "SuccessfulCreateOrUpdate" then
      -- logic here
    end
  end
end

This approach reduces cognitive load, eliminates unnecessary nesting levels, and makes the code’s intent clearer by focusing on the actual conditions that matter rather than defensive nil checking.

2
Comments Analyzed
Other
Primary Language
Code Style
Category

Source Discussions