We are using the markdownlint
library (via markdownlint-cli2
and adding our opinions and custom rules to it.
To review behaviors supported by markdownlint
, particularly how to enable or disable rules, see markdownlint-cli2
configuration.
At GitHub, we have opinions about how our markdown should be written.
In addition to defaults defined by markdownlint
, we use this repository to enforce rules not defined by default, including our own custom rules.
See our opinions codified in index.js.
This plugin will enable the defaults defined by markdownlint
. Several of these pertain to stylistic practices. You may choose to disable these rules if you determine it doesn't provide value for your project.
However, others of these rules should NOT be disabled because they encourage best accessibility practices. Disabling these rules will negatively impact accessibility. These rules are specified in accessibility.json.
The following are custom rules defined in this plugin.
- GH001 no-default-alt-text
- GH002 no-generic-link-text
See markdownlint
rules for documentation on rules pulled in from markdownlint
.
Note: We recommend configuring markdownlint-cli2
over markdownlint-cli
for compatibility with the vscode-markdownlint plugin.
-
Create a
.markdownlint-cli2.cjs
file in the root of your repositorytouch .markdownlint-cli2.cjs
-
Install packages
-
npm install -D markdownlint-cli2 # if updating existing package, check for updates npm install -D @github/markdownlint-github [--@github:registry=https://registry.npmjs.org]
-
-
Add/modify your linting script in
package.json
.markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\"
-
Edit
.markdownlint-cli2.cjs
file to suit your needs. Start withconst options = require('@github/markdownlint-github').init() module.exports = { config: options, customRules: ["@github/markdownlint-github"], }
Or, you can also pass in configuration options that you wish to override the default. This looks like:
const options = require('@github/markdownlint-github').init({ 'fenced-code-language': false, }) module.exports = { config: options, customRules: ["@github/markdownlint-github"], }
-
Install the
vscode-markdownlint
plugin to ensuremarkdownlint
violations are surfaced in the file. This plugin should flag rules based off your.markdownlint-cli2.cjs
configuration. When you make edits to your configuartion, you will need to reload the VSCode window (Ctrl+Shift+P
->Reload Window
) to ensure the extension syncs.
You may write custom rules within your repository. Follow the custom rules guide in markdownlint
to write your rule.
The rule will need to be enabled in the configuration. For instance, if you introduce some-rule.js
with the name "some-rule", you must set the path of the custom rule in the .markdownlint-cli2.cjs
file:
module.exports = require('@github/markdownlint-github').init({
"some-rule": true,
customRules: ["@github/markdownlint-github", "some-rule.js"],
})
See markdownlint-cli2
configuration.
Consider upstreaming any rules you find useful as proposals to this repository.
Please read Contributing Guide for more information.