flipper icon indicating copy to clipboard operation
flipper copied to clipboard

Add NamingStyle adapter to enforce format for added features.

Open bkeepers opened this issue 1 year ago • 1 comments
trafficstars

As suggested by @LandonSchropp in https://github.com/flippercloud/flipper/issues/879, this adds the ability to constrain feature names to a naming style.

require 'flipper/adapters/naming_style'

Flipper.configure do |config|
  config.use Flipper::Adapters::NamingStyle, :snake # or :camel, :kebab, :screaming_snake, or a Regexp
end

# This will work because the feature key is in snake_case.
Flipper.enable(:snake_case)

begin
  # This will raise an error because the feature key is in CamelCase.
  Flipper.enable(:CamelCase)
rescue Flipper::Adapters::NamingStyle::InvalidFormat => e
  puts "#{e.class}: #{e.message}"
end

Output:

Flipper::Adapters::NamingStyle::InvalidFormat: Feature key "CamelCase" does not match format /^[a-z0-9]+(_[a-z0-9]+)*$/

bkeepers avatar Aug 22 '24 13:08 bkeepers

Awesome!

Any thoughts on if/how we should communicate the error raised from the flipper-ui? Should we rescue this error and add validation errors to the form or something?

IMO, the best UX would be an inline error message that displays once the user has blurred the input. The second-best would be a banner/inline error if the user tries to submit the form. 😄

LandonSchropp avatar Aug 23 '24 17:08 LandonSchropp