Back to all reviewers

Environment variable validation

facebook/react-native
Based on 2 comments
Ruby

Environment variables should be properly validated with correct type checking and without redundant conditions. Common issues include comparing strings to integers and using unnecessary double-checks that can lead to unexpected behavior.

Configurations Ruby

Reviewer Prompt

Environment variables should be properly validated with correct type checking and without redundant conditions. Common issues include comparing strings to integers and using unnecessary double-checks that can lead to unexpected behavior.

Key principles:

  1. Avoid redundant checks: Don’t check if an environment variable exists and then check its value in the same condition
  2. Use correct types: Environment variables are always strings, so compare against string values
  3. Simplify boolean logic: Use direct comparisons instead of complex conditional chains

Examples of issues and fixes:

Problematic patterns:

# Redundant checking
if ENV["RCT_USE_PREBUILT_RNCORE"] && ENV["RCT_USE_PREBUILT_RNCORE"] == "1"

# Type mismatch - comparing string to integer
return ENV["RCT_NEW_ARCH_ENABLED"] == 0 ? false : true

Improved patterns:

# Direct value check
if ENV["RCT_USE_PREBUILT_RNCORE"] == "1"

# Correct string comparison with simplified logic
return ENV["RCT_NEW_ARCH_ENABLED"] != "0"

This approach prevents runtime errors, improves code readability, and ensures consistent behavior across different environments and deployment scenarios.

2
Comments Analyzed
Ruby
Primary Language
Configurations
Category

Source Discussions