llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Shamili3010 <details> <summary>Changes</summary> Fixed a bug related to JavaScript import wrapping reported in the LLVM GitHub issue tracker. The clang-format, a tool that automatically formats source code, including indentation and whitespace, was splitting JS import statements across multiple lines even when the user's formatting preferences specified that imports should not be wrapped. --- Full diff: https://github.com/llvm/llvm-project/pull/235474.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+7-2) - (modified) clang/unittests/Format/FormatTestJS.cpp (+6) ``````````diff diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index d1f68877ef0339..f7de639ddddb2d 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1643,11 +1643,16 @@ unsigned UnwrappedLineFormatter::format( (!Style.isJavaScript() || !Style.JavaScriptWrapImports)) || (Style.isCSharp() && TheLine.InPPDirective)); // don't split #regions in C# - if (Style.ColumnLimit == 0) { + if (Style.ColumnLimit == 0 && + !(TheLine.Type == LT_ImportStatement && Style.isJavaScript() && + !Style.JavaScriptWrapImports)) { NoColumnLimitLineFormatter(Indenter, Whitespaces, Style, this) .formatLine(TheLine, NextStartColumn + Indent, FirstLine ? FirstStartColumn : 0, DryRun); - } else if (FitsIntoOneLine) { + } else if (FitsIntoOneLine || + (Style.ColumnLimit == 0 && + TheLine.Type == LT_ImportStatement && Style.isJavaScript() && + !Style.JavaScriptWrapImports)) { Penalty += NoLineBreakFormatter(Indenter, Whitespaces, Style, this) .formatLine(TheLine, NextStartColumn + Indent, FirstLine ? FirstStartColumn : 0, DryRun); diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index b405a73bce0860..05d5d91e366368 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2006,6 +2006,12 @@ TEST_F(FormatTestJS, ImportWrapping) { verifyFormat("import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying," " VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying" "} from 'some/module.js';"); + + FormatStyle NoWrapStyle = getGoogleJSStyleWithColumns(0); + NoWrapStyle.JavaScriptWrapImports = false; + verifyFormat("import {aaa, bbb, ccc} from 'abc';", + "import {aaa, bbb, ccc} from 'abc';", NoWrapStyle); + FormatStyle Style = getGoogleJSStyleWithColumns(80); Style.JavaScriptWrapImports = true; verifyFormat("import {\n" `````````` </details> https://github.com/llvm/llvm-project/pull/235474 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
