Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/src/main/js/linter/checks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ export * from './enum-value-formatting.check.js';
export * from './enum-value-no-other.check.js';
export * from './duplicate-content.check.js';
export * from './duplicate-definitions.check.js';
export * from './no-todos.check.js';

70 changes: 70 additions & 0 deletions tools/src/main/js/linter/checks/no-todos.check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* CycloneDX Schema Linter - No ToDo's Check
*
* @license Apache-2.0
*/

import { LintCheck, registerCheck, Severity, traverseSchema } from '../index.js';

/**
* Patterns to detect ToDo's
*/
const TODO_PATTERNS = /\bToDo\b/i

const DOCS_KEYS = Object.freeze(new Set([
'$comment',
'title',
'description',
]))

/**
* Check that validates there are no ToDo's
*/
class NoTodosCheck extends LintCheck {
constructor() {
super(
'no-todos',
'No ToDo\'s',
'Validates that there are no ToDo\'s' ,
Severity.ERROR
);
}

async run(schema, rawContent, config = {}) {
const issues = [];

// Allow "must" in specific contexts
const allowInContext = config.allowInContext ?? false;

traverseSchema(schema, (node, path, key, parent) => {
if (TODO_PATTERNS.test(key)) {
issues.push(this.createIssue(
`There is an open ToDo`,
path,
{ key }
));
}

if (typeof node !== 'string') return;

if (!DOCS_KEYS.has(key)) return;

if (TODO_PATTERNS.test(node)) {
issues.push(this.createIssue(
`There is an open ToDO: ${node}`,
path,
{ text: node }
));
}
});

return issues;
}
}

// Create and register the check
const check = new NoTodosCheck();
registerCheck(check);

export { NoTodosCheck };
export default check;
Loading