@harness-engineering/linter-gen (英语)
使用可扩展的 Handlebars 模板从 YAML 配置生成 ESLint 规则 .
安装
pnpm add @harness-engineering/linter-gen
使用量
配置
创建 harness-linter.yml数字 :
version: 1
output: ./generated/eslint-rules
rules:
- name: no-ui-in-services
type: import-restriction
severity: error
config:
source: 'src/services/**'
forbiddenImports:
- 'react'
- 'src/ui/**'
message: 'Service layer cannot import UI code'
国 际
# Generate rules
harness linter generate
# Generate with options
harness linter generate --config ./custom-config.yml --output ./rules --clean
# Validate config only
harness linter validate
程序化 API
import { generate, validate } from '@harness-engineering/linter-gen';
// Generate rules
const result = await generate({
configPath: './harness-linter.yml',
outputDir: './generated',
clean: true,
});
if (result.success) {
console.log(`Generated ${result.rulesGenerated.length} rules`);
}
// Validate config
const validation = await validate({ configPath: './harness-linter.yml' });
内建模板
导入限制
在匹配源模式的文件中块导入匹配模式 .
- name: no-react-in-services
type: import-restriction
config:
source: 'src/services/**'
forbiddenImports:
- 'react'
- 'react-dom'
message: 'Service files cannot import React'
边界验证
确保文件导出 Zod schemas 进行校验 .
- name: api-must-validate
type: boundary-validation
config:
pattern: 'src/api/**/*.ts'
requireZodSchema: true
message: 'API endpoints must use Zod validation'
依赖图
检测循环导入依赖性 .
- name: no-cycles
type: dependency-graph
config:
entryPoints:
- 'src/index.ts'
exclude:
- '**/*.test.ts'
maxDepth: 20
自定义模板
以《公约》为基础
将模板放入 templates/ 相对于配置的目录 :
project/
├── harness-linter.yml
└── templates/
└── my-custom-type.ts.hbs
明确路径
在配置中指定模板路径 :
templates:
my-custom-type: ./custom-templates/my-rule.ts.hbs
模板上下文
模板接收 :
{
name: 'rule-name', // kebab-case
nameCamel: 'ruleName', // camelCase
namePascal: 'RuleName', // PascalCase
severity: 'error', // error | warn | off
config: { ... }, // Template-specific config
meta: {
generatedAt: '2026-03-13T...',
generatorVersion: '0.1.0',
configPath: '/path/to/config.yml',
}
}
处理栏助手
{{json value}}- JSON,快说{{jsonPretty value}}- JSON. 弦与格式化{{camelCase "kebab-name"}}- 转换为骆驼Case{{pascalCase "kebab-name"}}- 转换为PascalCase
许可证
麻省理工学院