@accordproject/concerto-linter 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/.eslintignore +20 -0
  2. package/.eslintrc.yml +45 -0
  3. package/HEADER.md +2 -0
  4. package/README.md +207 -0
  5. package/default-ruleset/.eslintignore +20 -0
  6. package/default-ruleset/.eslintrc.yml +45 -0
  7. package/default-ruleset/README.md +300 -0
  8. package/default-ruleset/jest.config.js +7 -0
  9. package/default-ruleset/package.json +51 -0
  10. package/default-ruleset/src/abstract-must-subclassed.ts +29 -0
  11. package/default-ruleset/src/camel-case-properties.ts +35 -0
  12. package/default-ruleset/src/functions/check-length-validator.ts +52 -0
  13. package/default-ruleset/src/functions/find-abstract-declaration.ts +70 -0
  14. package/default-ruleset/src/functions/find-empty-declarations.ts +56 -0
  15. package/default-ruleset/src/namespace-version.ts +35 -0
  16. package/default-ruleset/src/no-empty-declarations.ts +31 -0
  17. package/default-ruleset/src/no-reserved-keywords.ts +43 -0
  18. package/default-ruleset/src/pascal-case-declarations.ts +35 -0
  19. package/default-ruleset/src/pascal-case-decorators.ts +38 -0
  20. package/default-ruleset/src/ruleset-main.ts +41 -0
  21. package/default-ruleset/src/string-length-validator.ts +32 -0
  22. package/default-ruleset/src/upper-snake-case-enum-const.ts +36 -0
  23. package/default-ruleset/test/fixtures/ENUM_Constans-invaild.cto +7 -0
  24. package/default-ruleset/test/fixtures/ENUM_Constans-vaild.cto +7 -0
  25. package/default-ruleset/test/fixtures/abstract-must-subclassed-invalid.cto +10 -0
  26. package/default-ruleset/test/fixtures/abstract-must-subclassed-valid.cto +18 -0
  27. package/default-ruleset/test/fixtures/declarations-valid-PascalCase.cto +21 -0
  28. package/default-ruleset/test/fixtures/declarations-violate-PascalCase.cto +22 -0
  29. package/default-ruleset/test/fixtures/decorators-valid-PascalCase.cto +8 -0
  30. package/default-ruleset/test/fixtures/decorators-violate-PascalCase.cto +8 -0
  31. package/default-ruleset/test/fixtures/namespace-invalid-version.cto +5 -0
  32. package/default-ruleset/test/fixtures/namespace-valid-version.cto +5 -0
  33. package/default-ruleset/test/fixtures/no-empty-declarations-invalid.cto +10 -0
  34. package/default-ruleset/test/fixtures/no-empty-declarations-valid.cto +16 -0
  35. package/default-ruleset/test/fixtures/no-reserved-keywords-invalid.cto +16 -0
  36. package/default-ruleset/test/fixtures/no-reserved-keywords-valid.cto +16 -0
  37. package/default-ruleset/test/fixtures/properties-valid-camelCase.cto +10 -0
  38. package/default-ruleset/test/fixtures/properties-violate-camelCase.cto +10 -0
  39. package/default-ruleset/test/fixtures/string-length-validator-invalid.cto +9 -0
  40. package/default-ruleset/test/fixtures/string-length-validator-valid.cto +10 -0
  41. package/default-ruleset/test/rules/abstract-must-subclassed.test.ts +33 -0
  42. package/default-ruleset/test/rules/namespace-version.test.ts +24 -0
  43. package/default-ruleset/test/rules/naming-ruleset.test.ts +133 -0
  44. package/default-ruleset/test/rules/no-empty-declarations.test.ts +33 -0
  45. package/default-ruleset/test/rules/no-reserved-keywords.test.ts +33 -0
  46. package/default-ruleset/test/rules/string-length-validator.test.ts +33 -0
  47. package/default-ruleset/test/test-rule.ts +30 -0
  48. package/default-ruleset/tsconfig.json +113 -0
  49. package/dist/config-loader.d.ts +6 -0
  50. package/dist/config-loader.js +52 -0
  51. package/dist/config-loader.js.map +1 -0
  52. package/dist/index.d.ts +32 -0
  53. package/dist/index.js +135 -0
  54. package/dist/index.js.map +1 -0
  55. package/jest.config.js +11 -0
  56. package/package.json +54 -0
  57. package/src/config-loader.ts +48 -0
  58. package/src/index.ts +173 -0
  59. package/test/unit/configLoader.test.ts +76 -0
  60. package/test/unit/formatResults.test.ts +149 -0
  61. package/test/unit/lintModel.test.ts +84 -0
  62. package/test/unit/loadRuleset.test.ts +64 -0
  63. package/tsconfig.build.json +4 -0
  64. package/tsconfig.json +113 -0
package/.eslintignore ADDED
@@ -0,0 +1,20 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ coverage
16
+ node_modules
17
+ out
18
+ lib/parser.js
19
+ test/data
20
+ dist
package/.eslintrc.yml ADDED
@@ -0,0 +1,45 @@
1
+ env:
2
+ es6: true
3
+ node: true
4
+ mocha: true
5
+ extends:
6
+ - 'eslint:recommended'
7
+ - 'plugin:@typescript-eslint/eslint-recommended'
8
+ - 'plugin:@typescript-eslint/recommended'
9
+ parser: '@typescript-eslint/parser'
10
+ plugins:
11
+ - '@typescript-eslint'
12
+ parserOptions:
13
+ ecmaVersion: 13
14
+ sourceType: script
15
+ rules:
16
+ indent:
17
+ - error
18
+ - 4
19
+ linebreak-style:
20
+ - warn
21
+ - unix
22
+ quotes:
23
+ - error
24
+ - single
25
+ semi:
26
+ - error
27
+ - always
28
+ no-console: warn
29
+ curly: error
30
+ eqeqeq: error
31
+ no-throw-literal: error
32
+ strict: 0
33
+ no-var: error
34
+ dot-notation: error
35
+ no-tabs: error
36
+ no-trailing-spaces: error
37
+ # no-use-before-define: error
38
+ no-useless-call: error
39
+ no-with: error
40
+ operator-linebreak: error
41
+ require-jsdoc: 0
42
+ valid-jsdoc:
43
+ - error
44
+ - requireReturn: false
45
+ yoda: error
package/HEADER.md ADDED
@@ -0,0 +1,2 @@
1
+ ## License <a name="license"></a>
2
+ 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), available at http://creativecommons.org/licenses/by/4.0/.
package/README.md ADDED
@@ -0,0 +1,207 @@
1
+ # concerto linter
2
+
3
+ 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.
4
+
5
+ ## Table of contents
6
+ - [concerto linter](#concerto-linter)
7
+ - [Table of contents](#table-of-contents)
8
+ - [Features](#features)
9
+ - [Model Input](#model-input)
10
+ - [Ruleset Discovery](#ruleset-discovery)
11
+ - [Ruleset Flexibility](#ruleset-flexibility)
12
+ - [Namespace Filtering](#namespace-filtering)
13
+ - [JSON Output](#json-output)
14
+ - [Getting Started](#getting-started)
15
+ - [Installation](#installation)
16
+ - [Providing the concerto Model](#providing-the-concerto-model)
17
+ - [As a CTO String](#as-a-cto-string)
18
+ - [As a Parsed AST Object](#as-a-parsed-ast-object)
19
+ - [Ruleset Configuration](#ruleset-configuration)
20
+ - [Default Ruleset](#default-ruleset)
21
+ - [Custom Rulesets](#custom-rulesets)
22
+ - [Automatic Ruleset Discovery](#automatic-ruleset-discovery)
23
+ - [Creating Custom Rulesets](#creating-custom-rulesets)
24
+ - [The linter output](#the-linter-output)
25
+ - [Namespace Filtering](#namespace-filtering-1)
26
+ - [License](#license)
27
+
28
+ <!-- tocstop -->
29
+ ## Features
30
+
31
+ ### Model Input
32
+
33
+ - **Versatile Model Input**: Supports concerto models provided as either a CTO string or a parsed Abstract Syntax Tree (AST) object.
34
+
35
+ ### Ruleset Discovery
36
+
37
+ - **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.
38
+
39
+ ### Ruleset Flexibility
40
+
41
+ - **Custom Ruleset Flexibility**: Enables the use of a custom Spectral ruleset by allowing you to specify its file path for tailored linting rules.
42
+
43
+ ### Namespace Filtering
44
+
45
+ - **Namespace Filtering**: Filters linting results by namespace, with configurable exclusion patterns. By default, excludes `'concerto.*'` and `'org.accordproject.*'` namespaces.
46
+
47
+ ### JSON Output
48
+
49
+ - **Structured JSON Output**: Returns linting results in a consistent JSON format for easier integration with other tools and workflows.
50
+
51
+ ## Getting Started
52
+ 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.
53
+
54
+ ## Installation
55
+ Install the package via npm:
56
+ ```bash
57
+ npm install @accordproject/concerto-linter
58
+ ```
59
+ ### Providing the concerto Model
60
+ The lintModel function accepts your Concerto model in one of two formats:
61
+
62
+ #### As a CTO String
63
+ ```javascript
64
+ const model = `
65
+ namespace org.example
66
+ asset MyProduct {
67
+ o String ProductId
68
+ }
69
+ `;
70
+ ```
71
+
72
+ #### As a Parsed AST Object
73
+ ```javascript
74
+ import { ModelManager } from '@accordproject/concerto-core';
75
+
76
+ const modelManager = new ModelManager();
77
+ const model = `
78
+ namespace org.example
79
+ asset MyProduct {
80
+ o String ProductId
81
+ }
82
+ `;
83
+ modelManager.addCTOModel(model);
84
+ const ast = modelManager.getAst();
85
+ ```
86
+ ## Ruleset Configuration
87
+
88
+ The concerto Linter provides flexible `ruleset` configuration options to suit your project needs.
89
+
90
+ ### Default Ruleset
91
+
92
+ 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.
93
+
94
+ ### Custom Rulesets
95
+
96
+ You can customize the linting rules in several ways:
97
+
98
+ 1. **Create a ruleset file** in your project directory using any of these supported formats:
99
+ - `.spectral.yaml`
100
+ - `.spectral.yml`
101
+ - `.spectral.json`
102
+ - `.spectral.js`
103
+
104
+ 2. **Specify a ruleset path** explicitly when calling the linter:
105
+ ```javascript
106
+ const results = await lintModel(ast, {ruleset: 'path/to/your/custom-ruleset.yaml'});
107
+ ```
108
+
109
+ 3. **Force the default ruleset**
110
+ ```javascript
111
+ const results = await lintModel(ast, {ruleset: 'default'});
112
+ ```
113
+
114
+ ### Automatic Ruleset Discovery
115
+
116
+ When you call `lintModel` without specifying a ruleset, the linter will automatically search for ruleset files in the following order:
117
+
118
+ 1. `.spectral.yaml`
119
+ 2. `.spectral.yml`
120
+ 3. `.spectral.json`
121
+ 4. `.spectral.js`
122
+
123
+ 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:
124
+
125
+ ```javascript
126
+ import { lintModel } from '@accordproject/concerto-linter';
127
+
128
+ const results = await lintModel(ast, { ruleset: 'default' });
129
+ ```
130
+ 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`).
131
+
132
+ ```javascript
133
+ import { lintModel } from '@accordproject/concerto-linter';
134
+
135
+ // The linter will automatically detect ruleset files in your project
136
+ const results = await lintModel(ast); // Pass the AST object
137
+ // OR
138
+ const results = await lintModel(model); // Pass the CTO string directly
139
+ ```
140
+
141
+ ### Creating Custom Rulesets
142
+
143
+ 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](./default-ruleset/README.md).
144
+
145
+ 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.
146
+
147
+ ## The linter output
148
+
149
+ The lintModel function returns a Promise that resolves to an array of linting results in JSON format:
150
+
151
+ Each lint issue is represented as a flat JSON object:
152
+
153
+ ```ts
154
+ interface ILintResult {
155
+ /** Unique rule identifier (e.g. 'no-unused-concept') */
156
+ code: string;
157
+
158
+ /** Human-readable description of the violation */
159
+ message: string;
160
+
161
+ /** Severity level ('error' | 'warning' | 'info' | 'hint') */
162
+ severity: string;
163
+
164
+ /**
165
+ * JSONPath-style pointer as an array of keys/indices
166
+ * (e.g. ['declarations', 3])
167
+ */
168
+ path: Array<string | number>;
169
+
170
+ /** Namespace where the violation occurred (e.g. 'org.accordproject') */
171
+ namespace: string;
172
+
173
+ }
174
+ ```
175
+ Example Output :
176
+
177
+ ```json
178
+ [
179
+ {
180
+ "code": "camel-case-properties",
181
+ "message": "Property 'FirstVal' should be camelCase (e.g. 'myProperty').",
182
+ "severity": "warning",
183
+ "path": ["declarations", 3],
184
+ "namespace": "org.example.model",
185
+ "source": "concerto-lintr"
186
+ }
187
+ ```
188
+
189
+ ### Namespace Filtering
190
+
191
+ By default, results from namespaces matching `'concerto.*'` and `'org.accordproject.*'` are excluded from the output. You can customize this behavior using the `excludeNamespaces` option.
192
+
193
+ ```javascript
194
+ // Override default namespace exclusions
195
+ const results = await lintModel(ast, {
196
+ excludeNamespaces: ['org.example.*', 'com.acme.*']
197
+ });
198
+
199
+ // Combine custom ruleset and namespace filtering
200
+ const results = await lintModel(ast, {
201
+ ruleset: "D:\\linter-test\\my-ruleset.yaml",
202
+ excludeNamespaces: ['org.example.*']
203
+ });
204
+ ```
205
+ ## License
206
+
207
+ 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).
@@ -0,0 +1,20 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ #
14
+
15
+ coverage
16
+ node_modules
17
+ out
18
+ lib/parser.js
19
+ test/data
20
+ dist
@@ -0,0 +1,45 @@
1
+ env:
2
+ es6: true
3
+ node: true
4
+ mocha: true
5
+ extends:
6
+ - 'eslint:recommended'
7
+ - 'plugin:@typescript-eslint/eslint-recommended'
8
+ - 'plugin:@typescript-eslint/recommended'
9
+ parser: '@typescript-eslint/parser'
10
+ plugins:
11
+ - '@typescript-eslint'
12
+ parserOptions:
13
+ ecmaVersion: 13
14
+ sourceType: script
15
+ rules:
16
+ indent:
17
+ - error
18
+ - 4
19
+ linebreak-style:
20
+ - warn
21
+ - unix
22
+ quotes:
23
+ - error
24
+ - single
25
+ semi:
26
+ - error
27
+ - always
28
+ no-console: warn
29
+ curly: error
30
+ eqeqeq: error
31
+ no-throw-literal: error
32
+ strict: 0
33
+ no-var: error
34
+ dot-notation: error
35
+ no-tabs: error
36
+ no-trailing-spaces: error
37
+ # no-use-before-define: error
38
+ no-useless-call: error
39
+ no-with: error
40
+ operator-linebreak: error
41
+ require-jsdoc: 0
42
+ valid-jsdoc:
43
+ - error
44
+ - requireReturn: false
45
+ yoda: error
@@ -0,0 +1,300 @@
1
+ # Concerto Linter Default Ruleset
2
+
3
+ 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.
4
+
5
+ This sub-package is part of the `@accordproject/concerto-linter` package. Read the [concerto-linter README](https://github.com/accordproject/concerto/tree/main/packages/concerto-linter) if you want to know how to use this ruleset with concerto models.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Concerto Linter Default Ruleset](#concerto-linter-default-ruleset)
10
+ - [Table of Contents](#table-of-contents)
11
+ - [Key Benefits](#key-benefits)
12
+ - [Available Rules](#available-rules)
13
+ - [Installation](#installation)
14
+ - [Usage](#usage)
15
+ - [Customization](#customization)
16
+ - [Extending the Default Ruleset](#extending-the-default-ruleset)
17
+ - [Disabling Specific Rules](#disabling-specific-rules)
18
+ - [Available Rule IDs](#available-rule-ids)
19
+ - [Enabling Specific Rules](#enabling-specific-rules)
20
+ - [Adjusting Rule Severity](#adjusting-rule-severity)
21
+ - [Creating Custom Rules](#creating-custom-rules)
22
+ - [License](#license)
23
+
24
+ ## Key Benefits
25
+
26
+ - **Consistent Code Style**: Enforce uniform naming conventions across your concerto models
27
+ - **Error Prevention**: Catch common modeling mistakes before they cause issues
28
+ - **Best Practices**: Apply industry-standard modeling practices automatically
29
+ - **Customizable**: Easily extend or modify rules to match your project's specific needs
30
+ - **Integration Ready**: Works seamlessly with the concerto Linter and your development workflow
31
+
32
+ ## Available Rules
33
+
34
+ The following table provides an overview of the available linting rules in the default ruleset:
35
+
36
+ <table>
37
+ <tr>
38
+ <th>Rule Id</th><th>Description</th>
39
+ </tr>
40
+ <tr>
41
+ <td><a href="#namespace-version">namespace-version</a></td>
42
+ <td>Ensures that the namespace declaration in the model includes a version number. This rule enforces semantic versioning in namespaces, promoting clarity and compatibility management.</td>
43
+ </tr>
44
+ <tr>
45
+ <td><a href="#no-reserved-keywords">no-reserved-keywords</a></td>
46
+ <td>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.</td>
47
+ </tr>
48
+ <tr>
49
+ <td><a href="#pascal-case-declarations">pascal-case-declarations</a></td>
50
+ <td>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.</td>
51
+ </tr>
52
+ <tr>
53
+ <td><a href="#camel-case-properties">camel-case-properties</a></td>
54
+ <td>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.</td>
55
+ </tr>
56
+ <tr>
57
+ <td><a href="#upper-snake-case-enum-constants">upper-snake-case-enum-constants</a></td>
58
+ <td>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.</td>
59
+ </tr>
60
+ <tr>
61
+ <td><a href="#pascal-case-decorators">pascal-case-decorators</a></td>
62
+ <td>Ensures that decorator names follow PascalCase naming convention (e.g., 'MyDecorator'). This promotes consistency and readability across model decorators.</td>
63
+ </tr>
64
+ <tr>
65
+ <td><a href="#string-length-validator">string-length-validator</a></td>
66
+ <td>Ensures that all string properties within the data model have a length validator applied, which helps prevent inconsistent data length and ensure proper storage.</td>
67
+ </tr>
68
+ <tr>
69
+ <td><a href="#no-empty-declarations">no-empty-declarations</a></td>
70
+ <td>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.</td>
71
+ </tr>
72
+ <tr>
73
+ <td><a href="#abstract-must-subclassed">abstract-must-subclassed</a></td>
74
+ <td>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.</td>
75
+ </tr>
76
+ </table>
77
+
78
+ ## Installation
79
+
80
+ First, install the package as a development dependency:
81
+
82
+ ```bash
83
+ npm install --save-dev @accordproject/concerto-linter-default-ruleset
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ Once installed, the default ruleset is automatically used by the concerto Linter when no custom ruleset is specified:
89
+
90
+ ```javascript
91
+ import { lintModel } from '@accordproject/concerto-linter';
92
+
93
+ // The default ruleset will be used automatically
94
+ const results = await lintModel(modelText);
95
+ console.log(results);
96
+ ```
97
+
98
+ To explicitly specify the default ruleset:
99
+
100
+ ```javascript
101
+ const results = await lintModel(modelText, { ruleset: 'default' });
102
+ ```
103
+
104
+ ## Customization
105
+
106
+ 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.
107
+
108
+ 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"`.
109
+
110
+ ### Extending the Default Ruleset
111
+
112
+ You can extend the default ruleset in multiple formats:
113
+
114
+ **YAML (.spectral.yaml)**
115
+ ```yaml
116
+ extends: '@accordproject/concerto-linter-default-ruleset'
117
+ ```
118
+
119
+ ---
120
+
121
+ **JSON (.spectral.json)**
122
+ ```json
123
+ {
124
+ "extends": "@accordproject/concerto-linter-default-ruleset"
125
+ }
126
+ ```
127
+
128
+ ---
129
+
130
+ **JavaScript (.spectral.js)**
131
+ ```javascript
132
+ const rules = require('@accordproject/concerto-linter-default-ruleset');
133
+ module.exports = {
134
+ extends: rules
135
+ };
136
+ ```
137
+
138
+ ### Disabling Specific Rules
139
+
140
+ 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`.
141
+
142
+ #### Available Rule IDs
143
+
144
+ Here are all the rule IDs that can be disabled:
145
+
146
+ | Rule ID | Description |
147
+ |---------|-------------|
148
+ | `namespace-version` | Ensures namespaces include version numbers |
149
+ | `no-reserved-keywords` | Prevents use of reserved keywords |
150
+ | `pascal-case-declarations` | Enforces PascalCase for declarations |
151
+ | `camel-case-properties` | Enforces camelCase for properties |
152
+ | `upper-snake-case-enum-constants` | Enforces UPPER_SNAKE_CASE for enum constants |
153
+ | `pascal-case-decorators` | Enforces PascalCase for decorators |
154
+ | `string-length-validator` | Requires string length validators |
155
+ | `no-empty-declarations` | Prevents empty declarations |
156
+ | `abstract-must-subclassed` | Ensures abstract classes have concrete subclasses |
157
+
158
+
159
+ **YAML (.spectral.yaml)**
160
+ ```yaml
161
+ extends: '@accordproject/concerto-linter-default-ruleset'
162
+ rules:
163
+ pascal-case-declarations: 'off'
164
+ camel-case-properties: 'off'
165
+ ```
166
+
167
+ ---
168
+
169
+ **JSON (.spectral.json)**
170
+ ```json
171
+ {
172
+ "extends": "@accordproject/concerto-linter-default-ruleset",
173
+ "rules": {
174
+ "pascal-case-declarations": "off",
175
+ "camel-case-properties": "off"
176
+ }
177
+ }
178
+ ```
179
+
180
+ **JavaScript (.spectral.js)**
181
+ ```javascript
182
+ const rules = require('@accordproject/concerto-linter-default-ruleset');
183
+ module.exports = {
184
+ extends: rules,
185
+ rules: {
186
+ 'pascal-case-declarations': off,
187
+ 'namespace-version': off
188
+ }
189
+ };
190
+ ```
191
+ ### Enabling Specific Rules
192
+
193
+ You can selectively start with everything off and enable only specific rules:
194
+
195
+ **YAML (.spectral.yaml)**
196
+ ```yaml
197
+ extends: [['@accordproject/concerto-linter-default-ruleset', 'off']]
198
+ rules:
199
+ pascal-case-declarations: true
200
+ namespace-version: true
201
+ ```
202
+
203
+ **JSON (.spectral.json)**
204
+ ```json
205
+ {
206
+ "extends": [["@accordproject/concerto-linter-default-ruleset", "off"]],
207
+ "rules": {
208
+ "pascal-case-declarations": true,
209
+ "namespace-version": true
210
+ }
211
+ }
212
+ ```
213
+
214
+ **JavaScript (.spectral.js)**
215
+ ```javascript
216
+ const rules = require('@accordproject/concerto-linter-default-ruleset');
217
+ module.exports = {
218
+ extends: [[rules, 'off']],
219
+ rules: {
220
+ 'pascal-case-declarations': true,
221
+ 'namespace-version': true
222
+ }
223
+ };
224
+ ```
225
+ ---
226
+ ### Adjusting Rule Severity
227
+
228
+ You can customize the severity level of each rule to control how violations are reported.
229
+ - **0** = error (must be fixed)
230
+ - **1** = warn (should be addressed)
231
+ - **2** = info (useful information)
232
+ - **3** = hint (optional suggestion)
233
+
234
+ **YAML (.spectral.yaml)**
235
+ ```yaml
236
+ extends: '@accordproject/concerto-linter-default-ruleset'
237
+ rules:
238
+ pascal-case-declarations: 'warn' # Change from error to warning
239
+ camel-case-properties: 'info' # Change to informational
240
+ ```
241
+
242
+ **JSON (.spectral.json)**
243
+ ```json
244
+ {
245
+ "extends": "@accordproject/concerto-linter-default-ruleset",
246
+ "rules": {
247
+ "pascal-case-declarations": "warn",
248
+ "camel-case-properties": "info"
249
+ }
250
+ }
251
+ ```
252
+
253
+ **JavaScript (.spectral.js)**
254
+ ```javascript
255
+ const rules = require('@accordproject/concerto-linter-default-ruleset');
256
+ module.exports = {
257
+ extends: rules,
258
+ rules: {
259
+ 'pascal-case-declarations': 'warn',
260
+ 'camel-case-properties': 'info'
261
+ }
262
+ };
263
+ ```
264
+
265
+ ## Creating Custom Rules
266
+
267
+ 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](https://meta.stoplight.io/docs/spectral/e5b9616d6d50c-rulesets).
268
+
269
+ Here's a simple example of what a custom rule looks like:
270
+
271
+ ```yaml
272
+ # description (optional): Explains what the ruleset is about.
273
+ description: "Declaration names (scalar, enum, concept, asset, participant, transaction, event) should be PascalCase."
274
+
275
+ # given (required): JSONPath expression that specifies where the rule applies.
276
+ given: "$.models[*].declarations[*].name"
277
+
278
+ # message (required): The error/warning message shown when the rule is violated.
279
+ message: "Declaration '{{value}}' should be PascalCase (e.g. 'MyDeclaration')"
280
+
281
+ # severity (optional): The level of violation.
282
+ # 0 = error, 1 = warning, 2 = info, 3 = hint
283
+ severity: 0
284
+
285
+ # then (required): Defines what function to apply and how.
286
+ then:
287
+ # function (required): The function that validates the rule.
288
+ function: casing
289
+
290
+ # functionOptions (optional): Extra options for the function.
291
+ functionOptions:
292
+ type: pascal
293
+ ```
294
+
295
+ For more complex rules, you can create custom JavaScript functions following [Spectral ruleset documentation](https://meta.stoplight.io/docs/spectral/e5b9616d6d50c-rulesets) and import it into your rule, similar to how the built-in rules work.
296
+
297
+
298
+ ## License
299
+
300
+ 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).
@@ -0,0 +1,7 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} **/
2
+ module.exports = {
3
+ testEnvironment: 'node',
4
+ transform: {
5
+ '^.+.tsx?$': ['ts-jest', {}],
6
+ },
7
+ };