standard-markdown

raw JSON →
7.1.0 verified Sat Apr 25 auth: no javascript

Test your Markdown files for Standard JavaScript Style™. Current stable version is 7.1.0 (requires Node >=11). Release cadence is sporadic, with major versions bumping the underlying `standard` dependency. Key differentiators: it lints JavaScript code blocks inside Markdown files (GitHub-Flavored `js`/`javascript` blocks), disables certain rules inappropriate for inline code (e.g., no-undef, no-unused-vars), and supports auto-fixing via `standard`. Alternatives include `remark-lint` for general Markdown linting or manual extraction of code blocks.

error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/standard-markdown not supported.
cause Using require() on an ESM-only package in Node.js <12 or with CJS module system.
fix
Use import syntax, or use dynamic import(): const standardMarkdown = await import('standard-markdown').
error TypeError: standardMarkdown.lintFiles is not a function
cause Importing the default export (which no longer exists) instead of named exports.
fix
Use import { lintFiles } from 'standard-markdown' instead of import standardMarkdown from 'standard-markdown'.
error Error: Cannot find module 'standard-markdown'
cause Package not installed or not in node_modules.
fix
Run npm install standard-markdown or check your package.json dependencies.
breaking standard-markdown v7.0.0 drops support for Node.js versions below 11.
fix Upgrade Node.js to >=11.
breaking standard-markdown v6.0.0 drops support for Node.js 6.
fix Upgrade Node.js to >=8.
breaking standard-markdown v7.0.0 is ESM-only; require() will fail with ERR_REQUIRE_ESM.
fix Use import syntax or switch to dynamic import().
gotcha standard-markdown disables several rules (no-undef, no-unused-vars) that may give false sense of security for code blocks.
fix Manually review code blocks for correctness beyond style.
breaking The default export was removed; lint and lintFiles are now named exports.
fix Switch from default import to named imports: import { lint } from 'standard-markdown'.
npm install standard-markdown
yarn add standard-markdown
pnpm add standard-markdown

Lints all .md files in the docs directory (except api subdirectory) using standard-markdown programmatically with ESM imports and async/await.

import { lintFiles } from 'standard-markdown'

async function lintMarkdownFiles() {
  try {
    const results = await lintFiles(['docs/**/*.md', '!docs/api/**/*.md'])
    if (results.length === 0) {
      console.log('No lint errors found.')
    } else {
      results.forEach(result => {
        console.log(`File: ${result.filePath}`)
        result.messages.forEach(msg => {
          console.log(`  Line ${msg.line}: ${msg.message}`)
        })
      })
    }
  } catch (err) {
    console.error('Linting failed:', err)
  }
}

lintMarkdownFiles()