Text linting is much less common than code linting, but if you have to maintain a lot of text it may save you a lot of time, and improve quality of your documentation.
Text linting is less common than code linting but in large projects with many contributors it could improve documentation quality. You can:
Textlint is an extendable text linter written in JavaScript, it’s a fork of ESLint so setup is similar. And like ESLint it can fix certain rules for you. It has many plugins:
Proselint is prose linter following the advice of world’s greatest writers and editors, it checks your texts for things like redundancy, jargon, illogic, clichés, sexism, misspelling, inconsistency and misuse of symbols. It has several dozens of rules by default.
It’s written in Python but we recommend using it via a JavaScript wrapper for better UI.
To check Markdown syntax and consistency, try remark-lint.
Let’s install Textlint with several rules:
npm install --save-dev textlint textlint-rule-terminology textlint-rule-common-misspellings textlint-rule-write-good textlint-rule-no-dead-link
Add a script to your package.json like this:
{
"scripts": {
"lint:text": "textlint '**/*.md'"
}
}
Create a config file, .textlintrc
:
{
"rules": {
"terminology": true,
"common-misspellings": true,
"write-good": {
"adverb": false,
"passive": false,
"tooWordy": false,
"weasel": false
},
"no-dead-link": true
}
}
And finally run:
npm run lint:text
You can run Textlint with autofixing like this: npm run lint:text -- --fix
. Don’t forget to commit your texts first because autofixing may introduce changes you don’t want to keep.
Let’s install Proselint:
pip install proselint
npm install --save-dev proselint
Add a script to your package.json like this:
{
"scripts": {
"lint:prose": "proselintjs '**/*.md'"
}
}
And finally run:
npm run lint:prose
We’re discussed Prettier in great detail in the Code Formatting chapter but it can do more. It can format your Markdown files, and not only text but also code example for languages it supports: JavaScript, TypeScript, CSS, Less, SCSS, JSON, GraphQL, and Markdown.
Let’s install Prettier:
npm install --save-dev prettier
Add a script to your package.json like this:
{
"scripts": {
"prettier": "prettier --write '**/*.md'"
}
}
Create a config file, .prettierrc
:
{
"printWidth": 68,
"singleQuote": true,
"trailingComma": "es5",
"proseWrap": "never"
}
If you’re using Prettier to format your code, you may want to define different rules for code inside Markdown files:
{
"printWidth": 100,
"singleQuote": true,
"trailingComma": "es5",
"useTabs": true,
"proseWrap": "never",
"overrides": [
{
"files": "*.md",
"options": {
"printWidth": 68,
"useTabs": false,
"trailingComma": "none"
}
}
]
}
And finally run:
npm run prettier
Documentation linting is as important as code linting: it helps you to improve quality, find mistakes and keep formatting consistent.
This book is available through Leanpub. By purchasing the book you support the development of further content.