• Stars
    star
    348
  • Rank 121,840 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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]

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)

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

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

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"

Deprecated

The following command behaves similarly, defaulting the fix property to true:

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

Otherwise, markdownlint-cli2-fix behaves the same as markdownlint-cli2.

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:

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.

Deprecated

The following command behaves similarly, accepting a base configuration file path as its first parameter:

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

Otherwise, markdownlint-cli2-config behaves the same as markdownlint-cli2.

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.8.1 "**/*.md" "#node_modules"

Notes:

  • As when using the command line, glob patterns are passed as arguments.
  • This image is built on the official Node.js Docker image. Per security best practices, the default user node runs with restricted permissions. If it is necessary to run as root, pass the -u root option when invoking docker.
  • By default, markdownlint-cli2 will execute within the /workdir directory inside the container. So, as shown above, bind mount the project's directory there.
    • A custom working directory can be specified with Docker's -w flag:

      docker run -w /myfolder -v $PWD:/myfolder davidanson/markdownlint-cli2:v0.8.1 "**/*.md" "#node_modules"

Deprecated

To invoke the markdownlint-cli2-config or markdownlint-cli2-fix commands instead, use Docker's --entrypoint flag:

docker run -v $PWD:/workdir --entrypoint="markdownlint-cli2-fix" davidanson/markdownlint-cli2:v0.8.1 "**/*.md" "#node_modules"

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

  • 0: Linting was successful and there were no errors
  • 1: Linting was successful and there were errors
  • 2: Linting was not completed due to a runtime issue

Rule List

Glob expressions

  • Globbing is performed by the globby library; refer to that documentation for more information and examples.

Configuration

  • See the Configuration section of the markdownlint documentation for information about the inline comment syntax for enabling and disabling rules with HTML comments.
  • In general, glob expressions should match files under the current directory; the configuration for that directory will apply to the entire tree.
    • When glob expressions match files not under the current directory, configuration for the current directory is applied to the closest common parent directory.
  • There are two kinds of configuration file (both detailed below):
    • Configuration files like .markdownlint-cli2.* allow complete control of markdownlint-cli2 behavior and are also used by vscode-markdownlint.
    • Configuration files like .markdownlint.* allow control over only the markdownlint config object and tend to be supported more broadly (such as by markdownlint-cli).
  • The VS Code extension vscode-markdownlint includes a schema definition for the JSON(C) configuration files described below. This adds auto-complete and can make it easier to define proper structure.

.markdownlint-cli2.jsonc

  • The format of this file is a JSONC object similar to the markdownlint options object.
  • Valid properties are:
    • config: markdownlint config object to configure rules for this part of the directory tree
      • If a .markdownlint.{jsonc,json,yaml,yml,js} file (see below) is present in the same directory, it overrides the value of this property
      • If the config object contains an extends property, it will be resolved the same as .markdownlint.{jsonc,json,yaml,yml,js} (see below)
    • customRules: Array of Strings (or Arrays of Strings) of module names/paths of custom rules to load and use when linting
    • fix: Boolean value to enable fixing of linting errors reported by rules that emit fix information
      • Fixes are made directly to the relevant file(s); no backup is created
    • frontMatter: String defining the RegExp used to match and ignore any front matter at the beginning of a document
      • The String is passed as the pattern parameter to the RegExp constructor
      • For example: (^---\s*$[^]*?^---\s*$)(\r\n|\r|\n|$)
    • globs: Array of Strings defining glob expressions to append to the command-line arguments
      • This setting can be used instead of (or in addition to) passing globs on the command-line and offers identical performance
      • This top-level setting is valid only in the directory from which markdownlint-cli2 is run
    • ignores: Array of Strings defining glob expressions to ignore when linting
      • This setting has the best performance when applied to the directory from which markdownlint-cli2 is run
        • In this case, glob expressions are negated (by adding a leading !) and appended to the command-line arguments before file enumeration
        • The setting is not inherited by nested configuration files in this case
      • When this setting is applied in subdirectories, ignoring of files is done after file enumeration, so large directories can negatively impact performance
        • Nested configuration files inherit and reapply the setting to the contents of nested directories in this case
    • markdownItPlugins: Array of Arrays, each of which has a String naming a markdown-it plugin followed by parameters
      • Plugins can be used to add support for additional Markdown syntax
      • Relative paths are resolved based on the location of the JSONC file
      • For example: [ [ "plugin-name", param_0, param_1, ... ], ... ]
      • Search markdown-it-plugins on npm
    • noInlineConfig: Boolean value to disable the support of HTML comments within Markdown content
      • For example: <!-- markdownlint-disable some-rule -->
    • noProgress: Boolean value to disable the display of progress on stdout
      • This top-level setting is valid only in the directory from which markdownlint-cli2 is run
    • outputFormatters: Array of Arrays, each of which has a String naming an output formatter followed by parameters
      • Formatters can be used to customize the tool's output for different scenarios
      • Relative paths are resolved based on the location of the JSONC file
      • For example: [ [ "formatter-name", param_0, param_1, ... ], ... ]
      • This top-level setting is valid only in the directory from which markdownlint-cli2 is run
      • Search markdownlint-cli2-formatter on npm
  • When referencing a module via the customRules, markdownItPlugins, or outputFormatters properties, each String identifier is passed to Node's require function then (if that failed) its import expression
    • Importing a locally-installed module using a bare specifier (ex: package-name) or using a directory name (ex: ./package-dir) will not work until import.meta.resolve is available
  • Settings in this file apply to the directory it is in and all subdirectories.
  • Settings merge with those applied by any versions of this file in a parent directory (up to the current directory).
  • For example: .markdownlint-cli2.jsonc with all properties set

.markdownlint-cli2.yaml

  • The format of this file is a YAML object with the structure described above for .markdownlint-cli2.jsonc.
  • Other details are the same as for .markdownlint-cli2.jsonc described above.
  • If a .markdownlint-cli2.jsonc file is present in the same directory, it takes precedence.
  • For example: .markdownlint-cli2.yaml with all properties set

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

  • The format of this file is a CommonJS module (.cjs) or ECMAScript module (.mjs) that exports the object described above for .markdownlint-cli2.jsonc.
  • Instead of passing a String to identify the module name/path to load for customRules, markdownItPlugins, and outputFormatters, the corresponding Object or Function can be provided directly.
  • Other details are the same as for .markdownlint-cli2.jsonc described above.
  • If a .markdownlint-cli2.jsonc or .markdownlint-cli2.yaml file is present in the same directory, it takes precedence; .markdownlint-cli2.cjs takes precedence over .markdownlint-cli2.mjs.
  • For example: .markdownlint-cli2.cjs or .markdownlint-cli2.mjs

.markdownlint.jsonc or .markdownlint.json

  • The format of this file is a JSONC or JSON object matching the markdownlint config object.
  • Settings in this file apply to the directory it is in and all subdirectories
  • Settings override those applied by any versions of this file in a parent directory (up to the current directory).
  • If jsonc and json files are present in the same directory, the jsonc version takes precedence.
  • To merge the settings of these files or share configuration, use the extends property (documented in the link above).
  • Both file types support comments in JSON.
  • For example: .markdownlint.jsonc

.markdownlint.yaml or .markdownlint.yml

  • The format of this file is a YAML object representing the markdownlint config object.
  • Other details are the same as for jsonc/json files described above.
  • If yaml and yml files are present in the same directory, the yaml version takes precedence.
  • If a jsonc or json file is present in the same directory, it takes precedence.
  • For example: .markdownlint.yaml

.markdownlint.cjs or .markdownlint.mjs

Compatibility

markdownlint-cli

  • The glob implementation and handling of pattern matching is slightly different.
  • Configuration files are supported in every directory (vs. only one at the root).
  • The INI config format, .markdownlintrc, and .markdownlintignore are not supported.

vscode-markdownlint

  • .markdownlintignore is not supported.

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.8.1
  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.

More Repositories

1

markdownlint

A Node.js style checker and lint tool for Markdown/CommonMark files.
JavaScript
4,770
star
2

vscode-markdownlint

Markdown linting and style checking for Visual Studio Code
JavaScript
934
star
3

ConvertTo-Jpeg

A PowerShell script that converts RAW (and other) image files to the widely-supported JPEG format
PowerShell
188
star
4

markdownlint-cli2-action

A GitHub Action to run the markdownlint-cli2 tool for linting Markdown/CommonMark files with the markdownlint library
JavaScript
92
star
5

DHCPLite

A small, simple, configuration-free DHCP server for Windows.
C++
52
star
6

ConvertTo-Heic

A PowerShell script that converts image files to the efficient HEIC format
PowerShell
47
star
7

PassWeb

A simple, secure, cloud-based password manager.
JavaScript
26
star
8

math-random-polyfill

A browser-based polyfill for JavaScript's Math.random() that tries to make it more random
JavaScript
23
star
9

live-photo-web

Live Photos via Web Components
JavaScript
19
star
10

Twitter-Alternatives

A Practical Comparison of Mastodon and Micro.blog
14
star
11

simple-website-with-blog

A simple website with a blog
JavaScript
13
star
12

update-ios-contact-images

A Scriptable (https://scriptable.app/) script to update Contact photos on iOS
JavaScript
12
star
13

check-pages

Checks various aspects of a web page for correctness.
JavaScript
11
star
14

grunt-check-pages

Grunt task that checks various aspects of a web page for correctness.
JavaScript
11
star
15

MouseButtonClicker

MouseButtonClicker clicks the mouse so you don't have to!
C++
10
star
16

StringExtractors

A collection of simple command-line utilities to extract strings and comments from source code
JavaScript
9
star
17

crc-hash

A Node.js Crypto Hash (Stream) implementation for the CRC algorithm.
JavaScript
6
star
18

azure-blob-container-download

A simple, cross-platform tool to bulk-download blobs from an Azure storage container.
JavaScript
5
star
19

CoLR

Camera of Last Resort - Possibly worse than no camera at all...
JavaScript
3
star
20

gruntMock

A simple mock for testing Grunt multi-tasks.
JavaScript
3
star
21

Workflows

Various Workflows for running GitHub Actions
JavaScript
3
star
22

check-pages-cli

Checks various aspects of a web page for correctness.
JavaScript
2
star
23

Utilities

Bits of code I use for stuff
JavaScript
2
star
24

Lenz

A simple, cross-platform app for reviewing photos and picking favorites.
JavaScript
2
star
25

tape-player

A simple, terse, in-process reporter for the tape test runner for Node.js.
JavaScript
2
star
26

SpellV

A simple app that makes it easy to spell-check with a browser.
JavaScript
1
star
27

generateRandomUUID

JavaScript code to efficiently generate a random (version 4) UUID per RFC 4122
HTML
1
star
28

promise-ring

Convenience methods for converting Node.js callbacks into native Promises.
JavaScript
1
star
29

npm-placeholder

This is a placeholder package to prevent name-squatting in the npm package registry.
1
star
30

markdownlint-analyze-config

Code to analyze markdownlint config in the wild
JavaScript
1
star
31

static-web-app

Source repository containing files of a static web app for experimentation and testing.
JavaScript
1
star