Linting markdown files using Node.js

Install dependencies

# Yarn
yarn add -D markdownlint markdownlint-cli2

# NPM
npm install -D markdownlint markdownlint-cli2

Add script to your package.json

"lint:md": "markdownlint-cli2 README.md"

Feel free to replace README.md with any files/globs that you want to lint

Using it with Prettier

Install dependencies

# Yarn
yarn add -D prettier

# NPM
npm install -D prettier

Update your script

"lint:md": "prettier --check README.md && markdownlint-cli2 README.md"

If you have long lines then you might find that Prettier doesn’t error, but markdownlint does. You can either disable line-height rule in markdown lint or enable prose-wrap in your Prettier configuration. You can do this by adding the following part to your package.json

"prettier": {
  "proseWrap": "always"
},

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s