add check if executable and subcmd are the same before combining

e.g. ˚jrsonnet˚ needs this
This commit is contained in:
Max Eisner 2022-08-11 16:56:04 +02:00
parent cf84800939
commit 02c9cc0720
No known key found for this signature in database
GPG Key ID: 4BF122C22879F0C8

View File

@ -517,7 +517,14 @@ module RuboCop
return if offenses.blank?
T.must(offenses[0...-1]).each do |node|
T.must(offenses[0...-1]).each_with_index do |node, i|
# executable and subcmd have to be the same to be combined
if node.arguments.first != offenses[i + 1].arguments.first ||
node.arguments.second != offenses[i + 1].arguments.second
shells.delete_at(i)
next
end
offending_node(node)
problem "Use a single `generate_completions_from_executable` " \
"call combining all specified shells." do |corrector|
@ -526,6 +533,8 @@ module RuboCop
end
end
return if shells.length <= 1 # no shells to combine left
offending_node(offenses.last)
replacement = if (%w[:bash :zsh :fish] - shells).empty?
@offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, "")