6
2

typosでtypoチェックをしよう

Last updated at Posted at 2024-08-06

typosはタイポチェックツールです。
恥ずかしい間違いをする前に入れておきましょう!

実行サンプル

CleanShot 2024-08-06 at 12.35.31.png

インストール

# cargo
cargo install typos-cli

# brew
brew install typos-cli

使い方

設定ファイル

除外したいファイルやキーワードがあれば設定ファイルに記載しておきましょう。

~/.config/typos.toml
[files]
# envやpubファイル等は除外
extend-exclude = [
    "*.pub",
    "Brewfile",
    "*env*",
]

# 固有のアプリ名や造語を登録
[default.extend-words]
regist = "regist"

実行方法

実行するとこんな感じで教えてくれます。
コンフィグファイルはXDG_CONFIG(~/.config)を考慮していないようなので、自分でパスを指定する必要があります。必要があれば指定しておきましょう!

% typos --config ~/.config/typos.toml .

error: `formated` should be `formatted`
  --> ./client/src/components/Map/GroupSearch/MapCanvas.jsx:7:10
  |
7 | import { formatedPin, unfocus } from '../../../libs/map';

ファイルパス込みのコマンドをフルで記載するのはしんどいので、aliasかabbrを使うと良いでしょう
僕は、aliasだとそのままhistoryに残るのでabbrで展開して実行するのが好みです。

.zshrc or .bashrc
alias typos="typos --config ~/.config/typos.toml ."
zsh/abbreviations
abbr -S typos="typos --config ~/.config/typos.toml ."

sedで修正

見つけてしまったら直したくなると思うので、findとgsedで修正する方法を書いておきます。
srcを探索して、beforeをafterに置き換えるコマンドです。
sedはBSD系とGNU系があるので注意ですね!

# brew install gnu-sed
find ./src/ -type f -exec gsed -i 's/before/after/g' {} +

typosをいつ実行するか?

僕の場合は、LSPとしてnvimに組み込んでいます

CleanShot 2024-08-06 at 12.25.55.png

pre-commitやGithub Actionsで対応するのも良さそうです。
お好みの手段で自動的に検知できると嬉しいですね!

6
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
6
2