[PATCH] D63482: [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value

Ivan Donchevskii via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 03:14:57 PDT 2019


yvvan created this revision.
yvvan added reviewers: gribozavr, nik.
Herald added a subscriber: xazax.hun.

Currently this check generates the replacement with the newline in the end. The proper way to export it to YAML is to have two \n\n instead of one.

Without this fix clients should reinterpret the replacement as "#include <utility> " instead of "#include <utility>\n"


https://reviews.llvm.org/D63482

Files:
  clang/include/clang/Tooling/ReplacementsYaml.h


Index: clang/include/clang/Tooling/ReplacementsYaml.h
===================================================================
--- clang/include/clang/Tooling/ReplacementsYaml.h
+++ clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,7 +35,15 @@
 
     NormalizedReplacement(const IO &, const clang::tooling::Replacement &R)
         : FilePath(R.getFilePath()), Offset(R.getOffset()),
-          Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
+          Length(R.getLength()), ReplacementText(R.getReplacementText()) {
+      size_t lineBreakPos = ReplacementText.find('\n');
+      while (lineBreakPos != std::string::npos) {
+        // Replace this occurrence of Sub String
+        ReplacementText.replace(lineBreakPos, 1, "\n\n");
+        // Get the next occurrence from the current position
+        lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
+      }
+    }
 
     clang::tooling::Replacement denormalize(const IO &) {
       return clang::tooling::Replacement(FilePath, Offset, Length,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63482.205289.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190618/6560d670/attachment-0001.bin>


More information about the cfe-commits mailing list