With this .rubocop.yml
AllCops: TargetRubyVersion: 3.4 Lint/UselessConstantScoping: Enabled: true
I expect bundle exec rubocop -a --disable-uncorrectable
not to add extraneous elements to an array.
# frozen_string_literal: true # This is a class. class Foo def valid?(bar) ALLOWED_VALUES.include?(bar) end private ALLOWED_VALUES = %w[ value1 value2 ].freeze def lolol; end end p Foo.new.valid?('#') # => false p Foo.const_get(:ALLOWED_VALUES) => # => ["value1", "value2"]Actual behavior
When Lint/UselessConstantScoping
is enabled, bundle exec rubocop -a --disable-uncorrectable
changes the code around ALLOWED_VALUES
to this:
# rubocop:todo Lint/UselessConstantScoping ALLOWED_VALUES = %w[ value1 # rubocop:todo Lint/UselessConstantScoping # rubocop:todo Lint/UselessConstantScoping value2 ].freeze # rubocop:enable Lint/UselessConstantScoping
There are the redundant comments, but more importantly it added a bunch of garbage to the array:
p Foo.new.valid?('#') # => true
p Foo.const_get(:ALLOWED_VALUES) # => ["value1", "#", "rubocop:todo", "Lint/UselessConstantScoping", "#", "rubocop:todo", "Lint/UselessConstantScoping", "value2"]
Steps to reproduce the problem
See above.
RuboCop version1.75.1 (using Parser 3.3.7.3, Prism 1.4.0, rubocop-ast 1.43.0, analyzing as Ruby 3.4, running on ruby 3.4.1) [x86_64-darwin24]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4