This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add support for new TODO style to google-readability-todo
Needs ReviewPublic

Authored by ymandel on May 18 2023, 7:47 AM.

Details

Summary

Google style is changing to encourage a different (and more common) form of
TODO, specifically: TODO: link - description. This patch adds support for the
new style, while maintaining backwards compatability with the old style. The
patch adds a configuration option to the check to control which style (V1 or V2)
is checked.

Diff Detail

Event Timeline

ymandel created this revision.May 18 2023, 7:47 AM
ymandel requested review of this revision.May 18 2023, 7:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 18 2023, 7:47 AM
njames93 added inline comments.May 18 2023, 9:39 AM
clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
97

Given this check is part of the google module, doesn't it make sense to have the default as what google now recommends.

clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst
6

Maybe update this line to something along with lines of
Finds TODO comments not conforming to googles style guidelines

16–18

This shouldn't appear in the options, as it isn't read from the CheckOptions

22

It would be good to specify the default value of this option(or just the default behaviour of the check)

ymandel updated this revision to Diff 523440.May 18 2023, 10:31 AM

Address reviewer comments.

ymandel marked 3 inline comments as done.May 18 2023, 10:32 AM

Thank you for the very fast review!

clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
97

The style guide hasn't been updated yet. Once that happens, I think we should switch the default. I can add a FIXME -- what do you think?

I'd be more comfortable reviewing this after it's actually been added to the style guide, it's hard to refer to non-public docs and discussions here.

I don't really understand the rationale for the hard split into two modes, vs always accepting both styles and maybe just making the fixit style configurable.
(OTOH If we *really* want to support exclusive use of the old style, why are we not supporting exclusive use of the new style?)

clang-tools-extra/clang-tidy/google/TodoCommentCheck.cpp
18

I'd really prefer if we could give these names rather than numbers. Best I can come up with is paren-style/hyphen style though.

Either way, we can drop "version" as it's redundant with "style".
(Unless you're using it to refer to the version of the style *guide*/check logic in which case it's confusing to also use it to refer to the style of the comment, as these aren't 1:1)

79

I find this part very confusing. We have two separate implementations that check whether this is a valid TODO(context): description comment, even though that's acceptable in all modes. Why?

It seems like the logic should look either like:

if (!isAnyTODOComment) // regex #1
  return;
if (isValidParenStyleTODO) // regex #2
  return;
if (allowNewStyle && isValidHyphenStyleTODO) // regex #3
  return;
diag(...) << Fix; // suggestion based on preferred style and parse from isAnyTODOComment

or

if (!matchesComplicatedAllEncompassingRegex)
  return;
if (submatchesIndicateValidParenStyleTODO)
  return;
if (submatchesIndicateValidHyphenStyleTODO)
  return;
// diagnose and suggest fix
85

this isn't accurate: TODO(username): description is still valid.
Maybe "should have"?

clang-tools-extra/docs/clang-tidy/checks/google/readability-todo.rst
16

This is a confusing option name.

It's not clear what "V2Style" is, it's non-descriptive and the style guide won't use that term.
It's not clear what "Use" means - in fixes? Only accept? My code uses V2 style?

Based on the current behavior, I'd suggest "PreferHyphenStyle"

32

I think trying to enforce a new style via a check that doesn't suggest or even describe the style is a mistake.

Given TODO: text, text is almost certainly a description - creating an appropriate link is a chore, but IME ~nobody forgets to actually write what they want to do.
If the suggestion is wrong, people can fix it. The most important thing is we tell them what the expected format is.

clang-tools-extra/test/clang-tidy/checkers/google/readability-todo-v2.cpp
21

(surely this example shows how absurd this style is...)

24

"supported for backwards compatibility" is stronger than the text I've seen, which simply says they're discouraged in new code. But for example if you don't have a bug link, AFAICS TODO(username): is the only possible form.