Skip to content

Commit f0fcf97

Browse files
Added comment check
Signed-off-by: Steve Springett <[email protected]>
1 parent 47f0ec2 commit f0fcf97

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

tools/src/main/js/linter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ node cli.js --list-checks
3838
| Check | Description |
3939
|-------|-------------|
4040
| `schema-id-pattern` | Validates `$id` matches CycloneDX URL pattern |
41+
| `schema-comment` | Validates `$comment` contains required standard notice |
4142
| `formatting-indent` | Validates 2-space indentation |
4243
| `description-full-stop` | Descriptions must end with full stop |
4344
| `meta-enum-full-stop` | `meta:enum` values must end with full stop |

tools/src/main/js/linter/checks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export async function loadAllChecks() {
3636

3737
// Export individual check modules for direct access if needed
3838
export * from './schema-id-pattern.check.js';
39+
export * from './schema-comment.check.js';
3940
export * from './formatting-indent.check.js';
4041
export * from './description-full-stop.check.js';
4142
export * from './meta-enum-full-stop.check.js';
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* CycloneDX Schema Linter - Schema Comment Check
3+
*
4+
* Validates that the root $comment property contains the required
5+
* OWASP CycloneDX standard notice.
6+
*
7+
* @license Apache-2.0
8+
*/
9+
10+
import { LintCheck, registerCheck, Severity } from '../index.js';
11+
12+
/**
13+
* Required $comment text
14+
*/
15+
const REQUIRED_COMMENT = 'OWASP CycloneDX is an Ecma International standard (ECMA-424) developed in collaboration between the OWASP Foundation and Ecma Technical Committee 54 (TC54). The standard is published under a royalty-free patent policy. This JSON schema is the reference implementation and is licensed under the Apache License 2.0.';
16+
17+
/**
18+
* Check that validates the $comment property
19+
*/
20+
class SchemaCommentCheck extends LintCheck {
21+
constructor() {
22+
super(
23+
'schema-comment',
24+
'Schema Comment',
25+
'Validates that the $comment property contains the required standard notice.',
26+
Severity.ERROR
27+
);
28+
}
29+
30+
async run(schema, rawContent, config = {}) {
31+
const issues = [];
32+
33+
const requiredComment = config.requiredComment ?? REQUIRED_COMMENT;
34+
35+
// Check if $comment exists at root level
36+
if (!('$comment' in schema)) {
37+
issues.push(this.createIssue(
38+
'Schema is missing required $comment property.',
39+
'$.$comment',
40+
{ expected: requiredComment }
41+
));
42+
return issues;
43+
}
44+
45+
// Check if $comment matches required value
46+
if (schema.$comment !== requiredComment) {
47+
issues.push(this.createIssue(
48+
'$comment does not match the required standard notice.',
49+
'$.$comment',
50+
{
51+
actual: schema.$comment,
52+
expected: requiredComment
53+
}
54+
));
55+
}
56+
57+
return issues;
58+
}
59+
}
60+
61+
// Create and register the check
62+
const check = new SchemaCommentCheck();
63+
registerCheck(check);
64+
65+
export { SchemaCommentCheck, REQUIRED_COMMENT };
66+
export default check;

0 commit comments

Comments
 (0)