[Linter] remark-lint

2022-03-10 hit count image

Let's see how to use the remark-lint to make the same style of the Markdown.

Outline

When dvelopers write the Readme fiel or Wiki about the development, they frequently use the Markdown for them. In this blog post, I will introduce how to use remark-lint to check the style of the Markdown contents.

You can see the full source code of this blog post on the link below.

Install Node

To use the remark-lint, you need to install Node. Install Node for your system by following.

macOS

Homebrew is a package manager for macOS to install and manage packages. You can simple install packages with Homebrew. Execute the command below to install Homebrew.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

After installing, execute the following command to check Homebrew installed well.

brew --version

If the version is now shown up, exit Termital and restart it. If you already installed Homebrew, you can skip this step. Next, execute the command below to install Node.

brew install node

Windows

In Windows, Chocolatey is a package manager. Open the CMD or Powershell with Administrator privileges. Execute the command below to install Chocolatey.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

After installing, execute the following command to check Chocolatey installed well.

choco –version

If the version of Chocolatey is not shown up, exit CMD or Powershell and restart it. After installing Chocolatey, execute the command below to install Node.

choco install -y nodejs.install

Create package.json

The remark-lint works on the Node development environment. So, we need to create a package.json file to manage the node packages. Execute the command below to create the package.json file.

npm init

When you execute the command, you will see the following questoins. If you don’t have any modification, just press Enter to all questions.

package name: (remark-lint-example)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)

After it, you can see the package.json file created like the below.

{
  "name": "remark-lint-example",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Install remark-lint

Execute the command below to install remark-lint.

npm install --save-dev remark-cli remark-lint remark-preset-lint-recommended

Configure remark-lint

To use the remark-lint, open the package.json file and modify it like the below.

{
  ...
  "remarkConfig": {
    "plugins": [
      "remark-preset-lint-recommended",
      [
        "remark-lint-list-item-indent",
        "mixed"
      ]
    ]
  }
}

Create script

Next, let’s create the executable script of remark-lint. Open the package.json file and modify it like the below.

{
  ...
  "scripts": {
    "lint:md": "remark . --quiet --frail"
  },
  ...
}

Execute

To check the remark-lint works well, create a README.md file and modify it like the below.

test

Next, execute the following command to check the remark-lint works well.

npm run lint:md

If you install and configure the remark-lint well, you can see the following warning mesage.

README.md
  1:1  warning  Missing newline character at end of file  final-newline  remark-lint

Complated

Done! we’ve seen how to install the remark-lint and how to use it to check the style of the Markdown contents. I recommend you to use remark-lint to check your Markdown contents.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

Posts