@accordproject/concerto-linter-default-ruleset

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

Default ruleset for the Accord Project Concerto Linter

原始使用文档
文档目录12 节
  1. Table of Contents
  2. Key Benefits
  3. Available Rules
  4. Installation
  5. Usage
  6. Customization
  7. Extending the Default Ruleset
  8. Disabling Specific Rules
  9. Enabling Specific Rules
  10. Adjusting Rule Severity
  11. Creating Custom Rules
  12. License

Concerto Linter Default Ruleset

A comprehensive set of linting rules designed to validate concerto models against industry best practices and consistent naming conventions. This default ruleset helps maintain high-quality, readable, and maintainable concerto models across your projects. It is fully configurable - you can extend it, add new rules, disable existing ones, or create an entirely new ruleset without extending this one.

This sub-package is part of the @accordproject/concerto-linter package. Read the concerto-linter README if you want to know how to use this ruleset with concerto models.

Table of Contents

Key Benefits

  • Consistent Code Style: Enforce uniform naming conventions across your concerto models
  • Error Prevention: Catch common modeling mistakes before they cause issues
  • Best Practices: Apply industry-standard modeling practices automatically
  • Customizable: Easily extend or modify rules to match your project's specific needs
  • Integration Ready: Works seamlessly with the concerto Linter and your development workflow

Available Rules

The following table provides an overview of the available linting rules in the default ruleset:

Rule IdDescription
namespace-version Ensures that the namespace declaration in the model includes a version number. This rule enforces semantic versioning in namespaces, promoting clarity and compatibility management.
no-reserved-keywords Enforces that names used for declarations, properties, and decorators in concerto models do not use reserved keywords. Reserved keywords are language-specific terms that may cause conflicts or unexpected behavior if used as identifiers.
pascal-case-declarations Ensures that declaration names (scalar, enum, concept, asset, participant, transaction, event) follow PascalCase naming convention (e.g., 'MyDeclaration'). This promotes consistency and readability across model declarations.
camel-case-properties Ensures that properties of type String, Double, Integer, Long, DateTime, and Boolean are named using camelCase. This promotes consistency and readability in property naming conventions across the model.
upper-snake-case-enum-constants Enforces that all enum constant names follow the UPPER_SNAKE_CASE convention. This rule checks each enum property name and reports an error if it does not match the required pattern. Ensures consistency and readability in enum naming across the model.
pascal-case-decorators Ensures that decorator names follow PascalCase naming convention (e.g., 'MyDecorator'). This promotes consistency and readability across model decorators.
string-length-validator Ensures that all string properties within the data model have a length validator applied, which helps prevent inconsistent data length and ensure proper storage.
no-empty-declarations Detects and reports any model declarations that are empty. This rule helps maintain model integrity by ensuring that all declarations contain meaningful content, preventing the inclusion of unused or placeholder declarations in the model.
abstract-must-subclassed Ensures that every abstract declaration in the model has at least one concrete subclass. This helps prevent unused or orphaned abstract types, enforcing better model design.

Installation

First, install the package as a development dependency:

npm install --save-dev @accordproject/concerto-linter-default-ruleset

Usage

Once installed, the default ruleset is automatically used by the concerto Linter when no custom ruleset is specified:

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

// The default ruleset will be used automatically
const results = await lintModel(modelText);
console.log(results);

To explicitly specify the default ruleset:

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

Customization

To create your own ruleset that fits your project needs, you can either extend the default ruleset, or create an entirely new ruleset from scratch.

Your ruleset should be defined in one of these file formats: .spectral.yaml, .spectral.yml, .spectral.json, or .spectral.js. The concerto Linter will automatically detect and use these files, or you can specify a custom path using the ruleset property: ruleset: "./path/to/my-ruleset.yaml".

Extending the Default Ruleset

You can extend the default ruleset in multiple formats:

YAML (.spectral.yaml)

extends: '@accordproject/concerto-linter-default-ruleset'

JSON (.spectral.json)

{
  "extends": "@accordproject/concerto-linter-default-ruleset"
}

JavaScript (.spectral.js)

const rules = require('@accordproject/concerto-linter-default-ruleset');
module.exports = {
  extends: rules
};

Disabling Specific Rules

You can disable specific rules that don't match your project's requirements by setting them to 'off'. The rule identifiers are defined in the ruleset-main.ts file located at concerto/packages/concerto-linter/default-ruleset/src.

Available Rule IDs

Here are all the rule IDs that can be disabled:

Rule IDDescription
namespace-versionEnsures namespaces include version numbers
no-reserved-keywordsPrevents use of reserved keywords
pascal-case-declarationsEnforces PascalCase for declarations
camel-case-propertiesEnforces camelCase for properties
upper-snake-case-enum-constantsEnforces UPPER_SNAKE_CASE for enum constants
pascal-case-decoratorsEnforces PascalCase for decorators
string-length-validatorRequires string length validators
no-empty-declarationsPrevents empty declarations
abstract-must-subclassedEnsures abstract classes have concrete subclasses

YAML (.spectral.yaml)

extends: '@accordproject/concerto-linter-default-ruleset'
rules:
  pascal-case-declarations: 'off'
  camel-case-properties: 'off'

JSON (.spectral.json)

{
  "extends": "@accordproject/concerto-linter-default-ruleset",
  "rules": {
    "pascal-case-declarations": "off",
    "camel-case-properties": "off"
  }
}

JavaScript (.spectral.js)

const rules = require('@accordproject/concerto-linter-default-ruleset');
module.exports = {
  extends: rules,
  rules: {
    'pascal-case-declarations': off,
    'namespace-version': off
  }
};

Enabling Specific Rules

You can selectively start with everything off and enable only specific rules:

YAML (.spectral.yaml)

extends: [['@accordproject/concerto-linter-default-ruleset', 'off']]
rules:
  pascal-case-declarations: true
  namespace-version: true

JSON (.spectral.json)

{
  "extends": [["@accordproject/concerto-linter-default-ruleset", "off"]],
  "rules": {
    "pascal-case-declarations": true,
    "namespace-version": true
  }
}

JavaScript (.spectral.js)

const rules = require('@accordproject/concerto-linter-default-ruleset');
module.exports = {
  extends: [[rules, 'off']],
  rules: {
    'pascal-case-declarations': true,
    'namespace-version': true
  }
};

Adjusting Rule Severity

You can customize the severity level of each rule to control how violations are reported.

  • 0 = error (must be fixed)
  • 1 = warn (should be addressed)
  • 2 = info (useful information)
  • 3 = hint (optional suggestion)

YAML (.spectral.yaml)

extends: '@accordproject/concerto-linter-default-ruleset'
rules:
  pascal-case-declarations: 'warn'  # Change from error to warning
  camel-case-properties: 'info'     # Change to informational

JSON (.spectral.json)

{
  "extends": "@accordproject/concerto-linter-default-ruleset",
  "rules": {
    "pascal-case-declarations": "warn",
    "camel-case-properties": "info"
  }
}

JavaScript (.spectral.js)

const rules = require('@accordproject/concerto-linter-default-ruleset');
module.exports = {
  extends: rules,
  rules: {
    'pascal-case-declarations': 'warn',
    'camel-case-properties': 'info'
  }
};

Creating Custom Rules

Whether you want to add new rules to the default ruleset or create an entirely new ruleset, you can follow the Spectral ruleset format. For comprehensive documentation, see the Spectral ruleset documentation.

Here's a simple example of what a custom rule looks like:

# description (optional): Explains what the ruleset is about.
description: "Declaration names (scalar, enum, concept, asset, participant, transaction, event) should be PascalCase."

# given (required): JSONPath expression that specifies where the rule applies.
given: "$.models[*].declarations[*].name"

# message (required): The error/warning message shown when the rule is violated.
message: "Declaration '{{value}}' should be PascalCase (e.g. 'MyDeclaration')"

# severity (optional): The level of violation.
# 0 = error, 1 = warning, 2 = info, 3 = hint
severity: 0

# then (required): Defines what function to apply and how.
then:
  # function (required): The function that validates the rule.
  function: casing

  # functionOptions (optional): Extra options for the function.
  functionOptions:
    type: pascal

For more complex rules, you can create custom JavaScript functions following Spectral ruleset documentation and import it into your rule, similar to how the built-in rules work.

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-default-ruleset 共发布 47 个版本,首次发布于 2025/07/16;过去 12 个月发布了 25 个版本。最新版本附带 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-default-ruleset 的常见问题

@accordproject/concerto-linter-default-ruleset 是什么?

Default ruleset for the Accord Project Concerto Linter

如何安装 @accordproject/concerto-linter-default-ruleset?

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

@accordproject/concerto-linter-default-ruleset 支持 TypeScript 吗?

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

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

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

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

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

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

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

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

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

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

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