Coder Social home page Coder Social logo

markdownlint's Introduction

markdownlint

A Node.js style checker and lint tool for Markdown/CommonMark files.

npm version License

Install

npm install markdownlint --save-dev

Overview

The Markdown markup language is designed to be easy to read, write, and understand. It succeeds - and its flexibility is both a benefit and a drawback. Many styles are possible, so formatting can be inconsistent. Some constructs don't work well in all parsers and should be avoided. The CommonMark specification standardizes parsers - but not authors.

markdownlint is a static analysis tool for Node.js with a library of rules to enforce standards and consistency for Markdown files. It was inspired by - and heavily influenced by - Mark Harrison's markdownlint for Ruby. The initial rules, rule documentation, and test cases came directly from that project.

Related

References

The following specifications are considered authoritative in cases of ambiguity:

Demonstration

markdownlint demo, an interactive, in-browser playground for learning and exploring.

Rules / Aliases

  • MD001 heading-increment - Heading levels should only increment by one level at a time
  • MD003 heading-style - Heading style
  • MD004 ul-style - Unordered list style
  • MD005 list-indent - Inconsistent indentation for list items at the same level
  • MD007 ul-indent - Unordered list indentation
  • MD009 no-trailing-spaces - Trailing spaces
  • MD010 no-hard-tabs - Hard tabs
  • MD011 no-reversed-links - Reversed link syntax
  • MD012 no-multiple-blanks - Multiple consecutive blank lines
  • MD013 line-length - Line length
  • MD014 commands-show-output - Dollar signs used before commands without showing output
  • MD018 no-missing-space-atx - No space after hash on atx style heading
  • MD019 no-multiple-space-atx - Multiple spaces after hash on atx style heading
  • MD020 no-missing-space-closed-atx - No space inside hashes on closed atx style heading
  • MD021 no-multiple-space-closed-atx - Multiple spaces inside hashes on closed atx style heading
  • MD022 blanks-around-headings - Headings should be surrounded by blank lines
  • MD023 heading-start-left - Headings must start at the beginning of the line
  • MD024 no-duplicate-heading - Multiple headings with the same content
  • MD025 single-title/single-h1 - Multiple top-level headings in the same document
  • MD026 no-trailing-punctuation - Trailing punctuation in heading
  • MD027 no-multiple-space-blockquote - Multiple spaces after blockquote symbol
  • MD028 no-blanks-blockquote - Blank line inside blockquote
  • MD029 ol-prefix - Ordered list item prefix
  • MD030 list-marker-space - Spaces after list markers
  • MD031 blanks-around-fences - Fenced code blocks should be surrounded by blank lines
  • MD032 blanks-around-lists - Lists should be surrounded by blank lines
  • MD033 no-inline-html - Inline HTML
  • MD034 no-bare-urls - Bare URL used
  • MD035 hr-style - Horizontal rule style
  • MD036 no-emphasis-as-heading - Emphasis used instead of a heading
  • MD037 no-space-in-emphasis - Spaces inside emphasis markers
  • MD038 no-space-in-code - Spaces inside code span elements
  • MD039 no-space-in-links - Spaces inside link text
  • MD040 fenced-code-language - Fenced code blocks should have a language specified
  • MD041 first-line-heading/first-line-h1 - First line in a file should be a top-level heading
  • MD042 no-empty-links - No empty links
  • MD043 required-headings - Required heading structure
  • MD044 proper-names - Proper names should have the correct capitalization
  • MD045 no-alt-text - Images should have alternate text (alt text)
  • MD046 code-block-style - Code block style
  • MD047 single-trailing-newline - Files should end with a single newline character
  • MD048 code-fence-style - Code fence style
  • MD049 emphasis-style - Emphasis style
  • MD050 strong-style - Strong style
  • MD051 link-fragments - Link fragments should be valid
  • MD052 reference-links-images - Reference links and images should use a label that is defined
  • MD053 link-image-reference-definitions - Link and image reference definitions should be needed
  • MD054 link-image-style - Link and image style
  • MD055 table-pipe-style - Table pipe style
  • MD056 table-column-count - Table column count

See Rules.md for more details.

Custom Rules

In addition to built-in rules, custom rules can be used to address project-specific requirements. To find community-developed rules use keyword markdownlint-rule on npm. To implement your own rules, refer to CustomRules.md.

Tags

Tags group related rules and can be used to enable/disable multiple rules at once.

  • accessibility - MD045
  • atx - MD018, MD019
  • atx_closed - MD020, MD021
  • blank_lines - MD012, MD022, MD031, MD032, MD047
  • blockquote - MD027, MD028
  • bullet - MD004, MD005, MD007, MD032
  • code - MD014, MD031, MD038, MD040, MD046, MD048
  • emphasis - MD036, MD037, MD049, MD050
  • hard_tab - MD010
  • headings - MD001, MD003, MD018, MD019, MD020, MD021, MD022, MD023, MD024, MD025, MD026, MD036, MD041, MD043
  • hr - MD035
  • html - MD033
  • images - MD045, MD052, MD053, MD054
  • indentation - MD005, MD007, MD027
  • language - MD040
  • line_length - MD013
  • links - MD011, MD034, MD039, MD042, MD051, MD052, MD053, MD054
  • ol - MD029, MD030, MD032
  • spaces - MD018, MD019, MD020, MD021, MD023
  • spelling - MD044
  • table - MD055, MD056
  • ul - MD004, MD005, MD007, MD030, MD032
  • url - MD034
  • whitespace - MD009, MD010, MD012, MD027, MD028, MD030, MD037, MD038, MD039

Configuration

Text passed to markdownlint is parsed as Markdown, analyzed, and any issues reported. Two kinds of text are ignored by most rules:

Rules can be enabled, disabled, and configured via options.config (described below) to define the expected behavior for a set of inputs. To enable or disable rules at a particular location within a file, add one of these markers to the appropriate place (HTML comments don't appear in the final markup):

  • Disable all rules: <!-- markdownlint-disable -->
  • Enable all rules: <!-- markdownlint-enable -->
  • Disable all rules for the current line: <!-- markdownlint-disable-line -->
  • Disable all rules for the next line: <!-- markdownlint-disable-next-line -->
  • Disable one or more rules by name: <!-- markdownlint-disable MD001 MD005 -->
  • Enable one or more rules by name: <!-- markdownlint-enable MD001 MD005 -->
  • Disable one or more rules by name for the current line: <!-- markdownlint-disable-line MD001 MD005 -->
  • Disable one or more rules by name for the next line: <!-- markdownlint-disable-next-line MD001 MD005 -->
  • Capture the current rule configuration: <!-- markdownlint-capture -->
  • Restore the captured rule configuration: <!-- markdownlint-restore -->

For example:

<!-- markdownlint-disable-next-line no-space-in-emphasis -->
space * in * emphasis

Or:

space * in * emphasis <!-- markdownlint-disable-line no-space-in-emphasis -->

Or:

<!-- markdownlint-disable no-space-in-emphasis -->
space * in * emphasis
<!-- markdownlint-enable no-space-in-emphasis -->

To temporarily disable rule(s), then restore the former configuration:

<!-- markdownlint-capture -->
<!-- markdownlint-disable -->
any violations you want
<!-- markdownlint-restore -->

The initial configuration is captured by default (as if every document began with <!-- markdownlint-capture -->), so the pattern above can be expressed more simply:

<!-- markdownlint-disable -->
any violations you want
<!-- markdownlint-restore -->

Changes take effect starting with the line a comment is on, so the following has no effect:

space * in * emphasis <!-- markdownlint-disable --> <!-- markdownlint-enable -->

To apply changes to an entire file regardless of where the comment is located, the following syntax is supported:

  • Disable all rules: <!-- markdownlint-disable-file -->
  • Enable all rules: <!-- markdownlint-enable-file -->
  • Disable one or more rules by name: <!-- markdownlint-disable-file MD001 -->
  • Enable one or more rules by name: <!-- markdownlint-enable-file MD001 -->

This can be used to "hide" markdownlint comments at the bottom of a file.

In cases where it is desirable to change the configuration of one or more rules for a file, the following more advanced syntax is supported:

  • Configure: <!-- markdownlint-configure-file { options.config JSON } -->

For example:

<!-- markdownlint-configure-file { "hr-style": { "style": "---" } } -->

or

<!-- markdownlint-configure-file
{
  "hr-style": {
    "style": "---"
  },
  "no-trailing-spaces": false
}
-->

These changes apply to the entire file regardless of where the comment is located. Multiple such comments (if present) are applied top-to-bottom. By default, content of markdownlint-configure-file is assumed to be JSON, but options.configParsers can be used to support alternate formats.

API

Linting

Standard asynchronous API:

/**
 * Lint specified Markdown files.
 *
 * @param {Options} options Configuration options.
 * @param {LintCallback} callback Callback (err, result) function.
 * @returns {void}
 */
function markdownlint(options, callback) { ... }

Synchronous API (for build scripts, etc.):

/**
 * Lint specified Markdown files synchronously.
 *
 * @param {Options} options Configuration options.
 * @returns {LintResults} Results object.
 */
function markdownlint.sync(options) { ... }

Promise API (in the promises namespace like Node.js's fs Promises API):

/**
 * Lint specified Markdown files.
 *
 * @param {Options} options Configuration options.
 * @returns {Promise<LintResults>} Results object.
 */
function markdownlint(options) { ... }

options

Type: Object

Configures the function. All properties are optional, but at least one of files or strings should be set to provide input.

options.config

Type: Object mapping String to Boolean | Object

Configures the rules to use.

Object keys are rule names or aliases and values are the rule's configuration. The value false disables a rule, true enables its default configuration, and passing an object customizes its settings. Setting the special default rule to true or false includes/excludes all rules by default. Enabling or disabling a tag name (ex: whitespace) affects all rules having that tag.

The default rule is applied first, then keys are processed in order from top to bottom with later values overriding earlier ones. Keys (including rule names, aliases, tags, and default) are not case-sensitive.

Example:

{
  "default": true,
  "MD003": { "style": "atx_closed" },
  "MD007": { "indent": 4 },
  "no-hard-tabs": false,
  "whitespace": false
}

See .markdownlint.jsonc and/or .markdownlint.yaml for an example configuration object with all properties set to the default value.

Sets of rules (known as a "style") can be stored separately and loaded as JSON.

Example of referencing a built-in style from JavaScript:

const options = {
  "files": [ "..." ],
  "config": require("style/relaxed.json")
};

Example doing so from .markdownlint.json via extends (more on this below):

{
  "extends": "markdownlint/style/relaxed"
}

See the style directory for more samples.

See markdownlint-config-schema.json for the JSON Schema of the options.config object.

See ValidatingConfiguration.md for ways to use the JSON Schema to validate configuration.

For more advanced scenarios, styles can reference and extend other styles. The readConfig and readConfigSync functions can be used to read such styles.

For example, assuming a base.json configuration file:

{
  "default": true
}

And a custom.json configuration file:

{
  "extends": "base.json",
  "line-length": false
}

Then code like the following:

const options = {
  "config": markdownlint.readConfigSync("./custom.json")
};

Merges custom.json and base.json and is equivalent to:

const options = {
  "config": {
    "default": true,
    "line-length": false
  }
};
options.configParsers

Type: Optional Array of Function taking (String) and returning Object

Array of functions to parse the content of markdownlint-configure-file blocks.

As shown in the Configuration section, inline comments can be used to customize the configuration object for a document. By default, the JSON.parse built-in is used, but custom parsers can be specified. Content is passed to each parser function until one returns a value (vs. throwing an exception). As such, strict parsers should come before flexible ones.

For example:

[ JSON.parse, require("toml").parse, require("js-yaml").load ]
options.customRules

Type: Array of Object

List of custom rules to include with the default rule set for linting.

Each array element should define a rule. Rules are typically exported by another package, but can be defined locally.

Example:

const extraRules = require("extraRules");
const options = {
  "customRules": [ extraRules.one, extraRules.two ]
};

See CustomRules.md for details about authoring custom rules.

options.files

Type: Array of String

List of files to lint.

Each array element should be a single file (via relative or absolute path); globbing is the caller's responsibility.

Example: [ "one.md", "dir/two.md" ]

options.frontMatter

Type: RegExp

Matches any front matter found at the beginning of a file.

Some Markdown content begins with metadata; the default RegExp for this option ignores common forms of "front matter". To match differently, specify a custom RegExp or use the value null to disable the feature.

The default value:

/((^---\s*$[\s\S]+?^---\s*)|(^\+\+\+\s*$[\s\S]+?^(\+\+\+|\.\.\.)\s*)|(^\{\s*$[\s\S]+?^\}\s*))(\r\n|\r|\n|$)/m

Ignores YAML, TOML, and JSON front matter such as:

---
layout: post
title: Title
---

Note: Matches must occur at the start of the file.

options.fs

Type: Object implementing the file system API

In advanced scenarios, it may be desirable to bypass the default file system API. If a custom file system implementation is provided, markdownlint will use that instead of invoking require("fs").

Note: The only methods called are readFile and readFileSync.

options.handleRuleFailures

Type: Boolean

Catches exceptions thrown during rule processing and reports the problem as a rule violation.

By default, exceptions thrown by rules (or the library itself) are unhandled and bubble up the stack to the caller in the conventional manner. By setting handleRuleFailures to true, exceptions thrown by failing rules will be handled by the library and the exception message logged as a rule violation. This setting can be useful in the presence of (custom) rules that encounter unexpected syntax and fail. By enabling this option, the linting process is allowed to continue and report any violations that were found.

options.markdownItPlugins

Type: Array of Array of Function and plugin parameters

Specifies additional markdown-it plugins to use when parsing input. Plugins can be used to support additional syntax and features for advanced scenarios.

Each item in the top-level Array should be of the form:

[ require("markdown-it-plugin"), plugin_param_0, plugin_param_1, ... ]
options.noInlineConfig

Type: Boolean

Disables the use of HTML comments like <!-- markdownlint-enable --> to toggle rules within the body of Markdown content.

By default, properly-formatted inline comments can be used to create exceptions for parts of a document. Setting noInlineConfig to true ignores all such comments.

options.resultVersion

Type: Number

Specifies which version of the result object to return (see the "Usage" section below for examples).

Passing a resultVersion of 0 corresponds to the original, simple format where each error is identified by rule name and line number. This is deprecated.

Passing a resultVersion of 1 corresponds to a detailed format where each error includes information about the line number, rule name, alias, description, as well as any additional detail or context that is available. This is deprecated.

Passing a resultVersion of 2 corresponds to a detailed format where each error includes information about the line number, rule names, description, as well as any additional detail or context that is available. This is deprecated.

Passing a resultVersion of 3 corresponds to the detailed version 2 format with additional information about how to fix automatically-fixable errors. In this mode, all errors that occur on each line are reported (other versions report only the first error for each rule). This is the default.

options.strings

Type: Object mapping String to String

Map of identifiers to strings for linting.

When Markdown content is not available as files, it can be passed as strings. The keys of the strings object are used to identify each input value in the result summary.

Example:

{
  "readme": "# README\n...",
  "changelog": "# CHANGELOG\n..."
}

callback

Type: Function taking (Error, Object)

Standard completion callback.

result

Type: Object

Call result.toString() for convenience or see below for an example of the structure of the result object. Passing the value true to toString() uses rule aliases (ex: no-hard-tabs) instead of names (ex: MD010).

Config

The options.config configuration object is simple and can be stored in a file for readability and easy reuse. The readConfig and readConfigSync functions load configuration settings and support the extends keyword for referencing other files (see above).

By default, configuration files are parsed as JSON (and named .markdownlint.json). Custom parsers can be provided to handle other formats like JSONC, YAML, and TOML.

Asynchronous API:

/**
 * Read specified configuration file.
 *
 * @param {string} file Configuration file name.
 * @param {ConfigurationParser[] | ReadConfigCallback} parsers Parsing function.
 * @param {Object} [fs] File system implementation.
 * @param {ReadConfigCallback} [callback] Callback (err, result) function.
 * @returns {void}
 */
function readConfig(file, parsers, fs, callback) { ... }

Synchronous API:

/**
 * Read specified configuration file synchronously.
 *
 * @param {string} file Configuration file name.
 * @param {ConfigurationParser[]} [parsers] Parsing function(s).
 * @param {Object} [fs] File system implementation.
 * @returns {Configuration} Configuration object.
 */
function readConfigSync(file, parsers, fs) { ... }

Promise API (in the promises namespace like Node.js's fs Promises API):

/**
 * Read specified configuration file.
 *
 * @param {string} file Configuration file name.
 * @param {ConfigurationParser[]} [parsers] Parsing function(s).
 * @param {Object} [fs] File system implementation.
 * @returns {Promise<Configuration>} Configuration object.
 */
function readConfig(file, parsers, fs) { ... }

file

Type: String

Location of configuration file to read.

The file is resolved relative to the current working directory. If an extends key is present once read, its value will be resolved as a path relative to file and loaded recursively. Settings from a file referenced by extends are applied first, then those of file are applied on top (overriding any of the same keys appearing in the referenced file). If either the file or extends path begins with the ~ directory, it will act as a placeholder for the home directory.

parsers

Type: Optional Array of Function taking (String) and returning Object

Array of functions to parse configuration files.

The contents of a configuration file are passed to each parser function until one of them returns a value (vs. throwing an exception). Consequently, strict parsers should come before flexible parsers.

For example:

[ JSON.parse, require("toml").parse, require("js-yaml").load ]

fs

Type: Optional Object implementing the file system API

In advanced scenarios, it may be desirable to bypass the default file system API. If a custom file system implementation is provided, markdownlint will use that instead of invoking require("fs").

Note: The only methods called are readFile, readFileSync, access, and accessSync.

callback

Type: Function taking (Error, Object)

Standard completion callback.

result

Type: Object

Configuration object.

Usage

Invoke markdownlint and use the result object's toString method:

const markdownlint = require("markdownlint");

const options = {
  "files": [ "good.md", "bad.md" ],
  "strings": {
    "good.string": "# good.string\n\nThis string passes all rules.",
    "bad.string": "#bad.string\n\n#This string fails\tsome rules."
  }
};

markdownlint(options, function callback(err, result) {
  if (!err) {
    console.log(result.toString());
  }
});

Output:

bad.string: 3: MD010/no-hard-tabs Hard tabs [Column: 19]
bad.string: 1: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#bad.string"]
bad.string: 3: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#This string fails        some rules."]
bad.string: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.string"]
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#This file fails      some rules."]
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]

Or invoke markdownlint.sync for a synchronous call:

const result = markdownlint.sync(options);
console.log(result.toString());

To examine the result object directly:

markdownlint(options, function callback(err, result) {
  if (!err) {
    console.dir(result, { "colors": true, "depth": null });
  }
});

Output:

{
  "good.md": [],
  "bad.md": [
    { "lineNumber": 3,
      "ruleNames": [ "MD010", "no-hard-tabs" ],
      "ruleDescription": "Hard tabs",
      "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md010.md",
      "errorDetail": "Column: 17",
      "errorContext": null,
      "errorRange": [ 17, 1 ] },
    { "lineNumber": 1,
      "ruleNames": [ "MD018", "no-missing-space-atx" ],
      "ruleDescription": "No space after hash on atx style heading",
      "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md018.md",
      "errorDetail": null,
      "errorContext": "#bad.md",
      "errorRange": [ 1, 2 ] },
    { "lineNumber": 3,
      "ruleNames": [ "MD018", "no-missing-space-atx" ],
      "ruleDescription": "No space after hash on atx style heading",
      "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md018.md",
      "errorDetail": null,
      "errorContext": "#This file fails\tsome rules.",
      "errorRange": [ 1, 2 ] },
    { "lineNumber": 1,
      "ruleNames": [ "MD041", "first-line-heading", "first-line-h1" ],
      "ruleDescription": "First line in a file should be a top-level heading",
      "ruleInformation": "https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md041.md",
      "errorDetail": null,
      "errorContext": "#bad.md",
      "errorRange": null }
  ]
}

Integration with the gulp build system is straightforward:

const gulp = require("gulp");
const through2 = require("through2");
const markdownlint = require("markdownlint");

gulp.task("markdownlint", function task() {
  return gulp.src("*.md", { "read": false })
    .pipe(through2.obj(function obj(file, enc, next) {
      markdownlint(
        { "files": [ file.relative ] },
        function callback(err, result) {
          const resultString = (result || "").toString();
          if (resultString) {
            console.log(resultString);
          }
          next(err, file);
        });
    }));
});

Output:

[00:00:00] Starting 'markdownlint'...
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#This file fails      some rules."]
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
[00:00:00] Finished 'markdownlint' after 10 ms

Integration with the Grunt build system is similar:

const markdownlint = require("markdownlint");

module.exports = function wrapper(grunt) {
  grunt.initConfig({
    "markdownlint": {
      "example": {
        "src": [ "*.md" ]
      }
    }
  });

  grunt.registerMultiTask("markdownlint", function task() {
    const done = this.async();
    markdownlint(
      { "files": this.filesSrc },
      function callback(err, result) {
        const resultString = err || ((result || "").toString());
        if (resultString) {
          grunt.fail.warn("\n" + resultString + "\n");
        }
        done(!err || !resultString);
      });
  });
};

Output:

Running "markdownlint:example" (markdownlint) task
Warning:
bad.md: 3: MD010/no-hard-tabs Hard tabs [Column: 17]
bad.md: 1: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#bad.md"]
bad.md: 3: MD018/no-missing-space-atx No space after hash on atx style heading [Context: "#This file fails      some rules."]
bad.md: 1: MD041/first-line-heading/first-line-h1 First line in a file should be a top-level heading [Context: "#bad.md"]
 Use --force to continue.

Fixing

Rules that can be fixed automatically include a fixInfo property which is outlined in the documentation for custom rules. To apply those fixes more easily, the applyFixes method in markdownlint-rule-helpers may be used.

Browser

markdownlint also works in the browser.

Generate normal and minified scripts with:

npm run build-demo

Then reference markdown-it and markdownlint:

<script src="demo/markdown-it.min.js"></script>
<script src="demo/markdownlint-browser.min.js"></script>

And call it like so:

const options = {
  "strings": {
    "content": "Some Markdown to lint."
  }
};
const results = window.markdownlint.sync(options).toString();

Examples

For ideas how to integrate markdownlint into your workflow, refer to the following projects or one of the tools in the Related section:

Contributing

See CONTRIBUTING.md for more information.

Releasing

See ReleaseProcess.md for more information.

History

See CHANGELOG.md.

markdownlint's People

Contributors

adithyabsk avatar aepfli avatar bmish avatar chenxsan avatar ciwchris avatar davidanson avatar dependabot[bot] avatar koppor avatar levacic avatar marklodato avatar mateus avatar mebeim avatar mlichtblau avatar mondeja avatar mrmanc avatar nschonni avatar ohtake avatar onkarruikar avatar pascalberger avatar paweldrozd avatar per1234 avatar peterrozum avatar piedone avatar regseb avatar rodneyrehm avatar theoludwig avatar tommy-gilligan avatar travisclagrone avatar wouter-admiraal-sonarsource avatar yash-singh1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

markdownlint's Issues

proper-names should allow different formatting when a URL is used as link text

Given the following configuration:

{
  "proper-names": {
    "names": [
      "GitHub"
    ]
  }
}

I can write this:

Awesome things related to Vue available at GitHub

Awesome things related to Vue available at [GitHub](https://github.com/vuejs/awesome-vue)

But not any of this:

Awesome things related to Vue available at github.com

Awesome things related to Vue available at [github.com](https://github.com/vuejs/awesome-vue)
Awesome things related to Vue available at [github.com/vuejs](https://github.com/vuejs/awesome-vue)
Awesome things related to Vue available at [github.com/vuejs/awesome-vue](https://github.com/vuejs/awesome-vue/)

I also tried adding "github.com" to the configuration both before and after "GitHub" but it didn't help, I still got the error.


I believe it's obvious that the latter should also be allowed here. When linking between domains, I quite frequently prefer writing the URL for the user, but will use the link formatting to only write the relevant part and make the link more readable. I might drop the protocol, parameters, trailing slashes and such.

I think proper-names should exempt all URLs and emails. This seems to be the intention as well as the code does not trigger errors from bare URLs, but it still disallows using the URL pattern as a user-facing link text, which probably isn't what we want.

ordered and unordered lists recognized where there are none

The following text triggers linting rules MD 29 and 30/32.

This example text triggers linting rules number 29 and
32. If no sentence follows the previous one, linting rules 29 and 30 are triggered.

A possible solution would be to search first for dot (.) in the line preceding the supposed ordered list. Only when . is found should rules 29, 30/32 be triggered.

Case of falsely recognised unordered list:

This example text triggers linting rule number 32
- and sometimes rule number 4.

MD029 is triggered on any multiline ordered list items.

I am using the markdownlint v0.6.2 and I am seeing that the MD029 rule is always triggered even when using the sample provided inside the rule.
i.e.

1. Do this.
2. Do that.
3. Done.

should pass the issue but it is generating green swiggle with MD029 tooltip.

Add rule to check for file naming

Adding a rule to check for file naming would be a nice enhancement.

Guidelines which for example we currently are using:

  • Filename needs to be lowercase
  • Allowed characters: a-z 0-9 - .

Add rule for checking proper formating of fenced code block inside lists

Writing fenced code blocks inside of ordered and unordered lists might not be the most obvious thing. A rule indicating mistakes might be really helpful in this case.

Stuff to check:

  • There needs to be a new line before and following any fenced code block inside of a ordered or unordered list

Rule MD004 incorrectly flagging on an Ordered List

I'm getting flagged on the following. Am I missing something obvious?

1. Fork the repository on Github
+ Create a named feature branch (like `add_component_x`)
+ Write your change
+ Write tests for your change (if applicable)
+ Run the tests, ensuring they all pass
+ Submit a Pull Request using Github

MD013 (line-length) and link tooltips

A link can have a tooltip with whitespace, e. g.

[Open a pull request](https://help.github.com/articles/using-pull-requests/ "Using pull requests · GitHub Help")

It is impossible to break it into multiple lines.
I think MD013 (line-length) should ignore lines with links that have tooltips.

Maximum line width

First off: Its really great that you work on this 👍 markdown files make out a lot of our work and linting it can really help. That being said,...

One important issue that I have with markdown is if the paragraphs should be multiline or not. I am of the opinion that paragraphs should be broken after 80 characters to make sure that pull requests go through smoother (and see changes easier). Do you think it would be possible to add an optional check for the maximum line size?

MD029 - Ordered list item prefix

I have a document where I have an ordered list and I get the warning above on every item after 1.
So if I have the following code I get the MD029 error on #'s 2, 3 and 4.

1. A computer or access to a computer that we can install software on. Preferably under our own user account. 2. Access to the internet. 3. A place where you can take and save notes. 4. Personal Grit

Is this normal behavior, or is the linter not recognizing the OL properly?

MD030, Spaces after list markers isn’t enforced if 0 spaces

Here’s an example of incorrect Markdown:

-Some stuff
-More stuff
- Things

I would like to enforce a single space after those dashes in the list. Without the space Markdown interprets it as a paragraph.

Important configuration I have turned on:

{
  "ul-style": {
    "style": "dash"
  },
  "list-indent": true,
  "ul-start-left": true,
  "ul-indent": {
    "indent": 2
  },
  "list-marker-space": {
    "ul_single": 1,
    "ol_single": 1,
    "ul_multi": 1,
    "ol_multi": 1
  },
}

What error message I do see:

MD032 — Lists should be surrounded by blank lines.

Which doesn’t make sense to me because those aren’t separate lists. It’s interpreting the last, correct dash, as a list and the other two as paragraphs.

Use case:

I teach beginners, people who have never written a line of Markdown before. The idea that a missing space can have such an impact is foreign. I’d like to use the linter to find these simple mistakes beforehand.

Any thoughts would be appreciated. Thanks.

Ignore indenting within code blocks

I write code with tabs and when I copy paste the code inside my markdown files, markdownlint complains about hard tabs. Wouldn't be a good idea to not enforce the indenting rule within code block s to allow any kind of indent?

Enhancement: Custom error messages

Rules

Currently rules have a static error message, it would be useful if they could generate context-sensitive errors, for example:

errors.push({
  lineNumber: whatever,
  error: `The '${headingText}' heading should be at level ${expectedLevel}`
});

Styles

An optional top-level error message that gets output upon the first error for a given batch of documents.

options.config._guidance = 'Please refer to the style guide for more information on the errors below: http://whatever.com/styleguide'

This would be particularly useful in CI builds of open source projects to help guide contributors to the style guide or templates, etc.

ignore hard-tabs in code block

for example

func main() {
    r := gin.Default()
    r.GET("/", func(c *gin.Context) {
        c.String(http.StatusOK, "Hello from %v", "Gin")
    })

    r.Run(":3000")
}

MD033 "Inline HTML" should allow exceptions

My markdown files contain certain html tags (like <kbd>) that just can't be expressed in markdown. I'd suggest to extend the configuration option to accept an array of tags that are considered safe for use in a document.

I generally want to be warned about html in my markdown, but there are situations where I actually need to use the html. I was wondering if there is any way to mark those situations inline, like you would with eslint's /*eslint-disable foobar */. (long shot, I don't see any obvious notation for this…)

Request: Mandatory headings

Would it be possible to get a rule which enforces mandatory headings in a file?

For example, in documentation, there may be a style guide that requires the docs to have a specific set of headers.

The rule would take an array of strings, each string being a header that must exist in the file. The rule is violated if any of the headers in the array are not found in the file.

If possible, an optional boolean flag (false by default) would make the rule ensure that the headers are in the same order as those specified in the array.

Add ability to disable specific rule(s) for specific file(s)

Hello, I'm working on the ESLint project, which uses this module. In general, we want to prohibit tabs in our markdown (using rule MD010), but there is one file where I need to use tabs in an example of the indent rule. Is there a way to turn off just that rule, for just that file? If not, is that a feature you would consider adding?

Erroneous MD003 warning

MD003/header-style: Header style [Expected: setext; Actual: atx]

I get this warning for ### Header Level 3, even though your documentation says it is valid...

The setext_with_atx and settext_with_atx_closed doc styles allow atx-style headers of level 3 or more in documents with setext style headers:

Add support for custom rules

Hi, nice tool! Thanks.

I would like to add my own custom rules, similar to rules param object, declare custom rules in the config. Would you consider?

Add rule to enforce letter case of project names [WAS: How to add custom rules?]

Hi,

I checked the docs/source but I didn't see any obvious extension mechanism (apart from forking). Do you have some preferred way on how to handle custom rules? I can see the rule mechanism itself is quite simple. If it was possible to inject new ones through the API somehow (match through npm/Node), I could likely do what I want (I need to verify certain word is lowercase always).

CommonMark mention

Currently README.md call markdownlint A Node.js style checker and lint tool for Markdown files.

Should CommonMark be mentioned too?

As far as I understood it covers CommonMark pretty good. CommonMark nowadays is becoming a de-facto standard, because it has spec unlike Markdown. I see that you included link to this spec in README.md.

Support for presets?

With the latest changes in 0.5.0 that introduce extends, I'm wondering what your thoughts are about supporting a concept of presets? This is similar to what ESLint offers and I think it'd be a useful addition this tool.

For some background, we currently maintain several projects that have .markdownlint.json files. For us, it'd be great to centrally define these rules, and then just pull that dependency into each project. We could then better communicate to our team what has changed and why :)

MD029 (ol-prefix) and nested unordered lists in ordered lists

If I use the following rule:

{
    "ol-prefix": {
        "style": "ordered"
    }
}

then markdownlint says "Ordered list item prefix (Expected: 1; Actual: 2)" to the following code:

1. a
- b
2. c
- d

It looks like markdownlint thinks that 2. c is the beginning of a new list, but it's the second item of the single ordered list.

If I indent the unordered lists, markdownlint says "Consider starting bulleted lists at the beginning of the line".

What is the correct way of using nested unordered lists in ordered lists?

MD009 for list continuation

when you make a multi paragraphs list, you have to continue indentation on empty lines. In this case, rule MD009 report an error.
To solve this issue, MD009 should not trigger errors for a line with only spaces if

  • previous lines starts by at least the same amount of lines and following line starts by exactly the same amount of spaces
  • or previous lines starts by exactly the same amount of lines and following line starts by at least the same amount of spaces

Example:

-   first paragraph of the item
    
    second paragraph of the same item

(note: although this is not visible, line 2 is exactly 4 paragraphs)

Bogus MD0036 error

Take this snippet for instance:

* `io.js 1.6.2`, `io.js 1.6.3` x86 and x64 added. Use `Install-Product node 1` cmdlet to switch runtime to the latest io.js version.
* `Node.js 0.10.38`, `Node.js 0.12.2` x86 and x64 added. Use `Install-Product node 0` cmdlet to switch runtime to the latest Node.js version or `Install-Product node 0.10` to the latest 0.10.x build.
    * Node.js 0.10.38 x86 is default Node.js in `PATH`
* **Azure SDK 2.5.1**
* [Microsoft Visual Studio Installer Projects](https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d) extension installed (`.vdproj` support).
* [Bundler 1.9.2](https://rubygems.org/gems/bundler/versions/1.9.2) is pre-installed to all Rubies.
* **Python 2.7.9** replaces Python 2.7.8 in `C:\Python27` and `C:\Python27-x64`.
* **Python 3.4.3** replaces Python 3.4.1 in `C:\Python34` and `C:\Python34-x64`.

Another example:

3. Run `install` scripts
4. Patch `AssemblyInfo` files
5. Modify `hosts` files
6. Start services
7. **Build**
    * Run `before_build` scripts
    * Run msbuild
    * Run `after_build` scripts
8. **Test**

That is an emphasis and not a header.

Add rule to check for inline-style links

A rule to dissallow inline-style links would be a nice enhancements.

Possible configuration parameters:

  • Disallow all inline-style links
  • Allow inline-style links in lists only
  • Allow all inline-style links

MD041 (first-line-h1) and HTML comments

I find it convenient to disable some rules for the whole file by adding a markdownlint marker to the top of the file (as I would do with JSLint directives, for example):

<!-- markdownlint-disable line-length -->
# Header

...

But this violates MD041 (first-line-h1) rule.
I think MD041 (first-line-h1) should ignore HTML comments.

Proposed rule: enforce typography

Here's a few checks that I would like to have:

  • quotes: use proper “” instead of "".
  • apostrophes: use proper apostrophes instead of '.
  • punctuation_space: enforce one space after a punctuation symbol, unless it's followed by a new line.
  • double_spaces: no double spaces.

I think code should be excluded by default for all these checks.

For the first two, Atom has a really nice package that might be used as inspiration.

Require structure only for certain files / paths

Is there a way to have MD043 only required for certain files or paths, but not for others?

Or is there a way to exclude this rule for certain files?

I tried with <!-- markdownlint-disable MD043 --> but couldn't get it working.

Request: No empty link rule

When working on large documents, sometimes placeholder links are added with the expectation they will be defined later. For example:

[foo]()

[bar](#)

Such links are somewhat difficult to spot in big documents. The rule would warn against those patterns.

Note: A # link is sometimes used to jump to top of document, however similar effect can be achieved by linking to main heading or a html anchor tag.

Unordered sublist with different symbol

When writing an unordered sublist I like to use a different list symbol rather than the same used for the main list:

- item 1
- item 2
  + subitem 1
  + subitem 2

In my opinion this should be fine, but I get a MD004 warning instead. I suggest to modify the linter not to raise a warning in this case.

Unordered sublist in ordered list

I'm having trouble getting an unordered sublist in an ordered list to pass linting with the default config. I've tested in playground and with markdownlint-cli.

With 2 space indent I get MD006 and also see 3 distinct lists - ordered, unordered, ordered - in the playground preview:

# sublist test

1. foo
  - bar
  - baz
1. foo

With 4 (or 3, or 5 just for kicks) space indent I get MD007:

# sublist test

1. foo
    - bar
    - baz
1. foo

An unordered sublist with 2 space indent in an unordered parent works fine:

# sublist test

- foo
  - bar
  - baz
- foo

As does inverting the structure of what I'm trying to achieve: an ordered sublist with 2 space indent in an unordered parent:

# sublist test

- foo
  1. bar
  1. baz
- foo

I may be missing a spacing requirement in the CommonMark spec, but feels like either one of the first two examples should pass if the fourth does?

Consider highlighting trailing space when encountering MD009

Currently when MD009 is encountered, the entire line is highlighted to indicate that there is a trailing space. This is distracting when you're constantly typing. Highlighting just the last space, or perhaps not showing the error indication if the cursor is currently active on the line would make it less obtrusive.

line highlight

setext_with_atx_closed not available in Virtual Studio Code extension

I just installed the markdownlint extension in VS Code. I was going nuts trying to figure out why I couldn't get the .json config to take setext_with_atx_closed, when all the other options (including setext_with_atx) worked fine. So I stumbled on your commit history and see you've only just implemented it. I assume, then, that this change has not been migrated into the VS Code extension. Will you be updating the extension soon, or should it be already working?

To reproduce the symptom:

  • Create file .markdownlint.json in project folder with the following content:
{
    "MD003": { "style": "setext_with_atx_closed" }
}
  • In VS Code with markdownlint extension installed, open the project folder.
  • Create a new file, set its language to Markdown, and enter the following lines:
Test of VS Code 'markdownlint' Extension
==

Setext Header
--

## ATX Header

### ATX_Closed Header ###

Some text.
  • Observe that all headers are flagged with warnings for rule MD003. Presumably, the setext_with_atx_closed value for the style property is unknown to the extension.

Make `no-multiple-blanks` configurable

Since this is mostly aesthetic, making the option configurable will offer more flexibility.

Say, allow max: 3 blank lines would allow for 1 up to 3 blank lines.

rule MD034 flags URL in fenced block as "bare url", unlike mdl

A URL inside of a fenced code block is marked as a "bare url" by markdownlint.

However, the ruby-based mdl doesn't mark the same line as a bare url.

Please resolve this difference. Thanks.

Example:
$ cat test-fenced-url.md

# Error with URL in Fenced Code Block

    ````text
http://lms.com/pens.cgi?command=collect&pens-version=1.0.0
&package-type=scorm-pif&package-type-version=1.2&package-format=zip
&package-id=http%3A%2F%2Fwww.author.com%3A994646572378864600-1085069139609
&package-url=http%3A%2F%2Fauthor.com%2Fpackages%2F1085069139609.zip
&package-url-expiry=2005-05-20T16%3A05%3A39Z&client=Author
&receipt=http%3A%2F%2Fauthor.com%2Fpens.cgi
&alerts=http%3A%2Fauthor.com%2Fpens.cgi
    ````

The above example will "pass" review by mdl, but markdownlint will trigger a warning:

$ mdl test-fenced-url.md
$ markdownlint test-fenced-url.md
test-fenced-url.md: 3: MD034 Bare URL used

Allow atx_closed with setext in rule MD003

Currently rule MD003 has the style option of setext_with_atx, but this does not allow atx_closed to be used with setext. Either adding a new style of setext_with_atx_closed to the rule or allowing atx_closed be acceptable when using the style setext_with_atx would be nice. Thoughts? Is there a preference one way or the other?

MD044 - Links and code should be excluded from checks

First of all, thanks for this great tool. I've been experimenting with it for the last couple of days and it works great.

I'm really interested in this rule, but it fails short with its current implementation. Example:

  "proper-names": {
      "names": [
          "GitHub"
      ]
  }

All docs fail where there's a link to GitHub. I think there should be an option to exclude links, URLs, and code from this check, and it should probably be true by default.

Trailing space in paragraph bug

There seems to be a bug in the trailing space matching of some kind, but only errors when there’s front matter. I cannot recreate the error in the demo so it could also be related to resultVersion: 1.

This is the code that throws the error:

---
basic-card: |
  The basic card is used to showcase the dogs that are available for adoption. It includes a button but never links itself.
---

The cards provide a way to highlight and group important information. 

There’s a trailing space right at the end of “information. ” and this is the error I get:

TypeError: Cannot read property 'match' of undefined on line 258

If I strip the front matter it seems to work okay.


Version: 0.4.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.