スペルミスやタイプミスを修正するmisspell-fixerを使う

はじめに

コードを書いているときやドキュメントを作成しているとき、ついうっかりスペルミスをしてしまうことは誰にでもある。
recieve (receive) や seperate (separate) といった典型的なミスは、自分ではなかなか気づきにくい。

misspell-fixer は、スペルミスやタイプミスを自動的に検出し、修正してくれる便利なツールである。
今回はこのツールを使って、プロジェクト内のスペルミスをなくす方法を紹介する。

環境

Ubuntu 24.04 LTS
misspell-fixer 0.5-1

misspell-fixerの特徴

機能

  • ソースコードやドキュメント内の一般的なスペルミスを検出・修正
  • 再帰的にディレクトリを探索
  • 修正前のバックアップ作成機能
  • 高速な並列処理モード

インストール

UbuntuなどのDebian系ディストリビューションでは、apt コマンドで簡単にインストールできる。

sudo apt update
sudo apt install misspell-fixer
ログ
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  ugrep
Suggested packages:
  poppler-utils antiword pandoc
The following NEW packages will be installed:
  misspell-fixer ugrep
0 upgraded, 2 newly installed, 0 to remove and 86 not upgraded.
Need to get 627 kB of archives.
After this operation, 3,141 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu noble/universe amd64 ugrep amd64 5.0.0+dfsg-1 [504 kB]
Get:2 http://archive.ubuntu.com/ubuntu noble/universe amd64 misspell-fixer all 0.5-1 [123 kB]
Fetched 627 kB in 3s (232 kB/s)         
Selecting previously unselected package ugrep.
(Reading database ... 40843 files and directories currently installed.)
Preparing to unpack .../ugrep_5.0.0+dfsg-1_amd64.deb ...
Unpacking ugrep (5.0.0+dfsg-1) ...
Selecting previously unselected package misspell-fixer.
Preparing to unpack .../misspell-fixer_0.5-1_all.deb ...
Unpacking misspell-fixer (0.5-1) ...
Setting up ugrep (5.0.0+dfsg-1) ...
Setting up misspell-fixer (0.5-1) ...
Processing triggers for man-db (2.12.0-4build2) ...

準備

まずは、スペルミスを含むテスト用のファイルを用意する。
以下のような内容の misspell_test.md というファイルを作成 する。

misspell_test.md
# Test File for misspell-fixer

This file contains some intentional spelling mistakes to test the tool.

1. I hope to recieve a reply soon. (receive)
2. Please keep the items seperate. (separate)
3. The langauge setting is incorrect. (language)
4. The operation was succesful. (successful)
5. This is a wierd behavior. (weird)

使ってみる

基本的な使い方(確認モード)

まずは、どのようなミスが含まれているかを確認するために、-s (show diff) オプションをつけて実行してみる。
デフォルトでは修正は行われず、検出されたミスが diff 形式で表示される。

misspell-fixer -s .

実行すると、以下のように修正内容が表示される。

misspell-fixer: -s Enable showing of diffs.
misspell-fixer: Target directories: ./misspell_test.md
misspell-fixer: Real run (-r) has not been enabled. Files will not be changed. Use -r to override this.
misspell-fixer: Iteration 0: prefiltering.
misspell-fixer: Iteration 0: processing.
--- ./misspell_test.md  2025-12-18 19:34:58.211426066 +0000
+++ ./misspell_test.md.18328    2025-12-18 19:36:31.699289782 +0000
@@ -2,8 +2,8 @@
 
 This file contains some intentional spelling mistakes to test the tool.
 
-1. I hope to recieve a reply soon. (receive)
-2. Please keep the items seperate. (separate)
+1. I hope to receive a reply soon. (receive)
+2. Please keep the items separate. (separate)
 3. The langauge setting is incorrect. (language)
-4. The operation was succesful. (successful)
-5. This is a wierd behavior. (weird)
+4. The operation was successful. (successful)
+5. This is a weird behavior. (weird)
misspell-fixer: Iteration 0: done.

なお、オプションなしで misspell-fixer . を実行すると、修正対象がある場合は終了コード 1 で終了する(何も表示されない)。

実際に修正する

修正内容に問題がなければ、-r (real mode) オプションをつけて実行する。
これにより、ファイルが実際に書き換えられる。

misspell-fixer -r .

デフォルトでは、修正前のファイルが .BAK という拡張子でバックアップされる。
Gitなどでバージョン管理をしていてバックアップが不要な場合は、-n (no backup) オプションを併用するとよい。

misspell-fixer -rn .

高速化

大規模なプロジェクトの場合は、-f (fast) オプションをつけることで並列処理が有効になり、処理速度が向上する。

misspell-fixer -frn .

参考

おわりに

スペルミスは些細な問題に見えるが、コードの可読性を下げたり、検索性を悪化させたりする原因になる。
misspell-fixer をCIに組み込んだり、定期的に実行したりすることで、クリーンなコードベースを保つことができる。

実際に自分が書いた記事を対象に試してみたところ、いくつかのスペルミスが検出され、簡単に修正できた。
特に「英語が苦手で…」という方(私を含む)には、強力な助っ人となってくれる。

Hugo で構築されています。
テーマ StackJimmy によって設計されています。