LoginSignup
3
2

More than 5 years have passed since last update.

Aspellでさっくりとソースコードのスペルチェック

Last updated at Posted at 2017-01-06

きっかけ

開発中案件でpaymentがpaymantになっている事件が発覚したため。
GNU Aspellでさっくりとチェックかけたいな、と思った。

前期: せめてファイル名だけでもきちんとしたい

Aspell導入

CentOSならyumでさっくり入る。

$ sudo yum install aspell-en
$ echo "lang en_US" > ~/.aspell.conf

チェックしてみる

$ cd path/to/files
$ find . -type f |sed "s/[A-Z][a-z]/ \0/g" | tr '[A-Z]' '[a-z]' |aspell list |sort|uniq

といった感じで実行して、

ajax
ami
ansible
apache
auth
bowerrc
btn
cli
colorbox
commom
conf
config
configs
const
consts
css
csv
(以下略)

直す

怪しいのを見つけたらgrepして、必要に応じて置換。

find . -type f -print | xargs grep -l typo_word | xargs sed -i "s/typo_word/correct_word/g";

あるいはgit-gsubを使って

git gsub typo_word correct_word

結果

commomなどが発掘され、平和が訪れたような気がした。

後期: さらに見つかり

ソースコード内の変数の中にbirthbayが埋もれていたりしたので、カッとなった。

改良してチェック

find . -type f -print |xargs file |grep text |awk -F' ' '{print $1}' |sed -e 's/://g' |xargs cat |sed "s/[A-Z][a-z]/ \0/g" |tr '[A-Z]' '[a-z]' |aspell list |sort|uniq

catで開いて、中身までチェック。

結果

2017-01-05_17h20_59.png

俺たちの戦いはまだ終わっていなかったりするし、次回作なんていらない。

まとめ

さっくりじゃなくなってきたので、ぼちぼち違う手法を使おうと思っている。

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2