Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

todo_comment_linter could get an argument for valid TODO patterns #2047

Closed
MichaelChirico opened this issue Aug 5, 2023 · 5 comments · Fixed by #2439
Closed

todo_comment_linter could get an argument for valid TODO patterns #2047

MichaelChirico opened this issue Aug 5, 2023 · 5 comments · Fixed by #2439
Labels
feature a feature request or enhancement
Milestone

Comments

@MichaelChirico
Copy link
Collaborator

This can allow TODO only if they fit certain patterns.

This could be used to enforce a rule like "All TODO must be tied to a bug, not a person".

## BAD
# TODO(michaelchirico): fix this
# TODO: add testing

## GOOD
# TODO(#nnn): fix this
# TODO(#mmm): add testing

Maybe an argument like allow_regex or allow_style_regex, in this case allow_regex = "TODO[(][#][0-9]+[)]:" could work.

@MichaelChirico MichaelChirico added the feature a feature request or enhancement label Aug 5, 2023
@AshesITR
Copy link
Collaborator

AshesITR commented Aug 5, 2023

Maybe just expose the regex as an optional argument and call it regex=?

todo_comment_linter(regex = "# TODO\\(#\\d+\\):") seems fine to me.

@MichaelChirico
Copy link
Collaborator Author

The question then is how to interact this with the existing todo argument:

todo_comment_linter <- function(todo = c("todo", "fixme")) {

Should we be looking for matches of paste0(todo, regex)? Then the call would be todo_comment_linter(regex = "\\(#\\d+\\):").

@AshesITR
Copy link
Collaborator

AshesITR commented Aug 6, 2023

I would let regex take precedence with a warning if both arguments are present.

@MichaelChirico
Copy link
Collaborator Author

After #2433, I'm thinking the approach here will be:

function(todo = c("todo", "fixme"), except_regex = NULL)

Where except_regex is used to filter out lints matched by todo. It also makes sense verbally: Don't use todo unless it matches one of except_regex.

I think we should support case-sensitive matching too -- I would want TODO(#1234) to be OK but not todo(#1234). Probably letting todo= be case-insenstive but except_regex= case-sensitive makes sense, otherwise we could add a third argument.

@AshesITR
Copy link
Collaborator

I don't think we need a third argument. You can simply turn on ignore-case by prepending except_regex with "(?i)" if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants