Skip to content

lint-md/github-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

@lint-md/github-action

CI license GitHub release

lint-md 提供的 GitHub Action 集成,无需在 CI 中额外执行 npm install,开箱即用,速度更快。

lint-md 是一款面向中文技术文档的 Markdown 格式检查工具,可检测空格、标点、排版等常见问题。本 Action 将其封装为可直接在 GitHub Actions 工作流中使用的步骤。

快速开始

在仓库中创建工作流文件,例如 .github/workflows/lint-md.yml

name: Lint Markdown

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  lint-markdown:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6.0.2

      - name: Lint Markdown
        uses: lint-md/github-action@v0.2.0

这会使用默认规则检查当前目录下的所有 Markdown 文件。

配置参数

参数名 类型 默认值 必填 说明
files string ./ 要检查的目录或文件路径,多个路径之间用空格分隔,例如:./docs ./README.md
configFile string .lintmdrc lint-md 配置文件路径,支持 JSON 文件或 JavaScript 模块(.lintmdrc / .lintmdrc.js
failOnWarnings boolean false 是否在出现警告(warning)时也使 Action 失败

检查多个目录

- name: Lint Markdown
  uses: lint-md/github-action@v0.2.0
  with:
    files: './docs ./src ./README.md'

指定自定义配置文件

- name: Lint Markdown
  uses: lint-md/github-action@v0.2.0
  with:
    configFile: './config/.lintmdrc'

警告也视为失败

- name: Lint Markdown
  uses: lint-md/github-action@v0.2.0
  with:
    failOnWarnings: 'true'

配置文件

若工作目录下存在配置文件,Action 会自动读取并应用其中的规则;若不存在,则使用默认规则。

JSON 格式(.lintmdrc

{
  "excludeFiles": ["**/node_modules/**", "**/dist/**"],
  "rules": {
    "space-around-alphabet": 1,
    "space-around-number": 1,
    "no-empty-code-lang": 2,
    "no-trailing-punctuation": 2
  }
}

JavaScript 模块格式(.lintmdrc.js

module.exports = {
  excludeFiles: ['**/node_modules/**'],
  rules: {
    "space-around-alphabet": 1,
    "space-around-number": 1,
    "no-empty-code-lang": 2,
    "no-trailing-punctuation": 2
  }
}

配置项说明

字段 类型 默认值 说明
excludeFiles string[] ["**/node_modules/**", "**/.git/**"] 排除的文件 glob 模式
rules object {} 规则配置,见下方规则列表

规则值含义

  • 0 — 关闭规则
  • 1 — 作为警告(不影响退出码,除非 failOnWarnings: 'true'
  • 2 — 作为错误(会使 Action 失败)

可用规则

规则名 说明
space-around-alphabet 中英文之间需要添加空格
space-around-number 中文与数字之间需要添加空格
no-empty-list 禁止空列表项
no-empty-code 禁止空代码块
no-empty-code-lang 代码块必须指定语言
no-empty-inline-code 禁止空行内代码
no-empty-url 禁止空链接
no-empty-blockquote 禁止空引用
no-full-width-number 禁止全角数字
no-half-width-punctuation 禁止半角标点
no-long-code 代码块不能过长
no-multiple-space-blockquote 引用块不能有多个空格
no-space-in-inline-code 行内代码前后不能有空格
no-space-in-link 链接文字前后不能有空格
no-special-characters 禁止特殊字符
use-standard-ellipsis 使用标准省略号
correct-title-trailing-punctuation 标题结尾标点符号检查

完整规则列表请参考 lint-md 文档

示例:完整配置

name: Lint Markdown

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  lint-markdown:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v6.0.2

      - name: Lint Markdown
        uses: lint-md/github-action@v0.2.0
        with:
          files: './docs ./README.md'
          configFile: '.lintmdrc'
          failOnWarnings: 'false'

License

MIT © Jim Yu

About

⚡ 基于 @lint-md 的 GitHub Action 封装,持续集成更方便,速度更快。

Topics

Resources

License

Stars

8 stars

Watchers

1 watching

Forks

Contributors