kakakakakku blog

Weekly Tech Blog: Keep on Learning!

Re:VIEW で textlint-filter-rule-comments を使う

textlint で textlint-filter-rule-comments を使うとコメント記法で「特定のルールを無視する」範囲を設定できる.

github.com

しかし textlint-plugin-review と組み合わせて Re:VIEW で textlint-filter-rule-comments を使う場合は <!-- --> ではなく #@# という Re:VIEW のコメント記法を使う必要がある.ポイントはここまで👌

#@# textlint-disable
#@# textlint-enable

github.com

検証ログ 📄

検証ログを残しておく.まず,今回のサンプルとして textlint-plugin-reviewtextlint-filter-rule-commentstextlint-rule-preset-ja-technical-writing を組み合わせた .textlintrc を作っておく.textlint-filter-rule-commentsfilters に設定してある.

{
  "filters": {
    "comments": true
  },
  "rules": {
    "preset-ja-technical-writing": true
  },
  "plugins": [
    "review"
  ]
}

そして Re:VIEW ドキュメントとして sample.re を作っておく.文章は適当で ja-technical-writing/max-ten でエラーが出るように意図的に を多く使っている.

= サンプル

今日は、とても、良い、天気、です。

さっそく sample.re に textlint を実行すると ja-technical-writing/max-ten でエラーが出る.ここまでは期待した通り!

$ npx textlint ./*.re

  3:14  error  一つの文で""4つ以上使用しています  ja-technical-writing/max-ten

次に今回の文章を例外として ja-technical-writing/max-ten のエラーを無視する(許容する).以下のように textlint-filter-rule-comments のドキュメントに載っているコメント記法をそのまま追加する.

= サンプル

<!-- textlint-disable ja-technical-writing/max-ten -->

今日は、とても、良い、天気、です。

<!-- textlint-enable ja-technical-writing/max-ten -->

すると今度は <!-- の部分に ja-technical-writing/no-exclamation-question-mark のエラーが出てしまう.

$ npx textlint ./*.re

  3:2   error  Disallow to use "!"                    ja-technical-writing/no-exclamation-question-mark
  5:14  error  一つの文で""4つ以上使用しています  ja-technical-writing/max-ten
  7:2   error  Disallow to use "!"                    ja-technical-writing/no-exclamation-question-mark

今回は Markdown ファイルではなく Re:VIEW ファイルを対象にするため,コメント記法は <!-- ではなく #@# を使う必要がある.以下のように sample.re を修正したら textlint でエラーは出なくなった.

= サンプル

#@# textlint-disable ja-technical-writing/max-ten

今日は、とても、良い、天気、です。

#@# textlint-enable ja-technical-writing/max-ten

Re:VIEW のコメント記法に関しては以下のドキュメントに載っている.

github.com