cSpell でピリオド (.) から始まるパスをチェック対象にしたい
こんにちは、製造ビジネステクノロジー部の若槻です。
cSpell を使うと、Node.js 環境にスペルチェッカーを導入することができます。
今回は、cSpell でピリオド/ドット (.) から始まるファイルやディレクトリ配下をチェック対象にしたい場合の Tips を紹介します。
環境
$ npm list cspell
...
└── cspell@9.6.0
$ node --version
v22.18.0
.github ディレクトリ配下が既定でチェックされない?
次の .github/ 配下のファイルに対してスペルチェックが行われるようにしたいです。
.github/workflows/**.github/pull_request_template.md
しかしいずれのファイルも明らかな誤字を含んでいるのに、チェックされていないのかエラーになりません。Files checked の数も明らかに少ないです。
$ npx cspell lint . --gitignore
CSpell: Files checked: 4, Issues found: 0 in 0 files.
チェック対象にする方法
.github ディレクトリ配下が既定でチェックされない理由は、、cSpell は既定では隠しファイルのパスをチェック対象にしない仕様になっているためです。これを回避する方法を2つ紹介します。
dot オプションを付ける
下記 Issue で4年前に対応がなされていました。
cspell lint コマンドで dot オプション (--dot) が追加されていました。こちらを使ってみます。
すると、ドットから始まるファイルやディレクトリ配下もチェック対象に含まれるようになりました!
$ npx cspell lint . --dot --gitignore
1/17 .github/CODEOWNERS 207.63ms X
.github/CODEOWNERS:1:4 - Unknown word (shuntaka)
.github/CODEOWNERS:1:18 - Unknown word (tomoki)
.github/CODEOWNERS:1:31 - Unknown word (rwakatsuki)
3/17 .github/pull_request_template.md 20.90ms X
.github/pull_request_template.md:14:23 - Unknown word (SSIA)
.github/pull_request_template.md:16:5 - Unknown word (SSIA)
7/17 .github/workflows/manual-deploy-to-development.yml 1.45ms X
.github/workflows/manual-deploy-to-development.yml:4:31 - Unknown word (cicd)
8/17 .gitignore 0.75ms X
.gitignore:3:2 - Unknown word (eslintcache)
12/17 .vscode/extensions.json 1.09ms X
.vscode/extensions.json:3:6 - Unknown word (dbaeumer)
.vscode/extensions.json:4:6 - Unknown word (esbenp)
.vscode/extensions.json:6:6 - Unknown word (Arjun)
13/17 .vscode/settings.json 1.59ms X
.vscode/settings.json:3:33 - Unknown word (esbenp)
.vscode/settings.json:6:33 - Unknown word (esbenp)
CSpell: Files checked: 17, Issues found: 12 in 6 files.
この時、.git ディレクトリ配下もチェック対象に含まれてしまうため、コンフィグファイルで除外をしておくようにしましょう。
{
"ignorePaths":[
".git/**"
]
}
明示的にパス指定する
cspell lint コマンドで明示的にパス指定してしまう方法もあります。指定は Glob パターンで行えます。
$ npx cspell lint . .github/** --gitignore
1/11 .github/CODEOWNERS 216.24ms X
.github/CODEOWNERS:1:4 - Unknown word (shuntaka)
.github/CODEOWNERS:1:18 - Unknown word (tomoki)
.github/CODEOWNERS:1:31 - Unknown word (rwakatsuki)
3/11 .github/pull_request_template.md 23.14ms X
.github/pull_request_template.md:14:23 - Unknown word (SSIA)
.github/pull_request_template.md:16:5 - Unknown word (SSIA)
7/11 .github/workflows/manual-deploy-to-development.yml 1.70ms X
.github/workflows/manual-deploy-to-development.yml:4:31 - Unknown word (cicd)
CSpell: Files checked: 11, Issues found: 6 in 3 files.
すべての隠しファイルを対象にしたくない場合に便利です。
おわりに
cSpell でピリオド/ドット (.) から始まるファイルやディレクトリ配下をチェック対象にしたい場合の Tips の紹介でした。
初めは後者の明示的なパスの指定で対応していましたが、dot オプションなる便利なオプションもあったのですね。今後はこちらを使っていきたいと思います。
以上







