Class: RuboCop::Cop::Gusto::FeatureFlagConstants
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Gusto::FeatureFlagConstants
- Defined in:
- lib/rubocop/cop/gusto/feature_flag_constants.rb
Overview
Enforces that FeatureFlag.active? is called with a constant rather than a
string literal. Defining flag keys as constants keeps them in one place,
makes typos a load-time error instead of a silent always-off flag, and lets
tools find every reference to a flag.
FeatureFlag is a constant, so it is never nil and safe navigation
(FeatureFlag&.active?) is never used; the cop only handles on_send.
Constant Summary collapse
- MSG =
"FeatureFlag keys should be constants, not strings"- RESTRICT_ON_SEND =
%i(active?).freeze
Instance Method Summary collapse
Instance Method Details
#feature_flag_with_string?(node) ⇒ Object
25 26 27 |
# File 'lib/rubocop/cop/gusto/feature_flag_constants.rb', line 25 def_node_matcher :feature_flag_with_string?, <<~PATTERN (send (const nil? :FeatureFlag) :active? (str _) ...) PATTERN |
#on_send(node) ⇒ Object
29 30 31 |
# File 'lib/rubocop/cop/gusto/feature_flag_constants.rb', line 29 def on_send(node) add_offense(node) if feature_flag_with_string?(node) end |