-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[clangd] Clean formatting modernize-use-override #81435
[clangd] Clean formatting modernize-use-override #81435
Conversation
When applying the recommended fix for the "modernize-use-override" clang-tidy diagnostic there was a stray whitespace. This commit fixes: clangd/clangd#1704
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clangd @llvm/pr-subscribers-clang-tools-extra Author: Kevin Joseph (kevinjoseph1995) ChangesWhen applying the recommended fix for the Full diff: https://github.com/llvm/llvm-project/pull/81435.diff 2 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index e348968b325a5a..4db32b02ee5a0c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -228,8 +228,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult &Result) {
if (HasVirtual) {
for (Token Tok : Tokens) {
if (Tok.is(tok::kw_virtual)) {
- Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
- Tok.getLocation(), Tok.getLocation()));
+ Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
+ Tok.getLocation(), Tok.getEndLoc().getLocWithOffset(1)));
break;
}
}
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index f302dcf5f09db0..76874ac9a2a4e7 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -898,6 +898,34 @@ TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
withFix(equalToFix(ExpectedDFix))))));
}
+TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {
+ Annotations Main(R"cpp(
+ class Interface {
+ public:
+ virtual void Reset() = 0;
+ };
+ class A : public Interface {
+ // This will be marked by clangd to use override instead of virtual
+ $virtual[[virtual ]] void $Reset[[Reset]]()$override[[]];
+ };
+ )cpp");
+ TestTU TU = TestTU::withCode(Main.code());
+ TU.ClangTidyProvider =
+ addTidyChecks("cppcoreguidelines-explicit-virtual-functions,");
+ clangd::Fix const ExpectedFix{"prefer using 'override' or (rarely) 'final' "
+ "instead of 'virtual'",
+ {TextEdit{Main.range("override"), " override"},
+ TextEdit{Main.range("virtual"), ""}}};
+ // Note that in the Fix we expect the "virtual" keyword and the following
+ // whitespace to be deleted
+ EXPECT_THAT(TU.build().getDiagnostics(),
+ ifTidyChecks(UnorderedElementsAre(
+ AllOf(Diag(Main.range("Reset"),
+ "prefer using 'override' or (rarely) 'final' "
+ "instead of 'virtual'"),
+ withFix(equalToFix(ExpectedFix))))));
+}
+
TEST(DiagnosticsTest, Preprocessor) {
// This looks like a preamble, but there's an #else in the middle!
// Check that:
|
Release notes entry (for clang-tidy) is also missing. |
Added a small entry to the Release notes. I wasn't sure about which section to add it to. Please let me know me if that isn't the right one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small fix in release notes needed.
If with this change tests are passing, then it's looking fine for me.
ninja check-clang-tools reports the following:
And all of the ClangdTests pass as well:
|
@kevinjoseph1995 Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace. This PR fixes that.
Resolves clangd/clangd#1704