Giter Site home page Giter Site logo

markdownlint-github's Introduction

Markdownlint-github

This repository provides GitHub's recommended markdownlint configurations, and additional rules for use on GitHub open source and internal projects.

Opinions

In addition to defaults defined by markdownlint, we use this repository to enforce rules not defined by default, including our own custom rules.

See opinions codified in index.js.

Rules

The following are custom rules defined in this plugin.

See markdownlint rules for documentation on rules pulled in from markdownlint.

Usage

Important: We support the use of markdownlint through markdownlint-cli2 instead of markdownlint-cli for compatibility with the vscode-markdownlint plugin.

  1. Create a .markdownlint-cli2.cjs file in the root of your repository.

    touch .markdownlint-cli2.cjs
  2. 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]
    npm install -D markdownlint-cli2-formatter-pretty
  3. Add/modify your linting script in package.json.

    "scripts": {
      "lint:markdown": "markdownlint-cli2 \"**/*.{md,mdx}\" \"!node_modules\""
    }
  4. Edit .markdownlint-cli2.cjs file to suit your needs. Start with

    const options = require('@github/markdownlint-github').init()
    module.exports = {
        config: options,
        customRules: ["@github/markdownlint-github"],
        outputFormatters: [
          [ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ] // ensures the error message includes a link to the rule documentation
        ]
    }

    Or, you can also pass in configuration options that you wish to override the default. Read more at Customizing configurations. This looks like:

    const options = require('@github/markdownlint-github').init({
        'fenced-code-language': false, // Custom overrides
    })
    module.exports = {
        config: options,
        customRules: ["@github/markdownlint-github"],
        outputFormatters: [
          [ "markdownlint-cli2-formatter-pretty", { "appendLink": true } ]
        ]
    }
  5. Install the vscode-markdownlint plugin to ensure markdownlint violations are surfaced in the file. This plugin should flag rules based off your .markdownlint-cli2.cjs configuration. When you make edits to your configuration, you will need to reload the VSCode window (Ctrl+Shift+P -> Reload Window) to ensure the extension syncs. If your project runs on Codespaces, consider adding this extension to your .devcontainer/devcontainer.json so that this extension is installed to new Codespaces by default.

Customizing configurations

You may determine that the defaults set by this plugin are not suitable for your project.

This plugin will pull in the the defaults defined by markdownlint, several of which 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 defined in accessibility.json.

To review configurations supported by markdownlint, see markdownlint-cli2 configuration.

Advanced: Adding custom rules in your codebase

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.

License

This project is licensed under the terms of the MIT open source license. Please refer to MIT for the full terms.

Maintainers

See CODEOWNERS.

Contributing

Please read Contributing Guide for more information.

markdownlint-github's People

Contributors

andrialexandrou avatar chadfawcett avatar dependabot[bot] avatar iansan5653 avatar janbrasna avatar kendallgassner avatar khiga8 avatar sampart 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

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  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-github's Issues

"header" aliases have been removed in markdown-cli2

We recently updated markdownlint-cli2 on The Hub and noticed we started receiving increased errors related to headings. I dove into why and noticed that markdownlint-cli2 has removed the rule aliases that use the word "header" in favour of "heading".

As per the commit message, "header" aliases were deprecated in v0.9.0. I checked your package.json and saw you're depending in v0.13.0 but still have rules with the "header" alias.

These rules should be updated to use "heading" instead of "header".

Provide rationale for the rules enabled or disabled

I think it will be helpful to provide context on why we recommend these configurations.

In base.json

{
    "default": true,
    "no-inline-html": false,
    "no-bare-urls": false,
    "no-blanks-blockquote": false,
    "fenced-code-language": true
}

In accessibility.json

{
    "no-alt-text": true,
    "no-default-alt-text": true,
    "no-duplicate-header": true,
    "no-emphasis-as-header": true,
    "no-generic-link-text": true,
    "no-space-in-links": false,
    "ol-prefix": "ordered",
    "single-h1": true,
    "ul-style": true
}

Some of these are somewhat obvious, while others are less so.

Default error output does not include link to documentation

The default error message for markdown-cli2 does not include description, aka the optional URL that we pass into the URL to provide consumers with more context about the rule.

It looks like as though we'd need projects to configure a separate formatter like formatter-pretty if we want the error message to link to the description URL. I don't like that we need to install a separate dependency, but this is the more idiomatic route.

Another option is to just include the URL as part of the error message so the formatter doesn't need to be configured but this is less idiomatic.

Create a `max-heading-level` rule

When Markdown content is rendered on GitHub, it is rendered into the context of a webpage. This means there is already an external heading structure to contend with.

In issue and PR comments, the maximum heading level that should be used is 3 (###). In files in Code View, the maximum should be 2 (##).

I think it's debatable whether Markdown files should be written with their intended viewing location in mind - Markdown is supposed to be a rendering-agnostic markup format. But comments should probably always be written like this. So I think it would be useful to make a new rule available, but disable it by default.

I propose we make this generic, allowing the linter to customize the heading level for the situation. For example, the following configuration would be for comments on github.com:

{
    "max-heading-level": {
        "level": 3
    }
}

Related:

Re-organize repo structure

As we add more files, I think it'll be beneficial to have a directory structure to place the rules and docs. Maybe something like:

src
--rules
----no-default-alt-text.js
----no-generic-link-text.js
----index.js
--helpers
test
--utils
------no-default-alt-text.test.js
------no-generic-link-text.test.js
docs
--rules
package.json
index.js
README.md

Document nuance around `no-duplicate-header` rule

This rule is set to true but I think there's some nuance around when this rule should be configured.

The rationale behind the no-duplicate-header rule is that some markdown parsers will generate anchor links from headings, and if the heading is the same, two headings in separate areas of the page will share the same anchor link. We see this issue in Primer docs.

However, on GitHub repos, the GitHub markdown parser ensures headings that share same text have unique IDs so the generated anchor links are unique even if the heading text is the same.

So I believe we wouldn't need to enforce that heading texts on a page are completely non-duplicated in other cases. I don't believe it's necessary to have completely unique heading text on a page for accessibility purposes. However, I believe there are accessibility benefits from enforcing that sibling headings are unique.

We could recommend setting siblings_only parameter which allows heading duplication for non-sibling headings and enforces sibling headings are unique.

Could we document these nuances?

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.