lint-md-cli

0.1.2 • Public • Published

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.

Dependencies (6)

Dev Dependencies (9)

Package Sidebar

Install

npm i lint-md-cli

Weekly Downloads

181

Version

0.1.2

License

MIT

Unpacked Size

20.8 kB

Total Files

10

Last publish

Collaborators

  • atool