-
Notifications
You must be signed in to change notification settings - Fork 226
Closed
Description
Just upgraded and got bit by this in a few places:
app/lib/form_builders/tailwind_form_builder.rb:187:5: Lint/UselessConstantScoping: Useless `private` access modifier for constant scope.
The offending code is deep down among a number of private methods:
CUSTOM_OPTS = [:inline, :label, :field_classes, :erase_field_classes, :wrapper_classes, :variant].freeze
def partition_custom_opts(opts)
(opts || {}).partition { |k, v| CUSTOM_OPTS.include?(k) }.map(&:to_h)
end
CUSTOM_LABEL_OPTS = [:text, :class, :inline, :extra_classes, :hidden, :skip]
def partition_custom_label_opts(opts)
(opts || {}).partition { |k, v| CUSTOM_LABEL_OPTS.include?(k) }.map(&:to_h)
end
In this case, the two constant definitions are triggering the error here.
My take is:
- Basic knowledge of Ruby will tell you constants can't be private. One of the first things we learn about Ruby is that constants are all global and there is just one shared namespace. Even a novice language ability doesn't need an automated tool to remind me
- In the case of private-method-specific frozen constants that are defined more for performance than for reference-ability (either of these could have been computed or loaded at boot from a yaml file or something), having those constants right next to where they're used (in this case at line 187 and later) makes a lot more sense to me than being forced to drag them all the way to the top of the file listing where they make no sense out of context just to satisfy a rule like this one
Would love to see this (re-?)disabled as a result
coorasse, soulcutter, timriley, MoskitoHero, roxannecojocariu and 1 more
Metadata
Metadata
Assignees
Labels
No labels