diff options
author | Martin Probst <martin@probst.io> | 2020-01-17 10:44:10 +0100 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2020-01-17 13:39:05 +0100 |
commit | 9835cf159014f40e8ea655d0bb3a341ef7ec34f7 (patch) | |
tree | 0bf414f01612b87e29cc9448511b0dd038097bdc /clang/unittests/Format/FormatTestJS.cpp | |
parent | 33463cfba2be7c8d6c08e666123cc34f114a1f3e (diff) | |
download | llvm-9835cf159014f40e8ea655d0bb3a341ef7ec34f7.zip llvm-9835cf159014f40e8ea655d0bb3a341ef7ec34f7.tar.gz llvm-9835cf159014f40e8ea655d0bb3a341ef7ec34f7.tar.bz2 |
clang-format: [JS] pragmas for tslint, tsc.
Summary:
tslint and tsc (the TypeScript compiler itself) use comment pragmas of
the style:
// tslint:disable-next-line:foo
// @ts-ignore
These must not be wrapped and must stay on their own line, in isolation.
For tslint, this required adding it to the pragma regexp. The comments
starting with `@` are already left alone, but this change adds test
coverage for them.
Reviewers: krasimir
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D72907
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 0150b43..ffeb53d9 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2168,6 +2168,38 @@ TEST_F(FormatTestJS, JSDocAnnotations) { 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'\";"); |