@bfra.me/eslint-config

中文文档
0.54.0发布于 2026/09/26MITTypeScriptES Module近 30 天下载 1.7万

Shared ESLint configuration for bfra.me

原始使用文档
文档目录16 节
  1. Install
  2. NPM
  3. PNPM
  4. Yarn
  5. Usage
  6. Markdown Support
  7. Quick Start
  8. Language Modes: CommonMark vs GFM
  9. Frontmatter Parsing
  10. Code Block Processing
  11. Disable Directives in Markdown
  12. Configuration Examples
  13. Default Rules
  14. Migrating from Simple Configuration
  15. Troubleshooting
  16. License

@bfra.me/eslint-config

Shared ESLint configuration for bfra.me.

Install

NPM

npm install --save-dev @bfra.me/eslint-config eslint

PNPM

pnpm add --save-dev @bfra.me/eslint-config eslint

Yarn

yarn add --dev @bfra.me/eslint-config eslint

Usage

Add or update your eslint.config.js file to include the following:

import preset from "@bfra.me/eslint-config"

export default preset()

Markdown Support

Lint your Markdown files with support for both CommonMark and GitHub Flavored Markdown (GFM). Parse frontmatter in YAML, TOML, or JSON formats, and optionally lint code blocks within your documentation. Built on the official @eslint/markdown plugin.

Quick Start

import {defineConfig} from "@bfra.me/eslint-config"

// Enable with defaults (GFM + YAML frontmatter)
export default defineConfig({
  markdown: true
})

Language Modes: CommonMark vs GFM

Choose the Markdown parsing mode that fits your use case:

CommonMark (Standard)

Use CommonMark for maximum portability and strict compliance with the standard specification:

export default defineConfig({
  markdown: {
    language: 'commonmark'
  }
})

Best for:

  • README files
  • Portable documentation
  • Cross-platform content
  • Strict Markdown compliance

GitHub Flavored Markdown (GFM)

Use GFM for enhanced features commonly used in GitHub and documentation sites:

export default defineConfig({
  markdown: {
    language: 'gfm'
  }
})

Adds support for:

  • Tables
  • Task lists (- [ ] Todo item)
  • Strikethrough (~~deleted text~~)
  • Autolinks (automatic URL linking)

Best for:

  • Documentation sites
  • GitHub README files
  • Blog posts
  • Wiki pages

GFM is the default mode when you enable Markdown support.

Frontmatter Parsing

Most static site generators (Astro, Next.js, Jekyll) use frontmatter to store metadata at the top of Markdown files. You can configure which format to parse—or disable it entirely.

export default defineConfig({
  markdown: {
    frontmatter: 'yaml'
  }
})

Example Markdown file with YAML frontmatter:

---
title: Getting Started
date: 2025-11-20
tags: [tutorial, documentation]
---

# Getting Started

Your content here...

Best for:

  • Documentation sites (Astro, Docusaurus, VitePress)
  • Blog posts
  • Most static site generators

TOML Frontmatter

export default defineConfig({
  markdown: {
    frontmatter: 'toml'
  }
})

Example Markdown file with TOML frontmatter:

+++
title = "Getting Started"
date = 2025-11-20
tags = ["tutorial", "documentation"]
+++

# Getting Started

Your content here...

Best for:

  • Hugo sites
  • Configuration-heavy frontmatter

JSON Frontmatter

export default defineConfig({
  markdown: {
    frontmatter: 'json'
  }
})

Example Markdown file with JSON frontmatter:

;;;
{
  "title": "Getting Started",
  "date": "2025-11-20",
  "tags": ["tutorial", "documentation"]
}
;;;

# Getting Started

Your content here...

Disable Frontmatter

For simple Markdown files without metadata:

export default defineConfig({
  markdown: {
    frontmatter: false
  }
})

YAML is the default frontmatter format when you enable Markdown support.

Code Block Processing

Enable Code Block Linting

export default defineConfig({
  markdown: {
    codeBlocks: {
      typescript: true,
      javascript: true,
      jsx: true,
      json: true,
      yaml: true
    }
  }
})

With code block processing enabled (the default), fenced code blocks are extracted and linted as separate virtual files:

# Example

```typescript
// This TypeScript code will be linted with TypeScript rules
interface User {
  name: string
  age: number
}

const user: User = {
  name: "John",
  age: 30
}
```

Filename Meta Support

Use filename annotations for better error reporting:

```typescript filename="src/user.ts"
export interface User {
  name: string
  age: number
}
```

The linter will treat this code block as if it were in src/user.ts for error messages and rule contexts.

Supported Languages in Code Blocks

The following languages are supported:

  • TypeScript (.ts, .tsx) - Full TypeScript-ESLint support
  • JavaScript (.js, .jsx) - ES modules, async/await, modern syntax
  • JSX/TSX - React components with proper linting
  • JSON - JSON/JSON5 syntax validation
  • YAML - YAML syntax validation

Disable Directives in Markdown

Use HTML comments to disable ESLint rules within Markdown files:

<!-- eslint-disable markdown/no-html -->

<div>Custom HTML content</div>

<!-- eslint-enable markdown/no-html -->

Configuration Examples

Documentation Site (Astro, Docusaurus, VitePress)

import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'gfm',
    frontmatter: 'yaml',
    codeBlocks: {
      typescript: true,
      javascript: true
    }
  }
})

Simple README Files

import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'commonmark',
    frontmatter: false,
    files: ['README.md', '**/README.md']
  }
})

Blog Posts with Code Examples

import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'gfm',
    frontmatter: 'yaml',
    codeBlocks: {
      typescript: true,
      javascript: true,
      jsx: true
    },
    files: ['blog/**/*.md', 'posts/**/*.md']
  }
})

Custom Rule Overrides

import {defineConfig} from "@bfra.me/eslint-config"

export default defineConfig({
  markdown: {
    language: 'gfm',
    rules: {
      // Allow HTML in Markdown
      'markdown/no-html': 'off',
      // Warn on missing code block languages
      'markdown/fenced-code-language': 'warn',
      // Enforce alt text for images
      'markdown/require-alt-text': 'error'
    }
  }
})

Default Rules

These rules are enabled out of the box to catch common Markdown issues:

  • markdown/fenced-code-language - Require language identifiers on fenced code blocks
  • markdown/heading-increment - Enforce proper heading level increments
  • markdown/no-duplicate-definitions - Prevent duplicate link/image definitions
  • markdown/no-empty-definitions - Prevent empty link/image definitions
  • markdown/no-empty-images - Prevent empty image alt text
  • markdown/no-empty-links - Prevent empty link text
  • markdown/no-invalid-label-refs - Prevent invalid reference-style links
  • markdown/no-missing-label-refs - Prevent missing reference definitions
  • markdown/no-missing-link-fragments - Validate heading fragment links
  • markdown/no-multiple-h1 - Enforce single h1 heading per file
  • markdown/no-unused-definitions - Prevent unused link/image definitions
  • markdown/require-alt-text - Require alt text for images
  • markdown/table-column-count - Validate table column consistency

Migrating from Simple Configuration

The simple boolean form still works:

// Simple form
export default defineConfig({
  markdown: true
})

This is equivalent to:

// Explicit defaults
export default defineConfig({
  markdown: {
    language: 'gfm',
    frontmatter: 'yaml',
    codeBlocks: {
      javascript: true,
      json: true,
      jsx: true,
      typescript: true,
      yaml: true
    }
  }
})

You only need the expanded form if you want to customize these defaults.

Troubleshooting

Code Block Processing Issues

Running into issues with code block extraction? Try these fixes:

  1. Selectively enable languages that work in your environment:

    export default defineConfig({
     markdown: {
       codeBlocks: {
         typescript: true,
         javascript: true,
         jsx: false,  // Disable if causing issues
         json: false,
         yaml: false
       }
     }
    })
    
  2. Check for plugin conflicts - some ESLint plugins require full SourceCode API that isn't available in virtual code block files

Frontmatter Parsing Errors

Frontmatter not parsing correctly? Check these common issues:

  • Verify delimiters: --- for YAML, +++ for TOML, ;;; for JSON
  • Validate your frontmatter syntax with a dedicated parser
  • If you don't need frontmatter, disable it: frontmatter: false

Performance Issues

Linting taking too long? Here's how to speed things up:

  • Target specific directories: files: ['docs/**/*.md']

  • Exclude generated docs using the ignores option:

    export default defineConfig({
      ignores: ['docs/api/**/*.md', '**/CHANGELOG.md']
    })
    

License

MIT

版本与发布记录

@bfra.me/eslint-config 共发布 128 个版本,首次发布于 2024/10/01;过去 12 个月发布了 39 个版本。

版本发布日期距今
0.54.0latest2026/09/261 个月前
0.52.22026/09/141 个月前
0.52.12026/08/262 个月前
0.52.02026/08/252 个月前
0.51.42026/08/242 个月前
0.51.32026/08/242 个月前

关于 @bfra.me/eslint-config 的常见问题

@bfra.me/eslint-config 是什么?

Shared ESLint configuration for bfra.me

如何安装 @bfra.me/eslint-config?

在项目目录运行 npm install @bfra.me/eslint-config,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(^10.4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bfra.me/eslint-config 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bfra.me/eslint-config 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bfra.me/eslint-config 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.22.2 || >=24.15.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bfra.me/eslint-config 可以商用吗?

@bfra.me/eslint-config 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bfra.me/eslint-config 的下载量有多少?

根据 npm 官方下载统计,@bfra.me/eslint-config 在 2026/10/08 – 2026/11/06 这 30 天内被下载 16,907 次,日均约 564 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bfra.me/eslint-config 还在维护吗?

最新版本 0.54.0 发布于 2026/09/26(1 个月前);至今共发布 128 个版本,其中过去 12 个月发布了 39 个;首次发布于 2024/10/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。