OREMATOPEE

プログラミング、気になったこと、メモ書き...etc

coc.nvimでMarkdownをlintする

Notionを整理していたら結構前に書いていたものが見つかったのでポスト。
ほぼ参考記事のとおりなので、詳しくはそちらを見てもらえたらと思います。

参考記事

coc.vim で textlint する話 - げっとシステムログ
coc.nvimでtextlintを使う

前提

  • goコマンドが使えること

1. efm-langserverをインストール

概要

mattn/efm-langserver

特定のコマンドから生成されるエラーメッセージに特化したLanguage Server

以下の場合、導入する利点がある。

  • 言語のLSが存在しないが、Linterは存在する場合
  • LSはあるが、Linterを使いたい場合

今回MarkdownのLinterを使用するので、efm-langserverを使ってLS化を行う。

インストール手順

  1. インストールコマンドを実行
go get [github.com/mattn/efm-langserver](http://github.com/mattn/efm-langserver)

これでインストールできるが、実際は /go/bin以下にツールをコンパイルするだけのもの。
コンパイルされたツールは任意のパスに移動できる。 /go/binにパスを通してもよい。

  1. coc-settings.jsonにefm-langserverの設定を追加
{
  "languageserver": {
    "efm": {
      "command": "efm-langserver",
      "args": [],
      "filetypes": ["markdown"]
    }
  }
}
  1. efm-langserverのコンフィグを設定

$HOME/.config/efm-langserver/config.yaml に設定を追加

version: 2
root-markers:
  - .git/

tools:
  textlint: &textlint
    lint-command: 'yarn run textlint --format unix --stdin --stdin-filename ${INPUT}'
    lint-ignore-exit-code: true
    lint-stdin: true
    lint-formats:
      - '%f:%l:%c: %m [%trror/%r]'
    root-markers:
      - .textlintrc

languages:
  markdown:
    - <<: *textlint

2. textlintとルールプリセットをインストール

概要

textlint/textlint

校正ツール
ルールを追加、定義することによって実行対象の文章の問題点を指摘してくれる。

textlint-ja/textlint-rule-preset-ja-technical-writing
textlint-ja/textlint-rule-max-ten
azu/textlint-rule-spellcheck-tech-word
textlint-ja/textlint-rule-no-mix-dearu-desumasu

textlintルールプリセット

インストール手順

  1. インストールコマンドを実行
yarn add textlint
yarn add textlint-rule-preset-ja-technical-writing textlint-rule-max-ten textlint-rule-spellcheck-tech-word textlint-rule-no-mix-dearu-desumasu

上記はグローバルインストールではないことに注意

  1. textlintのコンフィグを設定

$HOME/.textlintrcに設定を追加

{
  "rules": {
    "preset-ja-technical-writing": true,
        "max-ten": {
      "max": 3
      },
        "spellcheck-tech-word": true,
        "no-mix-dearu-desumasu": true
  }
}