This revision was automatically updated to reflect the committed changes. Closed by commit rG9835cf159014: clang-format: [JS] pragmas for tslint, tsc. (authored by mprobst).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D72907/new/ https://reviews.llvm.org/D72907 Files: clang/lib/Format/Format.cpp clang/unittests/Format/FormatTestJS.cpp Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -2168,6 +2168,38 @@ getGoogleJSStyleWithColumns(20))); } +TEST_F(FormatTestJS, TslintComments) { + // tslint uses pragma comments that must be on their own line. + verifyFormat("// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs\n" + "// wrapping. Trailing line.\n" + "// tslint:disable-next-line:must-be-on-own-line", + "// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs wrapping.\n" + "// Trailing line.\n" + "// tslint:disable-next-line:must-be-on-own-line"); +} + +TEST_F(FormatTestJS, TscComments) { + // As above, @ts-ignore and @ts-check comments must be on their own line. + verifyFormat("// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs\n" + "// wrapping. Trailing line.\n" + "// @ts-ignore", + "// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs wrapping.\n" + "// Trailing line.\n" + "// @ts-ignore"); + verifyFormat("// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs\n" + "// wrapping. Trailing line.\n" + "// @ts-check", + "// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs wrapping.\n" + "// Trailing line.\n" + "// @ts-check"); +} + TEST_F(FormatTestJS, RequoteStringsSingle) { verifyFormat("var x = 'foo';", "var x = \"foo\";"); verifyFormat("var x = 'fo\\'o\\'';", "var x = \"fo'o'\";"); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -939,9 +939,9 @@ GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; GoogleStyle.BreakBeforeTernaryOperators = false; - // taze:, triple slash directives (`/// <...`), @see, which is commonly - // followed by overlong URLs. - GoogleStyle.CommentPragmas = "(taze:|^/[ \t]*<|@see)"; + // taze:, triple slash directives (`/// <...`), tslint:, and @see, which is + // commonly followed by overlong URLs. + GoogleStyle.CommentPragmas = "(taze:|^/[ \t]*<|tslint:|@see)"; GoogleStyle.MaxEmptyLinesToKeep = 3; GoogleStyle.NamespaceIndentation = FormatStyle::NI_All; GoogleStyle.SpacesInContainerLiterals = false;
Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -2168,6 +2168,38 @@ getGoogleJSStyleWithColumns(20))); } +TEST_F(FormatTestJS, TslintComments) { + // tslint uses pragma comments that must be on their own line. + verifyFormat("// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs\n" + "// wrapping. Trailing line.\n" + "// tslint:disable-next-line:must-be-on-own-line", + "// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs wrapping.\n" + "// Trailing line.\n" + "// tslint:disable-next-line:must-be-on-own-line"); +} + +TEST_F(FormatTestJS, TscComments) { + // As above, @ts-ignore and @ts-check comments must be on their own line. + verifyFormat("// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs\n" + "// wrapping. Trailing line.\n" + "// @ts-ignore", + "// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs wrapping.\n" + "// Trailing line.\n" + "// @ts-ignore"); + verifyFormat("// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs\n" + "// wrapping. Trailing line.\n" + "// @ts-check", + "// Comment that needs wrapping. Comment that needs wrapping. " + "Comment that needs wrapping.\n" + "// Trailing line.\n" + "// @ts-check"); +} + TEST_F(FormatTestJS, RequoteStringsSingle) { verifyFormat("var x = 'foo';", "var x = \"foo\";"); verifyFormat("var x = 'fo\\'o\\'';", "var x = \"fo'o'\";"); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -939,9 +939,9 @@ GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty; GoogleStyle.AlwaysBreakBeforeMultilineStrings = false; GoogleStyle.BreakBeforeTernaryOperators = false; - // taze:, triple slash directives (`/// <...`), @see, which is commonly - // followed by overlong URLs. - GoogleStyle.CommentPragmas = "(taze:|^/[ \t]*<|@see)"; + // taze:, triple slash directives (`/// <...`), tslint:, and @see, which is + // commonly followed by overlong URLs. + GoogleStyle.CommentPragmas = "(taze:|^/[ \t]*<|tslint:|@see)"; GoogleStyle.MaxEmptyLinesToKeep = 3; GoogleStyle.NamespaceIndentation = FormatStyle::NI_All; GoogleStyle.SpacesInContainerLiterals = false;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits