textlintを安易にmason.nvimでインストールするべきではない
結論
- Textlintを安易にmason.nvimでインストールしようとしない
些末な話。
行き当たった問題
NeovimのLinterやFormatterをMason.nvimでインストールしている勢は多いと思う。
わたしもその一人だが、Textlintにおいては地味に引っかかる罠がある。
Ruleに使用しているモジュールが見つからないというエラーが出るのだ。
FAQによると、TextlintとRuleで使用されるモジュールは同じ場所にインストールされている必要があるとのこと。
Maybe, you have installed textlint and rules into different place.
- If you have installed textlint as --global(-g), must install each rule as --global.
- If you have installed textlint as --save-dev(-D), must install each rule as --save-dev.
この問題はmason.nvimの作者も認識しており、mason.nvimは現状サポートしていないと名言している。
NB: Textlint seems to take have a very plugin-centric approach, meaning if you want to use plugins with textlint you'll have to install them in the same location. This is something that Mason doesn't support nicely at the moment.
どう解決したか
Textlintはそれを使うプロジェクトのLocalにRuleと併せてインストールすることにした。
$ npm install --save-dev textlint textlint-rule-preset-ja-technical-writing
GlobalにInstallしても良いが、Ruleの設定がプロジェクトに依ることを考えれば、
各プロジェクトの package.json
に必要な依存モジュールが明示されている方が分かり易いと考えた。
何が起きたのか
null-lsから下記のようなエラーが出るのである。
failed to decode json: Expected value but found invalid token at character 2
これはtextlintの出力がおかしい状態なので、実際にシェルから叩いてみる。
$ textlint --debug ./foo.md
textlint:cli cliOptions: {"debug":true,"ignorePath":"/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/.textlintignore","init":false,"stdin":false,"format":"stylish","color":true,"quiet":false,"textlintrc":true,"cache":false,"cacheLocation":"/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/.textlintcache","_":["./foo.md"]} +0ms
textlint:cli textlint --version: 13.3.0 +0ms
textlint:cli Running on files, stdin-filename: undefined +0ms
textlint:cli cliDescriptor: {"rule":[],"filterRule":[],"plugin":[]} +1ms
textlint:loader:TextlintrcLoader loadTextlintrc failed: { ok: false, configFilePath: '/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/.textlintrc.json', error: { message: 'Can not load rule', errors: [ ReferenceError: Failed to load textlint's preset module: "preset-ja-technical-writing" is not found. See FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md at TextLintModuleResolver.resolvePresetPackageName (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/textlint-module-resolver.js:188:15) at loadPreset (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/loader.js:211:46) at /home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/loader.js:161:49 at Array.map (<anonymous>) at loadRules (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/loader.js:142:51) at loadPackagesFromRawConfig (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/config-loader.js:19:64) at loadConfig (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/config-loader.js:83:64) at async loadTextlintrc (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/textlint/lib/src/loader/TextlintrcLoader.js:36:20) at async loadDescriptor (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/textlint/lib/src/cli.js:27:11) at async Object.executeWithOptions (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/textlint/lib/src/cli.js:111:28), ReferenceError: Failed to load textlint's preset module: "preset-jtf-style" is not found. See FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md at TextLintModuleResolver.resolvePresetPackageName (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/textlint-module-resolver.js:188:15) at loadPreset (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/loader.js:211:46) at /home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/loader.js:161:49 at Array.map (<anonymous>) at loadRules (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/loader.js:142:51) at loadPackagesFromRawConfig (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/config-loader.js:19:64) at loadConfig (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/@textlint/config-loader/lib/src/config-loader.js:83:64) at async loadTextlintrc (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/textlint/lib/src/loader/TextlintrcLoader.js:36:20) at async loadDescriptor (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/textlint/lib/src/cli.js:27:11) at async Object.executeWithOptions (/home/kyoh86/Projects/github.com/kyoh86/zenn-dev/node_modules/textlint/lib/src/cli.js:111:28) ] } } +0ms
textlint:cli textlintrcDescriptor: {"rule":[],"filterRule":[],"plugin":[{"id":"@textlint/textlint-plugin-text","options":{}},{"id":"@textlint/textlint-plugin-markdown","options":{}}]} +4ms
textlint:cli mergedDescriptor: {"rule":[],"filterRule":[],"plugin":[{"id":"@textlint/textlint-plugin-text","options":{}},{"id":"@textlint/textlint-plugin-markdown","options":{}}]} +0ms
== No rules found, textlint hasn’t done anything ==
Possible reasons:
* Your textlint config file has no rules.
* You have no config file and you aren’t passing rules via command line.
* Your textlint config has a syntax error.
=> How to set up rules?
https://github.com/textlint/textlint/blob/master/docs/configuring.md
何やらおかしなエラーが出ている。
ReferenceError: Failed to load textlint's preset module: "preset-ja-technical-writing" is not found.
See FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md
at ...
ReferenceError: Failed to load textlint's preset module: "preset-jtf-style" is not found.
See FAQ: https://github.com/textlint/textlint/blob/master/docs/faq/failed-to-load-textlints-module.md
at ...
このFAQIssueに、先の案内が書かれている。
Maybe, you have installed textlint and rules into different place.
- If you have installed textlint as --global(-g), must install each rule as --global.
- If you have installed textlint as --save-dev(-D), must install each rule as --save-dev.
Discussion