Moved the files and moved the test inputs, adjusting for use within clang-tidy instead of as a standalone utility.
Diff Detail
Event Timeline
It looks like if you add reviewers and subscribers after creating a differential revision, Phabricator won't send notification mails to them (unless you add a comment afterwards). In any case, it makes sense double-checking that a message found its way to cfe-commits at least.
Thanks for the patch! A few comments inline.
clang-tidy/misc/MiscTidyModule.cpp | ||
---|---|---|
39 ↗ | (On Diff #19104) | I'd put this check under readability/ and call it "readability-redundant-cstr-calls". |
clang-tidy/misc/RemoveCStrCall.cpp | ||
32 ↗ | (On Diff #19104) | I suspect that most of this method can be replaced to a call to clang::Lexer::getSourceText (and this method can return StringRef). |
84 ↗ | (On Diff #19104) | Seems like a good use case for "auto". |
171 ↗ | (On Diff #19104) | nit: Please remove the trailing period. I'd also use 'c_str()' instead of c_str. |
test/clang-tidy/misc-remove-cstr-call.cpp | ||
23 ↗ | (On Diff #19104) | Please make the check more specific to avoid incorrect matches: // CHECK-FIXES: {{^ }}f1(s);{{$}} |
28 ↗ | (On Diff #19104) | This should be CHECK-FIXES:. Please also add CHECK-MESSAGES to verify the error messages. // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant call .... |
I don't have a problem with making this a clang-tidy module, but it was (also) meant as an example of how to write a refactoring tool.
I didn't find any references to remove-cstr-calls from docs, so I don't think the tool is in any sense special. There is a clang-rename which can be used as an example of a refactoring tool, and there is a dedicated tool-template. IMO, these should be enough.
clang-tidy/readability/RemoveCStrCall.cpp | ||
---|---|---|
37 ↗ | (On Diff #19873) | Use isa<> instead |
Use isa<> instead of dyn_cast<>.
Move the check from namespace clang::tidy into namespace clang::tidy::readability
clang-tidy/readability/RemoveCStrCall.cpp | ||
---|---|---|
23 ↗ | (On Diff #20937) | clang-format? |
50 ↗ | (On Diff #20937) | clang-format? |
58 ↗ | (On Diff #20937) | It's better to make this a StringRef and replace the concatenation of strings below with: return (llvm::Twine("*(") + Text + ")").str(). |
129 ↗ | (On Diff #20937) | This is a good place to use auto or const auto *. |
131 ↗ | (On Diff #20937) | s/const bool/bool/ |
134 ↗ | (On Diff #20937) | s/const std::string/std::string/ |
136 ↗ | (On Diff #20937) | Why static_cast instead of .str()? |
clang-tidy/readability/RemoveCStrCall.h | ||
20 ↗ | (On Diff #20937) | The fact that it removes something doesn't make it much different from other checks, and it doesn't deserve a place in the name. Let's call this check "readability-redundant-cstr" or "readability-redundant-cstr-calls" instead (and the class RedundantCStrCheck or RedundantCStrCallsCheck). I posted a relevant comment earlier, but it has fallen through the cracks. |
Run clang-format on the source files.
Use the name readability-redundant-cstr-call for the check.
Update types of locals as requested
Thanks for updating this. However could you use one of the alternatives I suggested? If you lean toward using 'call' in the name, let it be readability-redundant-cstr-calls and correspondingly RedundantCStrCallsCheck for the name of the class and the source files. Something seems wrong to me in using singular call in the name of this check, as it's supposed to find any number of them, not just one. Also note the Check suffix for the class name (and corresponding file names. It's kind of a naming convention for the checks.
Thanks.
For the reference, here's my previous comment:
The fact that it removes something doesn't make it much different from other checks, and it doesn't deserve a place in the name. Let's call this check "readability-redundant-cstr" or "readability-redundant-cstr-calls" instead (and the class RedundantCStrCheck or RedundantCStrCallsCheck).
clang-tidy/misc/MiscTidyModule.cpp | ||
---|---|---|
39 ↗ | (On Diff #19104) | Fixed. |
clang-tidy/misc/RemoveCStrCall.cpp | ||
32 ↗ | (On Diff #19104) | Fixed. |
84 ↗ | (On Diff #19104) | Fixed. |
171 ↗ | (On Diff #19104) | Fixed |
clang-tidy/readability/RemoveCStrCall.cpp | ||
23 ↗ | (On Diff #20937) | Fixed. |
50 ↗ | (On Diff #20937) | Fixed. |
58 ↗ | (On Diff #20937) | Fixed |
129 ↗ | (On Diff #20937) | Fixed. |
131 ↗ | (On Diff #20937) | Fixed. |
134 ↗ | (On Diff #20937) | Fixed. |
136 ↗ | (On Diff #20937) | Fixed. |
37 ↗ | (On Diff #19873) | Fixed. |
clang-tidy/readability/RemoveCStrCall.h | ||
20 ↗ | (On Diff #20937) | Fixed. |
10–11 ↗ | (On Diff #19867) | Fixed. |
test/clang-tidy/misc-remove-cstr-call.cpp | ||
23 ↗ | (On Diff #19104) | Fixed. |
28 ↗ | (On Diff #19104) | Fixed. |
clang-tidy/readability/RemoveCStrCall.h | ||
---|---|---|
20 ↗ | (On Diff #20937) | I was thinking about names; we have RedundantSmartPtrGet and check name readability-redundant-smartptr-get, a check for redundant calls to get() on a smartptr class. Would that make this RedundantStringCStr and check name readability-redundant-string-cstr? |
clang-tidy/readability/RemoveCStrCall.h | ||
---|---|---|
20 ↗ | (On Diff #20937) | I'd prefer the checks have the Check suffix in the class name. This convention is not strictly followed, but it probably should. The motivation is discussed in this review thread: http://reviews.llvm.org/D4189. Thus it can be RedundantStringCStrCheck and the check name readability-redundant-string-cstr. |
clang-tidy/readability/RemoveCStrCall.h | ||
---|---|---|
20 ↗ | (On Diff #20937) | Sounds good, I'll see if I can update that tonight. I did notice that not all checks had classes ending in Check. I'll create another changeset that fixes that. |
Improve the naming to be more consistent with other checks:
RedundantStringCStrCheck
readability-redundant-string-cstr
The code looks fine now, but if you don't mind, I'd ask you to fix a few more nits (mostly left from the original tool's code). Once done, I'd be happy to commit the patch for you.
Thanks!
clang-tidy/readability/RedundantStringCStrCheck.cpp | ||
---|---|---|
39 | s/const auto/const auto*/ | |
39 | Use LLVM naming style: Op | |
52 | s/const auto/const auto*/ | |
68 | const char StringConstructor[] = ... | |
72 | ditto | |
93 | id is an old-style construct, now we prefer using .bind(): id("...", X) -> X.bind("...") | |
96 | ditto | |
117 | ditto | |
120 | ditto | |
125 | const auto* | |
test/clang-tidy/readability-redundant-string-cstr.cpp | ||
25 | nit: The number of spaces here should remain the same, so I'd better replace {{^ *}} with {{^ }}. |
Prefer bind() over id()
Change types to be more consistent with llvm/clang
Chang header guard to be more consistent with llvm/clang
Make test cases more specific.
test/clang-tidy/readability-redundant-string-cstr.cpp | ||
---|---|---|
25 | Fixed |
s/const auto/const auto*/