@accordproject/concerto-linter

中文文档
5.2.1发布于 2026/10/18Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 1.3万

Concerto Linter using Spectral rulesets

原始使用文档
文档目录18 节
  1. Table of contents
  2. Features
  3. Model Input
  4. Ruleset Discovery
  5. Ruleset Flexibility
  6. Namespace Filtering
  7. JSON Output
  8. Getting Started
  9. Installation
  10. Providing the concerto Model
  11. Ruleset Configuration
  12. Default Ruleset
  13. Custom Rulesets
  14. Automatic Ruleset Discovery
  15. Creating Custom Rulesets
  16. The linter output
  17. Namespace Filtering
  18. License

concerto linter

The linter provide the lintModel function which provides a robust and efficient solution for linting Concerto models using Spectral. It ensures your models adhere to predefined or custom rulesets, promoting consistency, quality, and maintainability in your codebase.

Table of contents

Features

Model Input

  • Versatile Model Input: Supports concerto models provided as either a CTO string or a parsed Abstract Syntax Tree (AST) object.

Ruleset Discovery

  • Automatic Ruleset Discovery: Automatically detects Spectral ruleset files (e.g., .spectral.yaml, .spectral.yml, .spectral.json, .spectral.js) in the current or parent directories when no explicit ruleset is specified.

Ruleset Flexibility

  • Custom Ruleset Flexibility: Enables the use of a custom Spectral ruleset by allowing you to specify its file path for tailored linting rules.

Namespace Filtering

  • Namespace Filtering: Filters linting results by namespace, with configurable exclusion patterns. By default, excludes 'concerto.*' and 'org.accordproject.*' namespaces.

JSON Output

  • Structured JSON Output: Returns linting results in a consistent JSON format for easier integration with other tools and workflows.

Getting Started

The linter is highly customizable. By default, it will lint any Concerto model using the @accordproject/concerto-linter-default-ruleset, but you can also extend it or create your own custom ruleset.

Installation

Install the package via npm:

npm install @accordproject/concerto-linter

Providing the concerto Model

The lintModel function accepts your Concerto model in one of two formats:

As a CTO String

const model = `
namespace org.example
asset MyProduct {
  o String ProductId
}
`;

As a Parsed AST Object

import { ModelManager } from '@accordproject/concerto-core';

const modelManager = new ModelManager();
const model = `
namespace org.example
asset MyProduct {
  o String ProductId
}
`;
modelManager.addCTOModel(model);
const ast = modelManager.getAst();

Ruleset Configuration

The concerto Linter provides flexible ruleset configuration options to suit your project needs.

Default Ruleset

By default, the linter uses @accordproject/concerto-linter-default-ruleset, which provides a comprehensive set of rules for concerto models. This ruleset is automatically applied when no custom ruleset is specified.

Custom Rulesets

You can customize the linting rules in several ways:

  1. Create a ruleset file in your project directory using any of these supported formats:

    • .spectral.yaml
    • .spectral.yml
    • .spectral.json
    • .spectral.js
  2. Specify a ruleset path explicitly when calling the linter:

    const results = await lintModel(ast, {ruleset: 'path/to/your/custom-ruleset.yaml'});
    
  3. Force the default ruleset

    const results = await lintModel(ast, {ruleset: 'default'});
    

Automatic Ruleset Discovery

When you call lintModel without specifying a ruleset, the linter will automatically search for ruleset files in the following order:

  1. .spectral.yaml
  2. .spectral.yml
  3. .spectral.json
  4. .spectral.js

If you want to force the linter to use the built-in default ruleset even when custom ruleset files are present in the project, pass ruleset: 'default' in the options:

import { lintModel } from '@accordproject/concerto-linter';

const results = await lintModel(ast, { ruleset: 'default' });

If none of these files are found in the current or parent directories, the linter will fall back to using the default ruleset (@accordproject/concerto-linter-default-ruleset).

import { lintModel } from '@accordproject/concerto-linter';

// The linter will automatically detect ruleset files in your project
const results = await lintModel(ast); // Pass the AST object
// OR
const results = await lintModel(model); // Pass the CTO string directly

Creating Custom Rulesets

You can create your own custom ruleset to enforce specific rules for your Concerto models. For detailed guidance on creating custom rulesets, refer to the default-ruleset documentation.

Custom rulesets follow the Spectral ruleset format and can be created in YAML, JSON, or JavaScript. Once created, the linter will automatically detect your ruleset file if it uses one of the standard names, or you can explicitly specify its path as shown in the examples above.

The linter output

The lintModel function returns a Promise that resolves to an array of linting results in JSON format:

Each lint issue is represented as a flat JSON object:

interface ILintResult {
  /** Unique rule identifier (e.g. 'no-unused-concept') */
  code: string;

  /** Human-readable description of the violation */
  message: string;

  /** Severity level ('error' | 'warning' | 'info' | 'hint') */
  severity: string;

  /**
   * JSONPath-style pointer as an array of keys/indices
   * (e.g. ['declarations', 3])
   */
  path: Array<string | number>;

  /** Namespace where the violation occurred (e.g. 'org.accordproject') */
  namespace: string;

}

Example Output :

[
  {
    "code": "camel-case-properties",
    "message": "Property 'FirstVal' should be camelCase (e.g. 'myProperty').",
    "severity": "warning",
    "path": ["declarations", 3],
    "namespace": "org.example.model",
    "source": "concerto-lintr"
  }

Namespace Filtering

By default, results from namespaces matching 'concerto.*' and 'org.accordproject.*' are excluded from the output. You can customize this behavior using the excludeNamespaces option.

// Override default namespace exclusions
const results = await lintModel(ast, { 
  excludeNamespaces: ['org.example.*', 'com.acme.*'] 
});

// Combine custom ruleset and namespace filtering
const results = await lintModel(ast, {
  ruleset: "D:\\linter-test\\my-ruleset.yaml",
  excludeNamespaces: ['org.example.*']
});

License

Accord Project source code files are made available under the Apache License, Version 2.0 (Apache-2.0), located in the LICENSE file. Accord Project documentation files are made available under the Creative Commons Attribution 4.0 International License (CC-BY-4.0).

版本与发布记录

@accordproject/concerto-linter 共发布 50 个版本,首次发布于 2025/06/19;过去 12 个月发布了 26 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.1latest2026/10/1819 天前
5.2.02026/10/1620 天前
5.1.02026/10/0630 天前
5.0.02026/09/081 个月前
5.0.0-beta.3unstable2026/09/081 个月前
5.0.0-beta.22026/09/081 个月前

关于 @accordproject/concerto-linter 的常见问题

@accordproject/concerto-linter 是什么?

Concerto Linter using Spectral rulesets

如何安装 @accordproject/concerto-linter?

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

@accordproject/concerto-linter 支持 TypeScript 吗?

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

@accordproject/concerto-linter 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@accordproject/concerto-linter 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@accordproject/concerto-linter 可以商用吗?

@accordproject/concerto-linter 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@accordproject/concerto-linter 的下载量有多少?

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

@accordproject/concerto-linter 还在维护吗?

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