Skip to content

avto-dev/markdown-lint

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

icon

Linter for markdown | with presets

Release Build Build Docker Pulls Issues License

This repository contains source files of docker image (and github action) for markdown files linting. Additionally we provides setting (rules) for the most useful cases, like changelog file linting.

All docker images always can be found on this page.

Usage

This image contains markdownlint-cli (node-js) and:

  • Additional rules for changelog file linting (/lint/rules/changelog.js)
  • Configuration file for changelog file linting (it uses additional linting rules, /lint/config/changelog.yml)

Major image tag can be updated in any time, but all changes will be backwards compatible.

markdownlint-cli supports next options (more details can be found on project page):

Usage: markdownlint [options] <files|directories|globs>

Options:
  -h, --help                                  output usage information
  -V, --version                               output the version number
  -f, --fix                                   fix basic errors (does not work with STDIN)
  -s, --stdin                                 read from STDIN (does not work with files)
  -o, --output [outputFile]                   write issues to file (no console)
  -c, --config [configFile]                   configuration file (JSON, JSONC, or YAML)
  -i, --ignore [file|directory|glob]          files to ignore/exclude
  -r, --rules  [file|directory|glob|package]  custom rule files

Environment variables

Some linter execution options can be passed through environment variables (multiple variables usage are allowed):

Environment variable Interpretation
INPUT_RULES=/foo.js markdownlint --rules /foo.js ...
INPUT_CONFIG=/bar.yml markdownlint --config /bar.yml ...
INPUT_FIX=true markdownlint --fix ...
INPUT_OUTPUT=/foo markdownlint --output /foo ...
INPUT_IGNORE=/bar markdownlint --ignore /bar ...

Docker

For example, you can lint your CHANGELOG.md file using following command:

$ docker run --rm \
    -v "$(pwd)/CHANGELOG.md:/CHANGELOG.md:ro" \
    avtodev/markdown-lint:v1 \
    --rules /lint/rules/changelog.js \
    --config /lint/config/changelog.yml \
    /CHANGELOG.md

or

$ docker run --rm \
    -v "$(pwd)/CHANGELOG.md:/CHANGELOG.md:ro" \
    -e INPUT_RULES=/lint/rules/changelog.js \
    -e INPUT_CONFIG=/lint/config/changelog.yml \
    avtodev/markdown-lint:v1 \
    /CHANGELOG.md

GitHub Actions

jobs:
  lint-changelog:
    name: Lint changelog file
    runs-on: ubuntu-latest
    steps:
    - name: Check out code
      uses: actions/checkout@v2

    - name: Lint changelog file
      uses: docker:https://avtodev/markdown-lint:v1 # fastest way
      with:
        rules: '/lint/rules/changelog.js'
        config: '/lint/config/changelog.yml'
        args: './CHANGELOG.md'
        ignore: './one_file.md ./another_file.md' # multiple files must be separated with single space

    # Or using current repository as action:

    - name: Lint changelog file
      uses: avto-dev/markdown-lint@v1
      with:
        rules: '/lint/rules/changelog.js'
        config: '/lint/config/changelog.yml'
        args: './CHANGELOG.md'

License

MIT. Use anywhere for your pleasure.