Skip to content

Disable Lint/UselessConstantScoping #703

@searls

Description

@searls

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:

  1. 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
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions