iTranslated by AI
Proofreading Text with textlint
Introduction
I have been running a technical blog for a while now, and as the number of articles has increased, I have started to become concerned about inconsistencies in my writing style.
For example, should it be "コンピューター" (kompyūtā) or "コンピュータ" (kompyūta)?
While I was thinking about a good solution, I learned about textlint and decided to implement it.
What is textlint?
textlint is an open-source tool that automatically checks text and Markdown files, proofreading for grammar, inconsistent usage, and stylistic consistency. It supports a wide range of proofreading tasks through plugins and custom rules, and it can also be integrated into CI/CD pipelines and editors like VSCode.
It is commonly used in JavaScript and TypeScript projects.
textlint · The pluggable linting tool for text and markdown
How to get started
1. Install dependencies
First, install the necessary dependencies.
npm i -D textlint textlint-rule-preset-ja-spacing textlint-rule-preset-japanese textlint-rule-preset-ja-technical-writing
These include the core textlint package and the rule sets.
2. Create a configuration file
Create the configuration file.
npx textlint --init
Once .textlintrc.json is created, enable the rule sets.
{
"plugins": {},
"filters": {},
"rules": {
"preset-ja-technical-writing": true,
"preset-japanese": true,
"preset-ja-spacing": true
}
}
Once this is done, you can run textlint.
npx textlint ./README.md
If you see output like the following, it means it is working correctly.
/path/to/README.md
3:4 ✓ error 原則として、全角文字と半角文字の間にスペースを入れません。 ja-spacing/ja-space-between-half-and-full-width
✖ 5 problems (5 errors, 0 warnings)
✓ 4 fixable problems.
Try to run: $ textlint --fix [file]
3. Register in npm scripts
To run it in CI workflows, register it in the scripts section of your package.json.
The following command checks all Markdown files within the project using textlint.
{
"scripts": {
"textlint": "textlint './**/*.md'",
},
}
Now you can check all Markdown files by running npm run textlint.
✖ 1559 problems (1559 errors, 0 warnings)
✓ 938 fixable problems.
Try to run: $ textlint --fix [file]
This is the result I got when I ran it on my technical blog project. 1,559 errors...
4. VSCode extension
Install the VSCode extension.
textlint - Visual Studio Marketplace
Configure it for your workspace files as follows:
XXX.code-workspace.json
{
"settings": {
"textlint.configPath": "./path/to/.textlintrc.json",
"textlint.nodePath": "./path/to/node_modules",
"textlint.languages": [
"markdown"
]
}
}
Now, errors will be highlighted in red within VSCode.
Conclusion
Since I implemented textlint in a project that already contained many articles, I ended up with a mountain of errors and warnings. However, this has provided a foundation for writing with consistent style.
I plan to gradually resolve these errors and incorporate textlint into my build workflow.
I have summarized the knowledge I gained from developing at home every day for the past two and a half years! Please check it out if you'd like.
Discussion