Class: RuboCop::Cop::Dutchie::LaunchDarklyDefaults

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/dutchie/launchdarkly_defaults.rb

Overview

Ensures all LaunchDarkly feature flag calls have default values to prevent failures during LaunchDarkly service outages

This cop supports two LaunchDarkly patterns:

  1. Armageddon pattern: DutchieFeatureFlags.flag(), .context_flag(), etc.
  2. MenuConnector pattern: ld_client.variation(), MenuConnector::App.variation()

Examples:

Armageddon pattern

# bad
DutchieFeatureFlags.flag("some.flag")
DutchieFeatureFlags.context_flag("some.flag", dispensary_id: id)
DutchieFeatureFlags.on?("some.flag")

# good
DutchieFeatureFlags.flag("some.flag", false)
DutchieFeatureFlags.context_flag("some.flag", default: false, dispensary_id: id)
DutchieFeatureFlags.on?("some.flag", default: false)

MenuConnector pattern

# bad
ld_client.variation("flag", context)
MenuConnector::App[:launchdarkly].variation("flag", context)

# good
ld_client.variation("flag", context, false)
MenuConnector::App[:launchdarkly].variation("flag", context, false)

Constant Summary collapse

MSG_FLAG =
'DutchieFeatureFlags.flag must have a default value as 2nd parameter'
MSG_CONTEXT_FLAG =
'DutchieFeatureFlags.context_flag must have a default: parameter'
MSG_DISPENSARY_FLAG =
'DutchieFeatureFlags.dispensary_flag must have a default: parameter'
MSG_ENTERPRISE_FLAG =
'DutchieFeatureFlags.enterprise_flag must have a default: parameter'
MSG_ON =
'DutchieFeatureFlags.on? should have a default: parameter'
MSG_OFF =
'DutchieFeatureFlags.off? should have a default: parameter'
MSG_VARIATION =
'LaunchDarkly variation must have a default value as 3rd parameter'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/rubocop/cop/dutchie/launchdarkly_defaults.rb', line 128

def on_send(node)
  # Check Armageddon patterns
  check_flag_method(node)
  check_context_flag_method(node)
  check_dispensary_flag_method(node)
  check_enterprise_flag_method(node)
  check_on_method(node)
  check_off_method(node)

  # Check MenuConnector patterns
  check_variation_method(node)
  check_mock_variation_method(node)
end