This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Abseil: faster strsplit delimiter check
ClosedPublic

Authored by deannagarcia on Aug 16 2018, 1:36 PM.

Details

Summary

This check is an abseil specific check that checks for code using single character string literals as delimiters and transforms the code into characters.

The check was developed internally and has been running in google3 code, this is just a move to open source the check. It was originally written by @sbenza

Diff Detail

Event Timeline

deannagarcia created this revision.Aug 16 2018, 1:36 PM
JonasToth set the repository for this revision to rCTE Clang Tools Extra.
JonasToth added inline comments.
clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
25

you dont need the ast_matchers namespace as there is a using namespace ast_matchers at the top, same at other places.

50

The comment suggest, that all single quotes need to be escaped and then further processing happens, but you check on identity to ' and return the escaped version of it.
That confuses me.

55

This expects at max 2 " characters. couldnt there be more?

72

Please make the comments full sentences

76

What about the std::string_view?

109

Please dont use auto here

119

You can configure this diagnostic with %select{option1|option2}.

See https://clang.llvm.org/docs/InternalsManual.html#formatting-a-diagnostic-argument
or bugprone/ForwardingReferenceOverloadCheck.cpp line 133 as an example (there are of course other places that technique is used)

120

This diagnostic is really long, maybe you can shorten it a bit?

E.g. consider using character overload for the second part
and .. called with single character string literal;

My diagnostics are usually not so good, maybe you come up with something better :)

clang-tidy/abseil/FasterStrsplitDelimiterCheck.h
21

s/replaces with/replaces it with/

docs/ReleaseNotes.rst
63

Please highlight code with two `

docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
9

I think:
It will also catch code using ...

sounds a little better

test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
43

Please add a test, where "A" is used as an arbitray function argument (similar to the template case, but without templates involved)

Eugene.Zelenko added inline comments.
docs/clang-tidy/checks/abseil-faster-strsplit-delimiter.rst
7

Please make first statement same as in Release Notes. Please also avoid this check.

22

Please separate before and after with empty line. Same in other places.

hokein added a subscriber: sbenza.Aug 17 2018, 7:09 AM

Thanks for porting the check to upstream (context: the check was developed internally, and has been run on our codebase for a while, it is pretty stable). Could you please update the patch message to indicate this is a porting change, and add the original check author @sbenza in the patch description?

deannagarcia edited the summary of this revision. (Show Details)Aug 17 2018, 7:40 AM
deannagarcia marked 10 inline comments as done.
deannagarcia added inline comments.
clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
50

Does the new comment clear it up?

55

The only way this will be run is if the string is a single character, so the only possibility if there are more than 2 " characters is that the character that is the delimiter is actually " which is taken care of in the check. Does that make sense/do you think I need to add a comment about this?

76

This matcher is only here for the next matcher to check to see if absl::ByAnyChar has been passed in a single character string view and is only necessary because ByAnyChar accepts an absl::string_view so it isn't necessary to make one for std::string_view

test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
43

Can you explain this more/provide an example?

JonasToth added inline comments.Aug 18 2018, 8:36 AM
clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
50

Yes, thank you.

55

Ok I see, you could add an assertion before this section. Having the precondition checked is always a good thing and usually adds clarity as well :)

76

Ok.

86

Maybe you could make these comments into full sentences. I do think its clear what they mean, but the rule is full sentences.

Maybe Find uses of 'absl::...' to transform them into 'absl::...'.?

116

You can ellide the braces in this case.

test/clang-tidy/abseil-faster-strsplit-delimiter.cpp
43

The testcase i had in mind does not make sense, sorry for noise.

deannagarcia marked 11 inline comments as done.
deannagarcia added inline comments.
clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
55

I can't think of a simple thing to assert because most literals will look like: "a" but there is also the possibility that it looks like "\"" and I can't think of an easy way to combine those two. Do you have an idea/maybe I could just put a comment at the beginning saying this is only meant for single character string literals?

JonasToth added inline comments.Aug 20 2018, 6:57 AM
clang-tidy/abseil/FasterStrsplitDelimiterCheck.cpp
55

Wouldnt that result in an assert approximatly this:

assert(Result.size() == 1 || (Result.size() == 2 && Result.startswith('\\'))

Stating the size constraint alone is already a valuable assert in my opinion.

86

These comments seem to be longer then 80, if true please wrap them.

deannagarcia marked 6 inline comments as done.
hokein accepted this revision.Aug 21 2018, 1:20 AM

The patch looks good. I'll commit for you once @JonasToth has no further comments.

This revision is now accepted and ready to land.Aug 21 2018, 1:20 AM
hokein closed this revision.Aug 22 2018, 7:00 AM

Committed in rL340411.