Fix an incorrectly adds a disable statement for Layout/SpaceInsideArrayLiteralBrackets with --disable-uncorrectable

このエントリーをはてなブックマークに追加

Fix an incorrectly adds a disable statement for Layout/SpaceInsideArrayLiteralBrackets with --disable-uncorrectable
https://github.com/rubocop/rubocop/pull/10493

以下のコードに対して rubocop --auto-correct --disable-uncorrectable を実行すると発生する問題があった。

# frozen_string_literal: true

puts [ :something ]

以下のように修正が実施される

» rubocop --auto-correct --disable-uncorrectable
Inspecting 1 file
C

Offenses:

example.rb:3:9: C: [Corrected] Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
puts [ :something ]
        ^
example.rb:3:20: C: [Todo] Layout/SpaceInsideArrayLiteralBrackets: Do not use space inside array brackets.
puts [ :something ]
                   ^

1 file inspected, 2 offenses detected, 2 offenses corrected
# frozen_string_literal: true

puts [:something]

そして再度、rubocop --auto-correct --disable-uncorrectableを実行すると disable コメントについての指摘は解消されているというLint/RedundantCopDisableDirectiveの指摘が上がる

» rubocop --auto-correct --disable-uncorrectable
Inspecting 1 file
W

Offenses:

example.rb:3:19: W: [Corrected] Lint/RedundantCopDisableDirective: Unnecessary disabling of Layout/SpaceInsideArrayLiteralBrackets.
puts [:something] # rubocop:todo Layout/SpaceInsideArrayLiteralBrackets
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense corrected