[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-15 Thread via cfe-commits

https://github.com/eywdck2l closed 
https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-15 Thread via cfe-commits

https://github.com/sstwcw updated 
https://github.com/llvm/llvm-project/pull/66372

>From a736d84df61e3e7c1a4c8b22c7cd1e7524499d64 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Thu, 14 Sep 2023 13:04:56 +
Subject: [PATCH 1/2] [clang-format] Disable string breaking in JS for now

See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.
---
 clang/docs/ClangFormatStyleOptions.rst|  10 +-
 clang/include/clang/Format/Format.h   |  10 +-
 clang/lib/Format/ContinuationIndenter.cpp |  13 +--
 clang/unittests/Format/FormatTestJS.cpp   | 114 +-
 4 files changed, 16 insertions(+), 131 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d5d9faa5c78cffb..4ab0b3a207270dc 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
+ string x = "veryVeryVeryVeryVeryVe" +
+"ryVeryVeryVeryVeryVery" +
+"VeryLongString";
 
  false:
- var x =
+ string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
   C# and JavaScript interpolated strings are not broken.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c7bd356b7faeded..3bf70838d059086 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2062,15 +2062,15 @@ struct FormatStyle {
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
-  /// In C#, Java, and JavaScript:
+  /// In C# and Java:
   /// \code
   ///true:
-  ///var x = "veryVeryVeryVeryVeryVe" +
-  ///"ryVeryVeryVeryVeryVery" +
-  ///"VeryLongString";
+  ///string x = "veryVeryVeryVeryVeryVe" +
+  ///   "ryVeryVeryVeryVeryVery" +
+  ///   "VeryLongString";
   ///
   ///false:
-  ///var x =
+  ///string x =
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6673b5c703b835f..15b9ad41a37af59 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
LineState , bool AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() &&
-(Current.is(TT_SelectorName) ||
- State.Line->startsWith(Keywords.kw_type) ||
- State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON can not be broken. Breaking strings in JavaScript is
+// disabled for now.
+if (Style.isJson() || Style.isJavaScript() || !Style.BreakStringLiterals ||
+!AllowBreak) {
   return nullptr;
 }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 51543d0a54d8561..23b010dbc982684 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
 
-  // Long strings should be broken.
+  // String breaking is disabled for now.
   verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
+   "' ';",
"var literal = ' ';",
getGoogleJSStyleWithColumns(17));
-  verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(18));
-  verifyFormat("var literal =\n"
-   "'' +\n"
-   "' ';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(16));
-  // The quotes should be correct.
-  for (char OriginalQuote : {'\'', '"'}) {
-auto VerifyQuotes = [=](FormatStyle::JavaScriptQuoteStyle StyleQuote,
-char TargetQuote) {
-

[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits

https://github.com/owenca approved this pull request.


https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits


@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
LineState , bool AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() &&
-(Current.is(TT_SelectorName) ||
- State.Line->startsWith(Keywords.kw_type) ||
- State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON can not be broken. Breaking strings in JavaScript is

owenca wrote:

```suggestion
// Strings in JSON cannot be broken. Breaking strings in JavaScript is
```

https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits

https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread Owen Pan via cfe-commits


@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
+ string x = "veryVeryVeryVeryVeryVe" +
+"ryVeryVeryVeryVeryVery" +
+"VeryLongString";
 
  false:
- var x =
+ string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
   C# and JavaScript interpolated strings are not broken.

owenca wrote:

```suggestion
  C# interpolated strings are not broken.
```

https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread via cfe-commits

https://github.com/alexfh approved this pull request.

This is the right call for now. There are multiple contexts in JS, TS and 
libraries like Closure, where simple string literals are expected. Getting all 
of these right may require some back-and-forths, during which clang-format will 
continue producing invalid code. Let's get back to a good state and figure out 
details after that.

https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format


Changes
See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.
--
Full diff: https://github.com/llvm/llvm-project/pull/66372.diff

4 Files Affected:

- (modified) clang/docs/ClangFormatStyleOptions.rst (+5-5) 
- (modified) clang/include/clang/Format/Format.h (+5-5) 
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+4-9) 
- (modified) clang/unittests/Format/FormatTestJS.cpp (+2-112) 



diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d5d9faa5c78cffb..4ab0b3a207270dc 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  
quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongStringquot;;
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = quot;veryVeryVeryVeryVeryVequot; +
- quot;ryVeryVeryVeryVeryVeryquot; +
- quot;VeryLongStringquot;;
+ string x = quot;veryVeryVeryVeryVeryVequot; +
+quot;ryVeryVeryVeryVeryVeryquot; +
+quot;VeryLongStringquot;;
 
  false:
- var x =
+ string x =
  
quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongStringquot;;
 
   C# and JavaScript interpolated strings are not broken.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c7bd356b7faeded..3bf70838d059086 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2062,15 +2062,15 @@ struct FormatStyle {
   ///
quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongStringquot;;
   /// \endcode
   ///
-  /// In C#, Java, and JavaScript:
+  /// In C# and Java:
   /// \code
   ///true:
-  ///var x = quot;veryVeryVeryVeryVeryVequot; +
-  ///quot;ryVeryVeryVeryVeryVeryquot; +
-  ///quot;VeryLongStringquot;;
+  ///string x = quot;veryVeryVeryVeryVeryVequot; +
+  ///   quot;ryVeryVeryVeryVeryVeryquot; +
+  ///   quot;VeryLongStringquot;;
   ///
   ///false:
-  ///var x =
+  ///string x =
   ///
quot;veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongStringquot;;
   /// \endcode
   ///
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6673b5c703b835f..15b9ad41a37af59 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken amp;Current,
LineState amp;State, bool 
AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() amp;amp;
-(Current.is(TT_SelectorName) ||
- State.Line-gt;startsWith(Keywords.kw_type) ||
- State.Line-gt;startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON can not be broken. Breaking strings in JavaScript is
+// disabled for now.
+if (Style.isJson() || Style.isJavaScript() || !Style.BreakStringLiterals ||
+!AllowBreak) {
   return nullptr;
 }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 51543d0a54d8561..23b010dbc982684 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat(quot;var literal = #x27;hello #x27; +\nquot;
quot;#x27;world#x27;;quot;);
 
-  // Long strings should be broken.
+  // String breaking is disabled for now.
   verifyFormat(quot;var literal =\nquot;
-   quot;#x27; #x27; +\nquot;
-   quot;#x27;#x27;;quot;,
+   quot;#x27; #x27;;quot;,
quot;var literal = #x27; 
#x27;;quot;,
getGoogleJSStyleWithColumns(17));
-  verifyFormat(quot;var literal =\nquot;
-   quot;#x27; #x27; +\nquot;
-   quot;#x27;#x27;;quot;,
-   quot;var literal = #x27; 
#x27;;quot;,
-   getGoogleJSStyleWithColumns(18));
-  verifyFormat(quot;var literal =\nquot;
-   quot;#x27;#x27; +\nquot;
-   quot;#x27; #x27;;quot;,
-   quot;var literal = #x27; 
#x27;;quot;,
-   

[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread via cfe-commits

https://github.com/llvmbot labeled 
https://github.com/llvm/llvm-project/pull/66372
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Disable string breaking in JS for now (PR #66372)

2023-09-14 Thread via cfe-commits

https://github.com/sstwcw created 
https://github.com/llvm/llvm-project/pull/66372:

See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.

>From a736d84df61e3e7c1a4c8b22c7cd1e7524499d64 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Thu, 14 Sep 2023 13:04:56 +
Subject: [PATCH] [clang-format] Disable string breaking in JS for now

See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).

The functionality is not mature enough.
---
 clang/docs/ClangFormatStyleOptions.rst|  10 +-
 clang/include/clang/Format/Format.h   |  10 +-
 clang/lib/Format/ContinuationIndenter.cpp |  13 +--
 clang/unittests/Format/FormatTestJS.cpp   | 114 +-
 4 files changed, 16 insertions(+), 131 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index d5d9faa5c78cffb..4ab0b3a207270dc 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2783,17 +2783,17 @@ the configuration (without a prefix: ``Auto``).
  const char* x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
-  In C#, Java, and JavaScript:
+  In C# and Java:
 
   .. code-block:: c++
 
  true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
+ string x = "veryVeryVeryVeryVeryVe" +
+"ryVeryVeryVeryVeryVery" +
+"VeryLongString";
 
  false:
- var x =
+ string x =
  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
   C# and JavaScript interpolated strings are not broken.
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index c7bd356b7faeded..3bf70838d059086 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2062,15 +2062,15 @@ struct FormatStyle {
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
-  /// In C#, Java, and JavaScript:
+  /// In C# and Java:
   /// \code
   ///true:
-  ///var x = "veryVeryVeryVeryVeryVe" +
-  ///"ryVeryVeryVeryVeryVery" +
-  ///"VeryLongString";
+  ///string x = "veryVeryVeryVeryVeryVe" +
+  ///   "ryVeryVeryVeryVeryVery" +
+  ///   "VeryLongString";
   ///
   ///false:
-  ///var x =
+  ///string x =
   ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
   ///
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 6673b5c703b835f..15b9ad41a37af59 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -2237,15 +2237,10 @@ ContinuationIndenter::createBreakableToken(const 
FormatToken ,
LineState , bool AllowBreak) {
   unsigned StartColumn = State.Column - Current.ColumnWidth;
   if (Current.isStringLiteral()) {
-// Strings in JSON can not be broken.
-if (Style.isJson() || !Style.BreakStringLiterals || !AllowBreak)
-  return nullptr;
-
-// Strings in TypeScript types and dictionary keys can not be broken.
-if (Style.isJavaScript() &&
-(Current.is(TT_SelectorName) ||
- State.Line->startsWith(Keywords.kw_type) ||
- State.Line->startsWith(tok::kw_export, Keywords.kw_type))) {
+// Strings in JSON can not be broken. Breaking strings in JavaScript is
+// disabled for now.
+if (Style.isJson() || Style.isJavaScript() || !Style.BreakStringLiterals ||
+!AllowBreak) {
   return nullptr;
 }
 
diff --git a/clang/unittests/Format/FormatTestJS.cpp 
b/clang/unittests/Format/FormatTestJS.cpp
index 51543d0a54d8561..23b010dbc982684 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
   verifyFormat("var literal = 'hello ' +\n"
"'world';");
 
-  // Long strings should be broken.
+  // String breaking is disabled for now.
   verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
+   "' ';",
"var literal = ' ';",
getGoogleJSStyleWithColumns(17));
-  verifyFormat("var literal =\n"
-   "' ' +\n"
-   "'';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(18));
-  verifyFormat("var literal =\n"
-   "'' +\n"
-   "' ';",
-   "var literal = ' ';",
-   getGoogleJSStyleWithColumns(16));
-  // The quotes should be correct.
-  for (char OriginalQuote :