中文 Markdown 編寫格式規範的命令行工具 lint-md

lint-md

用於檢查中文 markdown 編寫格式規範的命令行工具,基於 AST 開發,且方便集成 ci。Cli tool to lint your markdown file for Chinese.

Build Status
Coverage Status
npm
npm

安裝

npm i -g lint-md

使用

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
  -h, --help                     output usage information

Example:node

lint-md README.md Document.md

檢查類型

檢查規則來源於 chinese-document-style-guide.
規則 詳細描述 解決辦法
space-round-alphabet 中文與英文之間須要增長空格 對應提示的位置增長空格
space-round-number 中文與數字之間須要增長空格 對應提示的位置增長空格
no-empty-code-lang 代碼語言不能爲空 在代碼塊語法上增長語言
no-empty-url 連接和圖片地址不能爲空 填寫完整的 url,或者不使用連接和圖片語法
no-empty-list List 內容不能爲空 List 語法中,填寫內容
no-empty-code 代碼塊內容不能爲空 刪除空的代碼塊,或者填充代碼內容
no-empty-blockquote blockquote 內容不能爲空 刪除空的 blockquote,或者填充內容
no-special-characters 文本中不能有特殊字符 多是複製出來的特殊字符,刪除特殊字符便可
use-standard-ellipsis 使用標準規範的省略號 使用標準規範的省略號‘……’ / ‘...’
no-fullwidth-number 不能用全角數字 注意輸入法切換爲半角輸入
no-space-in-emphasis emphasis 內容先後不能有空格 刪除 emphasis 內容中的先後空格便可
no-space-in-link link 內容先後不能有空格 刪除 link 內容中的先後空格便可
no-multiple-space-blockquote blockquote 語法不能包含有多個空格 刪除 blockquote 內容中多餘的空格
no-trailing-punctuation 標題不能以標點符號結尾 刪除標題最後的標點符號
目前僅僅檢查了比較通用的類型, 歡迎 pull request,在 rules 中增長本身的規則,開發約束:
  • 規則主要針對於中文 markdown 的編寫規範
  • 使用類 babel plugin 的方式來進行規則檢查,一個插件對應一個規則
  • 規則名稱對應和插件文件名保持一致
  • 先提 issue 進行討論
  • AST 工具,使用其中的 markdown AST 輔助開發插件

配置

默認全部的規則都是 error 類型,可是能夠經過配置來指定規則類型。示例 .lintmdrcgit

{
  "excludeFiles": [],
  "rules": {
    "no-empty-code": 1
  }
}

經過 rules 來配置規則的等級。github

  • 0:ignore 忽略不檢查該規則
  • 1:warning 警告,但不阻斷 ci
  • 2:error 錯誤,且阻斷 ci

經過 excludeFiles 來忽略文件和目錄,glob 語法。npm

ci 集成

  • Travis
.travis.yml 文件中配置如下內容。
language: node_js
node_js:
  - "10"
before_install:
  - npm i -g lint-md
script: lint-md README.md
  • lint-stage
package.json 中增長如下配置。
"lint-staged": {
  "src/**/*.{md,markdown}": [
    "lind-md"
  ]
}

License

MIT@hustcc.json

相關文章
相關標籤/搜索