@harness-engineering/linter-gen

中文文档
0.2.0发布于 2026/11/12MITTypeScriptES Module构建来源已验证近 30 天下载 9348

Generate ESLint rules from YAML configuration

原始使用文档
文档目录15 节
  1. Installation
  2. Usage
  3. Configuration
  4. CLI
  5. Programmatic API
  6. Built-in Templates
  7. import-restriction
  8. boundary-validation
  9. dependency-graph
  10. Custom Templates
  11. Convention-based
  12. Explicit paths
  13. Template Context
  14. Handlebars Helpers
  15. License

@harness-engineering/linter-gen

Generate ESLint rules from YAML configuration using extensible Handlebars templates.

Installation

pnpm add @harness-engineering/linter-gen

Usage

Configuration

Create 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'

CLI

# Generate rules
harness linter generate

# Generate with options
harness linter generate --config ./custom-config.yml --output ./rules --clean

# Validate config only
harness linter validate

Programmatic 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' });

Built-in Templates

import-restriction

Block imports matching patterns in files matching a source pattern.

- name: no-react-in-services
  type: import-restriction
  config:
    source: 'src/services/**'
    forbiddenImports:
      - 'react'
      - 'react-dom'
    message: 'Service files cannot import React'

boundary-validation

Ensure files export Zod schemas for validation.

- name: api-must-validate
  type: boundary-validation
  config:
    pattern: 'src/api/**/*.ts'
    requireZodSchema: true
    message: 'API endpoints must use Zod validation'

dependency-graph

Detect circular import dependencies.

- name: no-cycles
  type: dependency-graph
  config:
    entryPoints:
      - 'src/index.ts'
    exclude:
      - '**/*.test.ts'
    maxDepth: 20

Custom Templates

Convention-based

Place templates in templates/ directory relative to config:

project/
├── harness-linter.yml
└── templates/
    └── my-custom-type.ts.hbs

Explicit paths

Specify template paths in config:

templates:
  my-custom-type: ./custom-templates/my-rule.ts.hbs

Template Context

Templates receive:

{
  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',
  }
}

Handlebars Helpers

  • {{json value}} - JSON.stringify
  • {{jsonPretty value}} - JSON.stringify with formatting
  • {{camelCase "kebab-name"}} - Convert to camelCase
  • {{pascalCase "kebab-name"}} - Convert to PascalCase

License

MIT

版本与发布记录

@harness-engineering/linter-gen 共发布 10 个版本,首次发布于 2026/03/17;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/11/125 天前
0.1.82026/10/2027 天前
0.1.72026/04/256 个月前
0.1.62026/04/107 个月前
0.1.52026/04/087 个月前
0.1.42026/03/287 个月前

关于 @harness-engineering/linter-gen 的常见问题

@harness-engineering/linter-gen 是什么?

Generate ESLint rules from YAML configuration

如何安装 @harness-engineering/linter-gen?

在项目目录运行 npm install @harness-engineering/linter-gen,或使用 pnpm add / yarn add / bun add。

@harness-engineering/linter-gen 支持 TypeScript 吗?

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

@harness-engineering/linter-gen 支持 ESM 还是 CommonJS?

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

@harness-engineering/linter-gen 可以商用吗?

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

@harness-engineering/linter-gen 的下载量有多少?

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

@harness-engineering/linter-gen 还在维护吗?

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