1. lint-md-cli
Cli tool to lint your markdown file for Chinese.
lint-md-cli
Package: lint-md-cli
Created by: hustcc
Last modified: Sun, 08 May 2022 02:05:25 GMT
Version: 0.1.2
License: MIT
Downloads: 397
Repository: https://github.com/hustcc/lint-md

Install

npm install lint-md-cli
yarn add lint-md-cli

lint-md-cli

用于检查中文 markdown 编写格式规范的命令行工具,基于 AST 开发,且方便集成 ci;同时提供 API 方法调用。Cli tool to lint your markdown file for Chinese.

npm
npm

安装

npm i -g lint-md-cli

使用

 Usage: <lint-md> <files...> [options]

lint your markdown files

Options:
  -v, --version                  output the version number
  -c, --config [configure-file]  use the configure file, default .lintmdrc
  -f, --fix                      fix the errors automatically
  -h, --help                     output usage information
  • 校验 lint
 lint-md README.md Document.md
  • 修复 fix
 lint-md README.md Document.md --fix

检查类型

基于 lint-md,具体支持的检查类型,请到该项目查看。

配置

默认所有的规则都是 error 类型,但是可以通过配置来指定规则类型。示例 .lintmdrc

 {
  "excludeFiles": [],
  "rules": {
    "no-empty-code": 1,
    "no-long-code": [2, {
      "length": 100,
      "exclude": ["dot"]
    }]
  }
}
  • 通过 rules 来配置规则。参考 lint-md 文档说明。
  • 通过 excludeFiles 来忽略文件和目录,glob 语法。

ci 集成

  • Travis

.travis.yml 文件中配置以下内容。

 language: node_js
node_js:
  - "10"
before_install:
  - npm i -g lint-md-cli
script: lint-md README.md
  • lint-stage

package.json 中增加以下配置。

 "lint-staged": {
  "src/**/*.{md,markdown}": [
    "lint-md"
  ]
}

基于 Docker

假设当前目录有一文件名为 README.md,可在本地使用以下命令:

 docker run --rm -it -v$(pwd):/docs yuque/lint-md:cli /docs/README.md # 也可直接带其它参数

其中:

  • --rm 表示在运行完毕后直接销毁容器。
  • -it 表示交互式 TTY,你可以理解为进入容器终端。
  • -v$(pwd)/docs 表示将当前目录「挂载」至容器内部的 /docs 目录。

另外,在基于 Docker 的 CI/CD 平台上,也可使用 yuque/lint-md 镜像。例如 GitLab CI/CD:

 lint:
  image: yuque/lint-md:cli
  script:
    - lint-md README.md # 或其它文件

Circle CI:

 version: 2
jobs:
  lint:
    docker:
      - image: yuque/lint-md:cli
    steps:
      - checkout
      - run: lint-md README.md # 或其它文件

利用 Docker 作为 CI 的基础环境通常更有优势,不必每次构建都执行 yarn install;资源节省,速度也会更快些。

License

MIT@hustcc.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin