概要
aspellを利用してスペルチェックを行う
aspellとcspellどっちがいいんですかねえ…
ファイル配置例
.github
|-aspell
| |-ignore.txt
| |-run.sh
|
|-workflows
|-aspell.yaml
github actionsの設定
・pull_requestのopen時とブランチが更新されたときに実行
・ubuntuで
contentsはreadのみ
長時間動いてしまうと怖いのでtimeoutは1min
・PR対象のブランチをチェックアウト
元となるブランチもfetch(mainに固定してしまっているので、元ブランチが違う場合には記述を変える必要あり)
aspellをインストールして実行
name: aspell
on:
pull_request:
types: [ opened, synchronize ]
jobs:
main:
runs-on: ubuntu-22.04 # runner OS version
permissions:
contents: read
timeout-minutes: 1
steps:
- name: checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Fetch base branch
run: git fetch origin main
- name: aspell
run: |
sudo apt install -y aspell aspell-en > /dev/null 2>&1
sh ./.github/aspell/run.sh
aspellの実行
設定ファイルをわかりやすくするために
・個人辞書は小文字でsortして格納するルールとする
・git diff で変更があった部分のみチェックをする
tail -n +2 ./.github/aspell/ignore.txt > /tmp/trimmed_ignore.txt
tr A-Z a-z < /tmp/trimmed_ignore.txt > /tmp/lower_ignore.txt
diff /tmp/trimmed_ignore.txt /tmp/lower_ignore.txt
if [ $? -gt 0 ]; then
echo 'There is upper case words in .github/aspell/ignore.txt. please fix lower case.'
exit 1
fi
sort -u -f /tmp/lower_ignore.txt > /tmp/sorted_lower_ignore.txt
diff /tmp/lower_ignore.txt /tmp/sorted_lower_ignore.txt
if [ $? -gt 0 ]; then
echo 'Please sort words in .github/aspell/ignore.txt'
exit 1
fi
rm /tmp/trimmed_ignore.txt /tmp/lower_ignore.txt /tmp/sorted_lower_ignore.txt
cp ./.github/aspell/ignore.txt ~/.aspell.en.pws
git diff origin/main HEAD | grep "^+" | tr A-Z a-z | aspell list |sort |uniq > error_spells.txt
if [ -s ./error_spells.txt ]; then
echo 'Check the spelling. Please store in .github/aspell/ignore.txt if needed.'
cat ./error_spells.txt
exit 1
fi
rm ~/.aspell.en.pws
個人辞書
aspellの個人辞書だが、無視する単語を格納しているのでignore.txtというファイルにして格納している
run.sh内でデフォルトのファイル名に変更している
これはaspell実行時のオプションでファイル名指定でもいいかもしれない…
先頭行だけ個人辞書を表すヘッダ。残りには無視する単語を入れていく
personal_ws-1.1 en 0
api
aspell
cp
雑感
使い始めは毎回スペルチェックに引っかかるのでちょっと面倒
辞書が整ってくるとtypoを見つけることができたりして便利になってくる
textlintやpullリクエストへの自動コメントも入れたかったがそれはまた今度ということでここまで
参考