|
| 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