Created
August 29, 2025 16:30
-
-
Save KelWill/7396a63e7405b527ffd7413059aa951b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const todoRegex = /^\s*todo /i; | |
| const taggedTodoRegex = /^\s*todo [-a-z0-9_]+ \d{4}-\d{2}-\d{2} /i; | |
| module.exports = { | |
| meta: { | |
| type: "problem", | |
| docs: { | |
| description: | |
| "Disallow TODO comments unless they follow the format '// TODO github_username YYYY-MM-DD'", | |
| category: "Best Practices", | |
| recommended: false, | |
| }, | |
| schema: [], | |
| messages: { | |
| invalidTodo: | |
| "TODO comments must be in the format '// TODO github_username YYYY-MM-DD'.", | |
| }, | |
| }, | |
| create(context) { | |
| return { | |
| Program() { | |
| const sourceCode = context.getSourceCode(); | |
| const comments = sourceCode.getAllComments(); | |
| for (const comment of comments) { | |
| const commentValue = comment.value; | |
| if (!todoRegex.test(commentValue)) continue; | |
| if (taggedTodoRegex.test(commentValue)) continue; | |
| context.report({ | |
| loc: comment.loc, | |
| messageId: "invalidTodo", | |
| }); | |
| } | |
| }, | |
| }; | |
| }, | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment