Skip to content

Instantly share code, notes, and snippets.

@r-plus
Last active October 5, 2017 03:35
Show Gist options
  • Save r-plus/5fffc745926fd932e752c3ca2215644c to your computer and use it in GitHub Desktop.
Save r-plus/5fffc745926fd932e752c3ca2215644c to your computer and use it in GitHub Desktop.
Swiftlintのunneeded_break_in_switchルール警告行の一括行削除

Swiftlint 0.23 unneeded_break_in_switch 対応

Swiftlint 0.23に unneeded_break_in_switch ルールが追加された。 是非利用したいのだが、既存の警告の量が多い。 autocorrect非対応なので、自動では消してくれない。

breakは単一の行になっているから全部自動で消そう

  1. unneeded_break_in_switch ルールの警告のみが出る状態で swiftlint > warn.txt
  2. 行番号指定で削除するのに昇順だとずれるので、vimで降順にする :g/^/m0
  3. ワンライナーで行削除(下記ではmacでgnu sedを利用するのにbrewで入れたgsedを使っている。 ${match[n]} の部分はzshのものなので注意)
while read line
do
 if [[ "${line}" =~ ^(.*\.swift):([0-9]+): ]]; then
   gsed -i"" -e "${match[2]}d" $match[1]
 fi
done < warn.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment