Prefer local_assigns.fetch over defined? in views
In many places in GitLab views, we checked for a local assign with - if defined?(variable) && variable == 'foo'
.
I think this is wrong and that we should use - variable = local_assigns.fetch(:variable, 'default_value')
at the top of the view (as much as possible) for several reasons:
- it's explicit what variables we're using
- we don't ask if we have a variable defined, we just tell we want it, and give a default value if it's not here
- we fetch it at the beginning of the file to avoid mixing too much Ruby logic with actual view code
Let's discuss that and if we find an agreement, I'll document it.