simplify and comment dangling comma handling

This commit is contained in:
Max Eisner 2022-07-31 21:29:50 +02:00
parent ab09d15703
commit 60db35096f
No known key found for this signature in database
GPG Key ID: 4BF122C22879F0C8

View File

@ -527,10 +527,8 @@ module RuboCop
offending_node(offenses.last) offending_node(offenses.last)
replacement = if (%w[:bash :zsh :fish] - shells).empty? replacement = if (%w[:bash :zsh :fish] - shells).empty?
@offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, "") @offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, "")
.gsub(",,", ",") .sub(", )", ")") # clean up dangling trailing comma
.sub(", )", ")") .sub("(, ", "(") # clean up dangling leading comma
.sub("(, ", "(")
.sub("()", "")
else else
@offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/, @offensive_node.source.sub(/shells: \[(:bash|:zsh|:fish)\]/,
"shells: [#{shells.join(", ")}]") "shells: [#{shells.join(", ")}]")