每个团队都有工具、模式和规范。问题是什么?没人能全部记住。
你即将编写的功能已经存在——何必重新发明轮子?
你的团队有既定的做事方式——这段代码却不一样
相同的概念使用不同的名称,或不同的概念使用相同的名称
你的代码库中隐藏着更好的抽象——用起来吧
一致性检查器的真实建议
// New code in UserProfile.tsx
function formatDate(date: Date): string {
const day = date.getDate().toString().padStart(2, '0')
const month = (date.getMonth() + 1).toString().padStart(2, '0')
const year = date.getFullYear()
return `${day}/${month}/${year}`
}重新实现 formatDate——你在 lib/date-utils.ts 已经有了
// Use existing utility
import { formatDate } from '@/lib/date-utils'
// Already handles localization, timezones, and edge cases
formatDate(date, 'short')复用已经处理边缘情况的现有工具
// Inconsistent error handling
try {
const data = await fetchUser(id)
return data
} catch (e) {
console.error(e)
return null
}错误处理方式与代码库其他部分不同
// Matches team pattern
import { withErrorHandler } from '@/lib/api'
const data = await withErrorHandler(
() => fetchUser(id),
{ fallback: null, context: 'UserProfile' }
)使用团队已建立的错误处理模式
// Custom loading state
{isLoading ? (
<div className="flex items-center justify-center p-8">
<div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary" />
</div>
) : (
<UserList users={users} />
)}自定义加载动画——你有 LoadingState 组件
// Use shared component
import { LoadingState } from '@/components/ui/loading-state'
<LoadingState isLoading={isLoading}>
<UserList users={users} />
</LoadingState>复用共享组件以保持一致的用户体验
一致性检查器学习你的代码库——现有的工具、已建立的模式、 命名规范。然后利用这些知识引导每个 PR 保持一致性。
理解哪些工具和辅助函数已经存在
识别你的团队如何组织代码
指向现有代码而不是重新发明
学习你的代码库
理解现有的模式、工具和规范
分析新代码
与项目中已建立的模式进行比较
发现相似性
识别你正在解决一个已解决的问题
建议复用
指向现有代码并解释如何使用
永不遗忘、随时帮助的队友
新团队成员通过实时建议学习模式,而不仅仅是文档
100 位开发者像一个团队一样编写代码,共享规范
在重复代码蔓延到整个项目之前捕获它
新人入职?没问题。
一致性检查器实时教会你的模式。