textlintを使ってみる

textlintを使ってみる

作業用のディレクトリを作成する。

$ mkdir textlint_test
$ cd textlint_test

package.jsonファイルを作成する。

$ npm init -y

textlintをインストールする。

$ npm install --save-dev textlint

設定ファイル(.textlintrc)を作成する。

$ npx textlint --init

ルールをインストールする。

$ npm install --save-dev textlint-rule-preset-ja-spacing
$ npm install --save-dev textlint-rule-preset-ja-technical-writing
$ npm install --save-dev textlint-rule-spellcheck-tech-word

設定ファイル(.textlintrc)を編集してルールを設定する。

{
  "filters": {},
  "rules": {
    "preset-ja-spacing": true,
    "preset-ja-technical-writing": true,
    "spellcheck-tech-word": true
  }
}

テスト用にテキスト文書を作成する。

$ echo 'この javascriptは おかしい' > test.txt

テキストをチェックする。

$ npx textlint test.txt

/Users/yamamoto/textlint_test/test.txt
  1:3   ✓ error  原則として、全角文字と半角文字の間にスペースを入れません。  ja-spacing/ja-space-between-half-and-full-width
  1:4   ✓ error  javascript => JavaScript                                    spellcheck-tech-word
  1:15  ✓ error  原則として、全角文字どうしの間にスペースを入れません。      ja-spacing/ja-no-space-between-full-width
  1:19  error    文末が"。"で終わっていません。                              ja-technical-writing/ja-no-mixed-period

✖ 4 problems (4 errors, 0 warnings)
✓ 3 fixable problems.
Try to run: $ textlint --fix [file]

テキストを修正する。

$ npx textlint --fix test.txt

/Users/yamamoto/textlint_test/test.txt
  1:4   ✔   javascript => JavaScript                                    spellcheck-tech-word
  1:15  ✔   原則として、全角文字どうしの間にスペースを入れません。      ja-spacing/ja-no-space-between-full-width
  1:3   ✔   原則として、全角文字と半角文字の間にスペースを入れません。  ja-spacing/ja-space-between-half-and-full-width

✔ Fixed 3 problems
✖ Remaining 1 problem

修正されたテキストを確認する。

$ cat test.txt
このJavaScriptはおかしい

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください