[PATCH] D116638: [clang-format] Fix ignoring JavaScriptWrapImport when ColumnWidth: 0
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 5 07:57:48 PST 2022
mprobst added inline comments.
================
Comment at: clang/docs/ClangFormatStyleOptions.rst:2827
-**JavaScriptWrapImports** (``Boolean``) :versionbadge:`clang-format 3.9`
- Whether to wrap JavaScript import/export statements.
+ * If ``ColumnWidth`` is 0 (no limit on the number of columns), then import
+ statements will keep the number of lines they start with.
----------------
andmis wrote:
> HazardyKnusperkeks wrote:
> > mprobst wrote:
> > > this seems odd to me: my understanding is that clang-format always reflows the entire document, there's no logic to ever "keep" whitespace.
> > >
> > > Are you sure you are seeing this behaviour? The logic change below sounds more as if the ColumnWidth: 0, import lines might not break (mustBreak returns false), but might still break?
> > From what I can tell with `ColumnLimit` (and not `ColumnWidth`) 0, then `clang-format` does many things differently. If by design or by accident I'm not sure. I can see that often, since I format my code with a limit, but my tests without.
> I just double-checked and yes, as-implemented, with `ColumnLimit: 0` and `JavaScriptWrapImports: true`, import statements retain the number of lines they started with.
>
> It is explicit in the code that with `ColumnLimit: 0`, we decide whether to break on a token based on whether there was a preexisting line break. (Check out `NoColumnLimitLineFormatter`.) I think you're right that usually clang-format reflows everything and I was also confused about this point.
>
> There are other options that do similar things, for example `EmptyLineAfterAccessModifier`.
Can you check with code that would normally cause reformatting? E.g.
```
import {
A, B,
C,
} from 'url';
```
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116638/new/
https://reviews.llvm.org/D116638
More information about the cfe-commits
mailing list