@faircopy/core

中文文档
1.27.3发布于 2026/11/07MITTypeScriptES Module构建来源已验证近 30 天下载 1.3万

Core engine for faircopy — types, config loader, file resolver, rule runner

原始使用文档
文档目录10 节
  1. Install
  2. Public API
  3. loadConfig(cwd?)
  4. resolveFiles(config, cwd?)
  5. Ignore comments
  6. lintFile(filePath, source, adapters, rules)
  7. lintFileWithCoverage(filePath, source, adapters, rules)
  8. parseSeverity(ruleConfig)
  9. Key types
  10. Agent Output

@faircopy/core

Core engine for faircopy. Provides types, config loading, file resolution, and the rule runner. This package is for adapter and rule authors — most users should install faircopy instead.

Install

npm i @faircopy/core

Public API

loadConfig(cwd?)

Finds and loads faircopy.config.ts (or .js, .mjs, .cjs) via jiti. Throws ConfigError if no config is found.

import { loadConfig } from '@faircopy/core'
const { config, configPath } = await loadConfig(process.cwd())

loadConfigFile(filename) loads an exact config path with imports resolved relative to that file.

resolveFiles(config, cwd?)

Resolves file globs from config.files, respecting config.ignore and .gitignore.

Ignore comments

Suppress every rule for one source line with either directive:

// faircopy-ignore-next-line
<p>Intentional copy that would otherwise be reported.</p>

<p>Intentional copy.</p> {/* faircopy-ignore-line */}

Add comma-separated rule IDs to suppress only those rules:

// faircopy-ignore-next-line no-em-dash, no-weasel-words
<p>Intentional rule exceptions.</p>

The directives work with line, block, JSX, and HTML comment markers.

import { resolveFiles } from '@faircopy/core'
const files = await resolveFiles(config, cwd)

lintFile(filePath, source, adapters, rules)

Runs a set of resolved rules against a single file using the appropriate adapter.

import { lintFile } from '@faircopy/core'
const diagnostics = await lintFile(filePath, source, adapters, resolvedRules)

lintFileWithCoverage(filePath, source, adapters, rules)

Returns { diagnostics, coverage: { adapter, segments, characters } } from one extraction pass. adapter: null means the extension is unsupported. Zero segments/characters means no nonblank prose was extracted. Character counts use UTF-16 code units and include retained whitespace. lintFile() remains the diagnostics-only API for existing callers; use the coverage API when a clean result must also prove extraction scope.

parseSeverity(ruleConfig)

Parses a RuleConfig value into { severity, options }.

Key types

interface FaircopyConfig { files, ignore?, adapters?, rules, noGitignore?, concurrency? }
interface Adapter { name, extensions, extract(filePath, source) }
interface Rule<Opts> { id, description, check(input) }
interface Diagnostic { ruleId, severity, message, range, help?, suggest? }
interface ExtractedText { text, sourceMap, meta? }

See types.ts for the full schema.

Agent Output

@faircopy/core/reporting exposes reusable formatters for CLI, docs, and integrations:

import { formatAgentCompact, buildAgentJsonPayload } from '@faircopy/core/reporting'

formatAgentCompact() prints grouped diagnostics for coding agents. Snippets are enabled by default, character byte ranges are disabled by default, and both can be configured globally or per rule through output.agentCompact.

export default defineConfig({
  output: {
    agentCompact: {
      snippets: 'all',
      snippetChars: 140,
      chars: false,
      rules: {
        'no-em-dash': { snippets: 'first' },
      },
    },
  },
})

版本与发布记录

@faircopy/core 共发布 35 个版本,首次发布于 2026/04/23;过去 12 个月发布了 35 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.27.3latest2026/11/077 天前
1.27.22026/11/077 天前
1.27.12026/11/077 天前
1.27.02026/11/0410 天前
1.26.02026/10/2124 天前
1.25.02026/10/2025 天前

关于 @faircopy/core 的常见问题

@faircopy/core 是什么?

Core engine for faircopy — types, config loader, file resolver, rule runner

如何安装 @faircopy/core?

在项目目录运行 npm install @faircopy/core,或使用 pnpm add / yarn add / bun add。

@faircopy/core 支持 TypeScript 吗?

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

@faircopy/core 支持 ESM 还是 CommonJS?

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

@faircopy/core 可以商用吗?

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

@faircopy/core 的下载量有多少?

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

@faircopy/core 还在维护吗?

最新版本 1.27.3 发布于 2026/11/07(7 天前);至今共发布 35 个版本,其中过去 12 个月发布了 35 个;首次发布于 2026/04/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。