@accordproject/concerto-linter-default-ruleset 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 (83) hide show
  1. package/.eslintignore +20 -0
  2. package/.eslintrc.yml +45 -0
  3. package/README.md +300 -0
  4. package/dist/abstract-must-subclassed.d.ts +14 -0
  5. package/dist/abstract-must-subclassed.js +30 -0
  6. package/dist/abstract-must-subclassed.js.map +1 -0
  7. package/dist/camel-case-properties.d.ts +20 -0
  8. package/dist/camel-case-properties.js +36 -0
  9. package/dist/camel-case-properties.js.map +1 -0
  10. package/dist/functions/check-length-validator.d.ts +9 -0
  11. package/dist/functions/check-length-validator.js +40 -0
  12. package/dist/functions/check-length-validator.js.map +1 -0
  13. package/dist/functions/find-abstract-declaration.d.ts +13 -0
  14. package/dist/functions/find-abstract-declaration.js +56 -0
  15. package/dist/functions/find-abstract-declaration.js.map +1 -0
  16. package/dist/functions/find-empty-declarations.d.ts +9 -0
  17. package/dist/functions/find-empty-declarations.js +45 -0
  18. package/dist/functions/find-empty-declarations.js.map +1 -0
  19. package/dist/namespace-version.d.ts +19 -0
  20. package/dist/namespace-version.js +35 -0
  21. package/dist/namespace-version.js.map +1 -0
  22. package/dist/no-empty-declarations.d.ts +15 -0
  23. package/dist/no-empty-declarations.js +31 -0
  24. package/dist/no-empty-declarations.js.map +1 -0
  25. package/dist/no-reserved-keywords.d.ts +22 -0
  26. package/dist/no-reserved-keywords.js +44 -0
  27. package/dist/no-reserved-keywords.js.map +1 -0
  28. package/dist/pascal-case-declarations.d.ts +20 -0
  29. package/dist/pascal-case-declarations.js +36 -0
  30. package/dist/pascal-case-declarations.js.map +1 -0
  31. package/dist/pascal-case-decorators.d.ts +19 -0
  32. package/dist/pascal-case-decorators.js +39 -0
  33. package/dist/pascal-case-decorators.js.map +1 -0
  34. package/dist/ruleset-main.d.ts +3 -0
  35. package/dist/ruleset-main.js +42 -0
  36. package/dist/ruleset-main.js.map +1 -0
  37. package/dist/string-length-validator.d.ts +14 -0
  38. package/dist/string-length-validator.js +33 -0
  39. package/dist/string-length-validator.js.map +1 -0
  40. package/dist/upper-snake-case-enum-const.d.ts +20 -0
  41. package/dist/upper-snake-case-enum-const.js +36 -0
  42. package/dist/upper-snake-case-enum-const.js.map +1 -0
  43. package/jest.config.js +7 -0
  44. package/package.json +51 -0
  45. package/src/abstract-must-subclassed.ts +29 -0
  46. package/src/camel-case-properties.ts +35 -0
  47. package/src/functions/check-length-validator.ts +52 -0
  48. package/src/functions/find-abstract-declaration.ts +70 -0
  49. package/src/functions/find-empty-declarations.ts +56 -0
  50. package/src/namespace-version.ts +35 -0
  51. package/src/no-empty-declarations.ts +31 -0
  52. package/src/no-reserved-keywords.ts +43 -0
  53. package/src/pascal-case-declarations.ts +35 -0
  54. package/src/pascal-case-decorators.ts +38 -0
  55. package/src/ruleset-main.ts +41 -0
  56. package/src/string-length-validator.ts +32 -0
  57. package/src/upper-snake-case-enum-const.ts +36 -0
  58. package/test/fixtures/ENUM_Constans-invaild.cto +7 -0
  59. package/test/fixtures/ENUM_Constans-vaild.cto +7 -0
  60. package/test/fixtures/abstract-must-subclassed-invalid.cto +10 -0
  61. package/test/fixtures/abstract-must-subclassed-valid.cto +18 -0
  62. package/test/fixtures/declarations-valid-PascalCase.cto +21 -0
  63. package/test/fixtures/declarations-violate-PascalCase.cto +22 -0
  64. package/test/fixtures/decorators-valid-PascalCase.cto +8 -0
  65. package/test/fixtures/decorators-violate-PascalCase.cto +8 -0
  66. package/test/fixtures/namespace-invalid-version.cto +5 -0
  67. package/test/fixtures/namespace-valid-version.cto +5 -0
  68. package/test/fixtures/no-empty-declarations-invalid.cto +10 -0
  69. package/test/fixtures/no-empty-declarations-valid.cto +16 -0
  70. package/test/fixtures/no-reserved-keywords-invalid.cto +16 -0
  71. package/test/fixtures/no-reserved-keywords-valid.cto +16 -0
  72. package/test/fixtures/properties-valid-camelCase.cto +10 -0
  73. package/test/fixtures/properties-violate-camelCase.cto +10 -0
  74. package/test/fixtures/string-length-validator-invalid.cto +9 -0
  75. package/test/fixtures/string-length-validator-valid.cto +10 -0
  76. package/test/rules/abstract-must-subclassed.test.ts +33 -0
  77. package/test/rules/namespace-version.test.ts +24 -0
  78. package/test/rules/naming-ruleset.test.ts +133 -0
  79. package/test/rules/no-empty-declarations.test.ts +33 -0
  80. package/test/rules/no-reserved-keywords.test.ts +33 -0
  81. package/test/rules/string-length-validator.test.ts +33 -0
  82. package/test/test-rule.ts +30 -0
  83. 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/README.md ADDED
@@ -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,14 @@
1
+ /**
2
+ * Rule: Abstract Must Be Subclassed
3
+ * ---------------------------------
4
+ * Ensures that every abstract declaration in the model has at least one concrete subclass.
5
+ * This helps prevent unused or orphaned abstract types, enforcing better model design.
6
+ */
7
+ declare const _default: {
8
+ given: string;
9
+ severity: number;
10
+ then: {
11
+ function: import("@stoplight/spectral-core").IFunction;
12
+ };
13
+ };
14
+ export default _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ const find_abstract_declaration_1 = require("./functions/find-abstract-declaration");
17
+ /**
18
+ * Rule: Abstract Must Be Subclassed
19
+ * ---------------------------------
20
+ * Ensures that every abstract declaration in the model has at least one concrete subclass.
21
+ * This helps prevent unused or orphaned abstract types, enforcing better model design.
22
+ */
23
+ exports.default = {
24
+ given: '$.models[*]',
25
+ severity: 0, // 0 = error, 1 = warning, 2 = info, 3 = hint
26
+ then: {
27
+ function: find_abstract_declaration_1.hasConcreteSubclass,
28
+ },
29
+ };
30
+ //# sourceMappingURL=abstract-must-subclassed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abstract-must-subclassed.js","sourceRoot":"","sources":["../src/abstract-must-subclassed.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;GAYG;AACH,qFAA4E;AAE5E;;;;;GAKG;AACH,kBAAe;IACX,KAAK,EAAE,aAAa;IACpB,QAAQ,EAAE,CAAC,EAAE,6CAA6C;IAC1D,IAAI,EAAE;QACF,QAAQ,EAAE,+CAAmB;KAChC;CACJ,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Rule: Camel Case Properties
3
+ * ---------------------------
4
+ * Ensures that properties of type String, Double, Integer, Long, DateTime, and Boolean
5
+ * are named using camelCase. This promotes consistency and readability in property naming
6
+ * conventions across the model.
7
+ */
8
+ declare const _default: {
9
+ description: string;
10
+ given: string;
11
+ message: string;
12
+ severity: number;
13
+ then: {
14
+ function: import("@stoplight/spectral-core").RulesetFunctionWithValidator<string, import("@stoplight/spectral-functions").CasingOptions>;
15
+ functionOptions: {
16
+ type: string;
17
+ };
18
+ };
19
+ };
20
+ export default _default;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const spectral_functions_1 = require("@stoplight/spectral-functions");
17
+ /**
18
+ * Rule: Camel Case Properties
19
+ * ---------------------------
20
+ * Ensures that properties of type String, Double, Integer, Long, DateTime, and Boolean
21
+ * are named using camelCase. This promotes consistency and readability in property naming
22
+ * conventions across the model.
23
+ */
24
+ exports.default = {
25
+ description: 'Properties of type String, Double, Integer, Long, DateTime, Boolean should be camelCase.',
26
+ given: '$.models[*].declarations[?(@.$class && @.$class != "concerto.metamodel@1.0.0.EnumDeclaration")].properties[*].name',
27
+ message: 'Property \'{{value}}\' should be camelCase (e.g. \'myProperty\')',
28
+ severity: 0, // 0 = error, 1 = warning, 2 = info, 3 = hint
29
+ then: {
30
+ function: spectral_functions_1.casing,
31
+ functionOptions: {
32
+ type: 'camel',
33
+ },
34
+ },
35
+ };
36
+ //# sourceMappingURL=camel-case-properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camel-case-properties.js","sourceRoot":"","sources":["../src/camel-case-properties.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAEH,sEAAuD;AAEvD;;;;;;GAMG;AACH,kBAAe;IACX,WAAW,EAAE,0FAA0F;IACvG,KAAK,EAAE,oHAAoH;IAC3H,OAAO,EAAE,kEAAkE;IAC3E,QAAQ,EAAE,CAAC,EAAE,6CAA6C;IAC1D,IAAI,EAAE;QACF,QAAQ,EAAE,2BAAM;QAChB,eAAe,EAAE;YACb,IAAI,EAAE,OAAO;SAChB;KACJ;CACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { IFunction } from '@stoplight/spectral-core';
2
+ /**
3
+ * Checks if a String object has a length validator.
4
+ *
5
+ * @param {unknown} targetVal The AST node to check, expected to be a StringProperty or StringScalar object.
6
+ * @returns {IFunctionResult[] | void} An array of results indicating declarations that lack a length validator.
7
+ * @throws {Error} If the input is not a valid object.
8
+ */
9
+ export declare const checkLengthValidator: IFunction;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.checkLengthValidator = void 0;
17
+ /**
18
+ * Checks if a String object has a length validator.
19
+ *
20
+ * @param {unknown} targetVal The AST node to check, expected to be a StringProperty or StringScalar object.
21
+ * @returns {IFunctionResult[] | void} An array of results indicating declarations that lack a length validator.
22
+ * @throws {Error} If the input is not a valid object.
23
+ */
24
+ const checkLengthValidator = (targetVal) => {
25
+ // Validate that targetVal is a non-null object
26
+ if (targetVal === null || typeof targetVal !== 'object') {
27
+ throw new Error('Input must be a valid String AST object.');
28
+ }
29
+ const stringObject = targetVal;
30
+ const results = [];
31
+ // Check for missing length validator
32
+ if (!stringObject.lengthValidator) {
33
+ results.push({
34
+ message: `String '${stringObject.name}' must have a length validator.`,
35
+ });
36
+ }
37
+ return results;
38
+ };
39
+ exports.checkLengthValidator = checkLengthValidator;
40
+ //# sourceMappingURL=check-length-validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check-length-validator.js","sourceRoot":"","sources":["../../src/functions/check-length-validator.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAeH;;;;;;GAMG;AACI,MAAM,oBAAoB,GAAc,CAAC,SAAS,EAAqB,EAAE;IAC5E,+CAA+C;IAC/C,IAAI,SAAS,KAAK,IAAI,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,YAAY,GAAG,SAAyB,CAAC;IAC/C,MAAM,OAAO,GAAsB,EAAE,CAAC;IAEtC,qCAAqC;IACrC,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC;YACT,OAAO,EAAE,WAAW,YAAY,CAAC,IAAI,iCAAiC;SACzE,CAAC,CAAC;IACP,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAjBW,QAAA,oBAAoB,wBAiB/B"}
@@ -0,0 +1,13 @@
1
+ import type { IFunction } from '@stoplight/spectral-core';
2
+ /**
3
+ * Checks if each abstract declaration in the model has at least one concrete subclass.
4
+ *
5
+ * Iterates through the model's declarations, collects all abstract types,
6
+ * and removes any abstract type that is extended by a concrete subclass.
7
+ * Returns a result for each abstract type without a concrete subclass.
8
+ *
9
+ * @param {unknown} targetVal The AST model object containing declarations.
10
+ * @returns {IFunctionResult[] | void} An array of results for abstract declarations lacking concrete subclasses.
11
+ * @throws {Error} If the input is not a valid model AST.
12
+ */
13
+ export declare const hasConcreteSubclass: IFunction;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.hasConcreteSubclass = void 0;
17
+ /**
18
+ * Checks if each abstract declaration in the model has at least one concrete subclass.
19
+ *
20
+ * Iterates through the model's declarations, collects all abstract types,
21
+ * and removes any abstract type that is extended by a concrete subclass.
22
+ * Returns a result for each abstract type without a concrete subclass.
23
+ *
24
+ * @param {unknown} targetVal The AST model object containing declarations.
25
+ * @returns {IFunctionResult[] | void} An array of results for abstract declarations lacking concrete subclasses.
26
+ * @throws {Error} If the input is not a valid model AST.
27
+ */
28
+ const hasConcreteSubclass = (targetVal) => {
29
+ const results = [];
30
+ // Validate that targetVal is a non-null object
31
+ if (typeof targetVal !== 'object' || !targetVal || !Array.isArray(targetVal.declarations)) {
32
+ throw new Error(`${targetVal} must be a valid AST for concerto model`);
33
+ }
34
+ const abstractNames = new Map();
35
+ const allDeclarations = targetVal.declarations;
36
+ for (const [index, decl] of allDeclarations.entries()) {
37
+ if (decl && decl.isAbstract && typeof decl.name === 'string') {
38
+ abstractNames.set(decl.name, index);
39
+ }
40
+ }
41
+ for (const decl of allDeclarations) {
42
+ if (decl && !decl.isAbstract && decl.superType && typeof decl.superType.name === 'string') {
43
+ abstractNames.delete(decl.superType.name);
44
+ }
45
+ }
46
+ if (abstractNames.size > 0) {
47
+ for (const [abstractName] of abstractNames) {
48
+ results.push({
49
+ message: `Abstract declaration '${abstractName}' must have concrete subclasses`,
50
+ });
51
+ }
52
+ }
53
+ return results;
54
+ };
55
+ exports.hasConcreteSubclass = hasConcreteSubclass;
56
+ //# sourceMappingURL=find-abstract-declaration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-abstract-declaration.js","sourceRoot":"","sources":["../../src/functions/find-abstract-declaration.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAcH;;;;;;;;;;GAUG;AACI,MAAM,mBAAmB,GAAc,CAC1C,SAAS,EACe,EAAE;IAC1B,MAAM,OAAO,GAAsB,EAAE,CAAC;IAEtC,+CAA+C;IAC/C,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAE,SAAmB,CAAC,YAAY,CAAC,EAAE,CAAC;QACnG,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,yCAAyC,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAChD,MAAM,eAAe,GAAI,SAAmB,CAAC,YAAY,CAAC;IAE1D,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC;QACpD,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC3D,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACxC,CAAC;IACL,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,eAAe,EAAE,CAAC;QACjC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,SAAS,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACxF,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;IACL,CAAC;IACD,IAAI,aAAa,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;QACzB,KAAK,MAAM,CAAC,YAAY,CAAC,IAAI,aAAa,EAAE,CAAC;YACzC,OAAO,CAAC,IAAI,CAAC;gBACT,OAAO,EAAE,yBAAyB,YAAY,iCAAiC;aAClF,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AAhCW,QAAA,mBAAmB,uBAgC9B"}
@@ -0,0 +1,9 @@
1
+ import type { IFunction } from '@stoplight/spectral-core';
2
+ /**
3
+ * Finds and reports empty Concerto Declarations (i.e., declarations with no properties).
4
+ *
5
+ * @param {unknown} targetVal The AST node to check, expected to be a Concerto Declaration object.
6
+ * @returns {IFunctionResult[]} An array of results indicating declarations that are empty.
7
+ * @throws {Error} If the input is not a valid object.
8
+ */
9
+ export declare const findEmptyDeclarations: IFunction;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /*
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.findEmptyDeclarations = void 0;
17
+ /**
18
+ * Finds and reports empty Concerto Declarations (i.e., declarations with no properties).
19
+ *
20
+ * @param {unknown} targetVal The AST node to check, expected to be a Concerto Declaration object.
21
+ * @returns {IFunctionResult[]} An array of results indicating declarations that are empty.
22
+ * @throws {Error} If the input is not a valid object.
23
+ */
24
+ const findEmptyDeclarations = (targetVal) => {
25
+ const results = [];
26
+ // Validate that targetVal is a non-null object
27
+ if (typeof targetVal !== 'object' || targetVal === null) {
28
+ throw new Error('Value must be a valid AST object for a Concerto Declaration.');
29
+ }
30
+ // Ensure targetVal is a Declaration with a 'properties' field (not a scalar)
31
+ if (!targetVal.properties) {
32
+ return results;
33
+ }
34
+ const declaration = targetVal;
35
+ const properties = declaration.properties;
36
+ // If 'properties' is missing, not an array, or empty, report an error
37
+ if (!Array.isArray(properties) || properties.length === 0) {
38
+ results.push({
39
+ message: `Declaration '${declaration.name}' should not be empty and must declare at least one property.`,
40
+ });
41
+ }
42
+ return results;
43
+ };
44
+ exports.findEmptyDeclarations = findEmptyDeclarations;
45
+ //# sourceMappingURL=find-empty-declarations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-empty-declarations.js","sourceRoot":"","sources":["../../src/functions/find-empty-declarations.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AASH;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAc,CAC5C,SAAS,EACQ,EAAE;IACnB,MAAM,OAAO,GAAsB,EAAE,CAAC;IAEtC,+CAA+C;IAC/C,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;IACpF,CAAC;IAED,6EAA6E;IAC7E,IAAI,CAAE,SAAyB,CAAC,UAAU,EAC1C,CAAC;QACG,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,MAAM,WAAW,GAAG,SAAwB,CAAC;IAC7C,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC;IAE1C,sEAAsE;IACtE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC;YACT,OAAO,EAAE,gBAAgB,WAAW,CAAC,IAAI,+DAA+D;SAC3G,CAAC,CAAC;IACP,CAAC;IAED,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AA3BW,QAAA,qBAAqB,yBA2BhC"}