0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

textlintを使ってカスタム文章チェック

Last updated at Posted at 2024-05-25

概要

マークダウンで記事を書くことがあったので、文章の内容をチェックするtextlintの導入方法についてまとめる。
今回は独自のルールを指定したかったので、設定方法について記載。

ローカル環境

  • macOS:Ventura(13.6)
  • npmとnodeのバージョン
$ npm --version
10.2.4

$ node --version
v21.6.2

設定後のディレクトリ

├── .textlintrc.json
├── custom_rule.yml
├── node_modules
│  ├── xxxxxxxxx
:  :  :
│  │  └── yyyyyy
│  └── zzzzzzzzz
:  
├── package-lock.json
├── package.json
└── text
    └── sample.md

手順

text-lintパッケージをローカルインストール

$ npm install --save-dev textlint-rule-preset-ja-technical-writing

・node_modulesディレクトリ
・package-lock.jsonファイル
・package.jsonファイル
が作成される。

textlint 初期化

$ npx textlint --init

.textlintrc.jsonファイルが作成される。

独自ルール設定

custom_rule.ymlファイル作成し、ルールを設定していく。
ここではWebという文字の揺らぎをチェックする。

custom_rule.yml
version: 1
rules:
  - expected: Web
    pattern: WEB
  - expected: Web
    pattern: web
  - expected: Web
    pattern: ウェブ

設定ファイル更新

.textlintrc.jsonファイルを更新し、独自ルールを設定したファイルをみるようにする。

.textlintrc.json
{
  "rules": {
    "preset-ja-technical-writing": true,
    "prh": {
        "rulePaths": [
            "./custom_rule.yml"
        ]
    }
  }
}

ファイル作成

textフォルダ配下にsample.mdファイルを作成し、文章を記載する。

/text/sample.md
私はWEBエンジニアです。
私はWebエンジニアです。
私はwebエンジニアです。

文章チェック

$ npx textlint ./text/sample.md

/{プロジェクト}/text/sample.md
  1:3  ✓ error  WEB => Web  prh
  3:3  ✓ error  web => Web  prh

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

まとめ

技術文書向けのルールリポジトリはこちら
https://github.com/textlint-ja/textlint-rule-preset-ja-technical-writing

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?