Skip to content

markdown-preferences/prefer-inline-code-words

enforce the use of inline code for specific words.

  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule enforces that specific words or phrases are always wrapped in inline code (backticks) when they appear in Markdown text. This is useful for:

  • Ensuring technical terms, API names, or function names are consistently formatted as code
  • Maintaining consistent styling for programming-related terminology
  • Automatically applying code formatting to specified words
  • Formatting words that match a regular expression
md
<!-- eslint markdown-preferences/prefer-inline-code-words: ["error", { "words": ["ESLint", "TypeScript", "npm"] }] -->

<!-- ✓ GOOD -->

Use `ESLint` with `TypeScript` for linting. Install it with `npm`.

The `ESLint` configuration file should be in the root directory.

<!-- ✗ BAD -->

Use 
ESLint
with
TypeScript
for linting. Install it with
npm
.
The
ESLint
configuration file should be in the root directory.

Regular expression patterns can be written in /pattern/flags notation:

md
<!-- eslint markdown-preferences/prefer-inline-code-words: ["error", { "words": ["/[A-Z][a-z]+\\.[a-z][A-Za-z]+/u"] }] -->

<!-- ✓ GOOD -->

Use `Array.isArray` to check the value.

<!-- ✗ BAD -->

Use 
Array.isArray
to check the value.

🔧 Options

This rule requires configuration of the words that should be wrapped in inline code.

json
{
  "markdown-preferences/prefer-inline-code-words": [
    "error",
    {
      "words": [
        "ESLint",
        "TypeScript",
        "JavaScript",
        "Prettier",
        "npm",
        "yarn"
      ],
      "ignores": [
        {
          "words": ["ESLint", "TypeScript", "JavaScript"],
          "node": { "type": "heading", "depth": 1 }
        }
      ]
    }
  ]
}
  • words (required): An array of strings representing the words or regular expression patterns that should always be wrapped in inline code when they appear in Markdown text.
  • ignores (optional): An array of objects that specify conditions under which the rule should not apply. Each object can have:
    • words: An array or string of words to ignore. If not specified, all words will be ignored.
    • node: An object specifying conditions for ignoring nodes.

Strings in /pattern/flags notation are interpreted as JavaScript regular expressions. For example, "/eslint/iu" matches ESLint case-insensitively. Matches use the same whole-word boundary checks as literal words.

ignores

You can use the ignores option to exclude the rule application under specific conditions. Each ignore condition is an object with the following properties:

  • words (optional): Specifies the matched words to ignore. Can be specified as an array or string. If not specified, all words will be targeted.
  • node (optional): Specifies the ignore conditions by node type or properties. Excludes nodes where the specified properties match. For example, to exclude all heading levels (h1 to h6), specify {"type": "heading"}, and to exclude only level 1 headings (h1), specify {"type": "heading", "depth": 1}.

Usage Examples

json
{
  "markdown-preferences/prefer-inline-code-words": [
    "error",
    {
      "words": ["ESLint", "TypeScript", "JavaScript"],
      "ignores": [
        {
          "words": ["ESLint", "TypeScript"],
          "node": { "type": "heading", "depth": 1 }
        },
        {
          "words": "JavaScript",
          "node": { "type": "link" }
        }
      ]
    }
  ]
}

In this configuration:

  • "ESLint" and "TypeScript" in level 1 headings will be ignored
  • "JavaScript" in links will be ignored

Node Types and Properties

Please refer to the mdast documentation for detailed properties of each node.

📚 Further Reading

🚀 Version

This rule was introduced in eslint-plugin-markdown-preferences v0.4.0

🔍 Implementation