Home

Awesome

markdownlint-cli2

A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the markdownlint library

npm version License

Install

As a global CLI:

npm install markdownlint-cli2 --global

As a development dependency of the current Node.js package:

npm install markdownlint-cli2 --save-dev

As a Docker container image:

docker pull davidanson/markdownlint-cli2

As a global CLI with Homebrew:

brew install markdownlint-cli2

As a GitHub Action via markdownlint-cli2-action:

- name: markdownlint-cli2-action
  uses: DavidAnson/markdownlint-cli2-action@v9

Overview

Use

Command Line

markdownlint-cli2 vX.Y.Z (markdownlint vX.Y.Z)
https://github.com/DavidAnson/markdownlint-cli2

Syntax: markdownlint-cli2 glob0 [glob1] [...] [globN] [--config file] [--fix] [--help]

Glob expressions (from the globby library):
- * matches any number of characters, but not /
- ? matches a single character, but not /
- ** matches any number of characters, including /
- {} allows for a comma-separated list of "or" expressions
- ! or # at the beginning of a pattern negate the match
- : at the beginning identifies a literal file path

Dot-only glob:
- The command "markdownlint-cli2 ." would lint every file in the current directory tree which is probably not intended
- Instead, it is mapped to "markdownlint-cli2 *.{md,markdown}" which lints all Markdown files in the current directory
- To lint every file in the current directory tree, the command "markdownlint-cli2 **" can be used instead

Optional parameters:
- --config    specifies the path to a configuration file to define the base configuration
- --fix       updates files to resolve fixable issues (can be overridden in configuration)
- --help      writes this message to the console and exits without doing anything else
- --no-globs  ignores the "globs" property if present in the top-level options object

Configuration via:
- .markdownlint-cli2.jsonc
- .markdownlint-cli2.yaml
- .markdownlint-cli2.cjs or .markdownlint-cli2.mjs
- .markdownlint.jsonc or .markdownlint.json
- .markdownlint.yaml or .markdownlint.yml
- .markdownlint.cjs or .markdownlint.mjs
- package.json

Cross-platform compatibility:
- UNIX and Windows shells expand globs according to different rules; quoting arguments is recommended
- Some Windows shells don't handle single-quoted (') arguments well; double-quote (") is recommended
- Shells that expand globs do not support negated patterns (!node_modules); quoting is required here
- Some UNIX shells parse exclamation (!) in double-quotes; hashtag (#) is recommended in these cases
- The path separator is forward slash (/) on all platforms; backslash (\) is automatically converted
- On any platform, passing the parameter "--" causes all remaining parameters to be treated literally

The most compatible syntax for cross-platform support:
$ markdownlint-cli2 "**/*.md" "#node_modules"

For scenarios where it is preferable to specify glob expressions in a configuration file, the globs property of .markdownlint-cli2.jsonc, .yaml, .cjs, or .mjs may be used instead of (or in addition to) passing glob0 ... globN on the command-line.

As shown above, a typical command-line for markdownlint-cli2 looks something like:

markdownlint-cli2 "**/*.md" "#node_modules"

Because sharing the same configuration between "normal" and "fix" modes is common, the --fix argument can be used to default the fix property (see below) to true (though it can still be overridden by a configuration file):

markdownlint-cli2 --fix "**/*.md" "#node_modules"

In cases where it is not convenient to store a configuration file in the root of a project, the --config argument can be used to provide a path to any supported configuration file (except package.json):

markdownlint-cli2 --config "config/.markdownlint-cli2.jsonc" "**/*.md" "#node_modules"

The configuration file name must be (or end with) one of the supported names above. For example, .markdownlint.json or example.markdownlint-cli2.jsonc. The specified configuration file will be loaded, parsed, and applied as a base configuration for the current directory - which will then be handled normally.

Container Image

A container image davidanson/markdownlint-cli2 can also be used (e.g., as part of a CI pipeline):

docker run -v $PWD:/workdir davidanson/markdownlint-cli2:v0.14.0 "**/*.md" "#node_modules"

Notes:

For convenience, the container image davidanson/markdownlint-cli2-rules includes the latest versions of custom rules published to npm with the tag markdownlint-rule. These rules are installed globally onto the base image davidanson/markdownlint-cli2.

Note: This container image exists for convenience and is not an endorsement of the rules within.

Exit Codes

Rule List

Glob expressions

Configuration

.markdownlint-cli2.jsonc

.markdownlint-cli2.yaml

.markdownlint-cli2.cjs or .markdownlint-cli2.mjs

package.json

.markdownlint.jsonc or .markdownlint.json

.markdownlint.yaml or .markdownlint.yml

.markdownlint.cjs or .markdownlint.mjs

Compatibility

markdownlint-cli

vscode-markdownlint

pre-commit

To run markdownlint-cli2 as part of a pre-commit workflow, add a reference to the repos list in that project's .pre-commit-config.yaml like:

- repo: https://github.com/DavidAnson/markdownlint-cli2
  rev: v0.14.0
  hooks:
  - id: markdownlint-cli2

Depending on the environment that workflow runs in, it may be necessary to override the version of Node.js used by pre-commit.

History

See CHANGELOG.md.