This revision was automatically updated to reflect the committed changes. Closed by commit rL293878: [clang-format] Don't reflow lines starting with TODO, FIXME or XXX. (authored by krasimir).
Changed prior to commit: https://reviews.llvm.org/D29396?vs=86643&id=86781#toc Repository: rL LLVM https://reviews.llvm.org/D29396 Files: cfe/trunk/lib/Format/BreakableToken.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/lib/Format/BreakableToken.cpp =================================================================== --- cfe/trunk/lib/Format/BreakableToken.cpp +++ cfe/trunk/lib/Format/BreakableToken.cpp @@ -301,12 +301,21 @@ static bool mayReflowContent(StringRef Content) { Content = Content.trim(Blanks); + // Lines starting with '@' commonly have special meaning. + static const SmallVector<StringRef, 4> kSpecialMeaningPrefixes = { + "@", "TODO", "FIXME", "XXX"}; + bool hasSpecialMeaningPrefix = false; + for (StringRef Prefix : kSpecialMeaningPrefixes) { + if (Content.startswith(Prefix)) { + hasSpecialMeaningPrefix = true; + break; + } + } // Simple heuristic for what to reflow: content should contain at least two // characters and either the first or second character must be // non-punctuation. - return Content.size() >= 2 && - // Lines starting with '@' commonly have special meaning. - !Content.startswith("@") && !Content.endswith("\\") && + return Content.size() >= 2 && !hasSpecialMeaningPrefix && + !Content.endswith("\\") && // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is // true, then the first code point must be 1 byte long. (!isPunctuation(Content[0]) || !isPunctuation(Content[1])); Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -2306,6 +2306,30 @@ format("// long long long long\n" "// @param arg", getLLVMStyleWithColumns(20))); + + // Don't reflow lines starting with 'TODO'. + EXPECT_EQ("// long long long\n" + "// long\n" + "// TODO: long", + format("// long long long long\n" + "// TODO: long", + getLLVMStyleWithColumns(20))); + + // Don't reflow lines starting with 'FIXME'. + EXPECT_EQ("// long long long\n" + "// long\n" + "// FIXME: long", + format("// long long long long\n" + "// FIXME: long", + getLLVMStyleWithColumns(20))); + + // Don't reflow lines starting with 'XXX'. + EXPECT_EQ("// long long long\n" + "// long\n" + "// XXX: long", + format("// long long long long\n" + "// XXX: long", + getLLVMStyleWithColumns(20))); // Reflow lines that have a non-punctuation character among their first 2 // characters.
Index: cfe/trunk/lib/Format/BreakableToken.cpp =================================================================== --- cfe/trunk/lib/Format/BreakableToken.cpp +++ cfe/trunk/lib/Format/BreakableToken.cpp @@ -301,12 +301,21 @@ static bool mayReflowContent(StringRef Content) { Content = Content.trim(Blanks); + // Lines starting with '@' commonly have special meaning. + static const SmallVector<StringRef, 4> kSpecialMeaningPrefixes = { + "@", "TODO", "FIXME", "XXX"}; + bool hasSpecialMeaningPrefix = false; + for (StringRef Prefix : kSpecialMeaningPrefixes) { + if (Content.startswith(Prefix)) { + hasSpecialMeaningPrefix = true; + break; + } + } // Simple heuristic for what to reflow: content should contain at least two // characters and either the first or second character must be // non-punctuation. - return Content.size() >= 2 && - // Lines starting with '@' commonly have special meaning. - !Content.startswith("@") && !Content.endswith("\\") && + return Content.size() >= 2 && !hasSpecialMeaningPrefix && + !Content.endswith("\\") && // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is // true, then the first code point must be 1 byte long. (!isPunctuation(Content[0]) || !isPunctuation(Content[1])); Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -2306,6 +2306,30 @@ format("// long long long long\n" "// @param arg", getLLVMStyleWithColumns(20))); + + // Don't reflow lines starting with 'TODO'. + EXPECT_EQ("// long long long\n" + "// long\n" + "// TODO: long", + format("// long long long long\n" + "// TODO: long", + getLLVMStyleWithColumns(20))); + + // Don't reflow lines starting with 'FIXME'. + EXPECT_EQ("// long long long\n" + "// long\n" + "// FIXME: long", + format("// long long long long\n" + "// FIXME: long", + getLLVMStyleWithColumns(20))); + + // Don't reflow lines starting with 'XXX'. + EXPECT_EQ("// long long long\n" + "// long\n" + "// XXX: long", + format("// long long long long\n" + "// XXX: long", + getLLVMStyleWithColumns(20))); // Reflow lines that have a non-punctuation character among their first 2 // characters.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits