Skip to content

Latest commit

 

History

History
66 lines (51 loc) · 2.3 KB

OutputFormatters.md

File metadata and controls

66 lines (51 loc) · 2.3 KB

Output Formatters

markdownlint-cli2 lets you customize its output by specifying one or more output formatters in its configuration file. Output formatters can be defined by scripts within a project or imported from a package (keyword markdownlint-cli2-formatter on npm).

Authoring

Output formatters are called after linting is done and are passed arguments that include the results, logging functions, and formatter parameters. They are expected to return a Promise that resolves when output formatting is complete or void if execution completes synchronously.

Output formatters export a function like:

module.exports = (options, params) => { ... }

Where options is an object that looks like:

  • directory: String that identifies the base directory for relative paths (using POSIX syntax)
  • results: Array of markdownlint LintError objects, each with an added String property fileName containing a relative path
  • logMessage: Function that takes a single String argument and logs it to standard output
  • logError: Function that takes a single String argument and logs it to standard error

And params is an object containing formatter parameters from configuration.

For a .markdownlint-cli2.jsonc like:

{
  "outputFormatters": [
    [ "markdownlint-cli2-formatter-json", { "name": "custom-name.json", "spaces": 1 } ]
  ]
}

params would be:

{
  "name": "custom-name.json",
  "spaces": 1
}

Examples