Class: RuboCop::Cop::Ezcater::FeatureFlagActive

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/ezcater/feature_flag_active.rb

Overview

Use ‘EzcaterFeatureFlag.active?` with a tracking_id or array of identifiers

Examples:


# good
EzFF.active?("FlagName", tracking_id: "user:12345")
EzFF.active?("FlagName", identifiers: ["user:12345", "user:23456"])
EzFF.active?(defined_flag_name_var, tracking_id: "brand:12345")
EzFF.active?(@flag_name_ivar, tracking_id: "brand:12345")

# bad
EzFF.active?("FlagName")
EzFF.active?(defined_flag_name_var)
EzFF.active?(@flag_name_ivar)

Constant Summary collapse

MSG =
"`EzFF.active?` must be called with at least one of `tracking_id` or `identifiers`"
FIRST_PARAM_MSG =
"The first argument to `EzFF.active?` must be a string or predefined variable"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rubocop/cop/ezcater/feature_flag_active.rb', line 51

def on_send(node)
  return unless method_call_matcher(node)

  if !first_param_good(node)
    add_offense(node, location: :expression, message: FIRST_PARAM_MSG)
  end

  if ezff_active_one_arg(node) || !args_matcher(node)
    add_offense(node, location: :expression, message: MSG)
  end
end