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")
EzFF.active?(CONSTANT_NAME, tracking_id: "brand:12345")
EzFF.active?(config.flag_name, tracking_id: "brand:12345")

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

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 literal or a variable " \
"or constant assigned to a string"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rubocop/cop/ezcater/feature_flag_active.rb', line 56

def on_send(node)
  return unless method_call_matcher(node)

  if first_param_bad(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