参考

Pluxel Oxlint 规则

用静态规则检查 Plugin 元数据、配置、资源归属和生命周期约束。

普通 Oxlint 检查 JavaScript 和 TypeScript 代码质量;@pluxel/rolldown/oxlint 继续检查只有 Pluxel 才理解的 Plugin 规则,例如元数据位置、配置读取时机和资源归属。

CLI 生成的插件包已经接入这些规则,先在包目录运行:

pnpm lint
pnpm lint:fix

修复后 pnpm lint 应成功,且没有 unused-disable 诊断。已有项目手动接入时,安装 oxlint@pluxel/rolldown 为开发依赖,再保存下面的配置为 oxlint.config.ts

pnpm exec oxlint -c oxlint.config.ts --report-unused-disable-directives-severity=error src tests

标准配置

import { , type OxlintConfig } from 'oxlint'
import {
	,
	,
	,
	,
} from '@pluxel/rolldown/oxlint'

type  = <OxlintConfig['rules']>

export default ({
	: [()],
	: [...],
	: { ...(() as ) },
})

重点规则

规则保护什么典型修复
plugin-base-class-requires-plugin-registrationconcrete Plugin 有 marker添加 @Plugin()
plugin-constructor-canonical-dependenciesrequired edge 有 root provenance从 package root value-import
configs-use-top-level-classconfig metadata 可提取把 field 放到 class 顶层
configs-use-no-private-fieldruntime 可以注入 config不使用 #private
configs-use-no-early-readconfig 已完成注入init() 之后读取
configs-use-no-redefaultschema 是唯一默认值来源移除额外的 fallback
configs-use-single-object-schema每个 Plugin 只有一个 schema合并成一个 object
plugin-no-process-exit退出策略属于 host抛出事实错误
no-direct-logtape-get-loggerlogger 保留 Context ownership使用 ctx.logger

Error log

记录完整错误对象,便于日志界面保留错误类型和堆栈:

try {
	await sync()
} catch (error) {
	this.ctx.logger.error('sync failed', { error })
}

不要插值 error、只记录 error.message,也不要把 failure 另造一套错误字段。

验证顺序

这些规则运行在 Pluxel/Vite build-correctness pipeline 中,依赖 package-root provenance 和 source semantics;普通 tsc 无法替代。

  1. 运行 pnpm lint:fix,应用安全的 import、字段名和 re-default 修复。
  2. 按 semantic 诊断修正 Plugin metadata、配置和 lifecycle 边界。
  3. 运行 pnpm verify,确认没有 unused disable。

不要用大范围 disable 绕过规则。若确有误报,保留最小范围、说明原因,并让 unused-disable 检查仍然开启。

最后更新于

本页目录