Skip to main content

No Raw Text in Code

Disallow unwrapped text inside <code> JSX elements to prevent MDX from parsing special characters as JSX tags.

Summary

The no-raw-text-in-code rule reports any unwrapped text placed directly between <code> JSX tags without a {} expression wrapper.

Unwrapped text that contains characters like <, >, {, or } causes MDX parsing failures because the parser treats them as JSX syntax.

Why Use This Rule?

  1. Prevents MDX build failures caused by special characters being parsed as JSX — for example, <code>Array<string></code> breaks because <string> is interpreted as a JSX opening tag.
  2. Catches the issue at lint time instead of at build time or runtime.
  3. Enforces a consistent pattern of wrapping text in {} expressions inside <code> elements.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Error fires on plain text without special characters — The rule flags all unwrapped text inside <code>, not just text with special characters. It is recommended to always use {} expression wrappers for consistency and to prevent future issues if the text changes.
  • Want to use backticks instead? — In prose, backtick syntax (`Array<string>`) is the simplest alternative and avoids the issue entirely.