Comments (7)
@Stephan202 - not completely, I saw that issue as well, but these are just bare static final string
constants.
For example:
public static final String JSON_1 =
"""
[
"FUNCTION1",
"FUNCTION2",
"// ... 98 other records ..."
"FUNCTION101"
]""";
public static final String JSON_2 =
"""
{
"errorID": "error id",
"errorMessage": "message",
"resourceType": "metadata",
"requestID": "request"
}""";
I'd say it was something about the JSON curly brackets, but it's not consistent. I'm trying to find a truly minimal reproduction.
from google-java-format.
My preferred formatting for text blocks would be something like:
public static final String STRING = """
... Embedded code and scripts possibly with long lines...
"""; // the position of this element defines the rest of the block's indentation
from google-java-format.
Ok, looked at it a bit more.
I suspect the behaviour you're seeing is that there's some logic to start the text block contents at the left margin if indenting the lines would cause the column limit to be exceeded...
This is the issue, generally. The text blocks in question all have lines exceeding 100 characters when the file is consistently indented. There's one block that seems to be an outlier, but this behavior explains the move of every other block. The gutter in the editor is configured at 120 characters, so that threw me for a bit.
IMHO, the left justification of long lines is unexpected, and I would not do it for text blocks. It makes the left margin of files look very strange if they have text blocks with long lines, and there's lots of situations where long lines are somewhat required, like embedded scripts. In the case of these files, about a third of the blocks are left justified, and the rest are justified with the code. Something to discuss, for sure.
from google-java-format.
Hey @bmeier-pros! Does your issue match what's described in #1081?
from google-java-format.
I suspect the behaviour you're seeing is that there's some logic to start the text block contents at the left margin if indenting the lines would cause the column limit to be exceeded, and to preserve the existing formatting choice if a text block is aligned with the left margin.
In that example, adding a least one space of indent to the second text block will cause the formatter to indent it the same way as the first text block.
The formatting of text blocks hasn't been finalized yet, we might revisit some of those details, in particular whether or not aligning with the left margin is a choice that should be preserved.
Example:
$ google-java-format T.java
class T {
String S =
"""
hello
world
""";
}
$ google-java-format T.java
class T {
String S =
"""
hello
world
""";
}
from google-java-format.
Hi @cushon,
That makes some sense, however the original formatting of the two text blocks before applying google-java-format was consistent at 8 spaces indentation for both blocks. This also happened in several other places throughout the file where some blocks were indented and others were justified. It's also consistent - if I modify the indentation of the second block, it gets revised back to left justified. I will try again to make a minimal case :-) I've had a busy couple of days.
from google-java-format.
The formatting of text blocks hasn't been finalized yet, we might revisit some of those details, in particular whether or not aligning with the left margin is a choice that should be preserved.
I'm also not a huge fan of pushing the text blocks all the way to the left margin. I would prefer if the line length limit was violated. GJF can't promise that its output will never violate the line length limit anyway (all it takes is an identifier of length 101).
Another option would be to wrap the inner contexts of the text block, like
foo(
"""
aaaaaaaaaaaaaaaaaaaaaaa\
a
"""
)
from google-java-format.
Related Issues (20)
- Unnamed pattern cannot be parsed
- The unused method cannot be detected HOT 2
- Import Ordering configuration suppressed on README HOT 2
- help HOT 4
- Version 1.20.0 hasn't been published to MavenCentral HOT 1
- 1.20.0 binaries reports incorrect version (HEAD-SNAPSHOT) when called with the -v flag HOT 2
- Request google-java-format IntelliJ plugin version 1.18 HOT 1
- Before commit reformatting option in IntelliJ does invoke plugin
- google-java-format_linux-x86-64: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./google-java-format_linux-x86-64) HOT 6
- The google-java-formatter eclipse plugin doesn't change the format of my code HOT 2
- IllegalAccessError from com.sun.tools.javac.util
- Omit the redundant method isReal() to make it simpler
- Excess indentation with method-receiving text blocks HOT 2
- compatibility with Gradle 9.x
- Inconsistent blank line between license and package statement HOT 1
- bug report: 1.21.0 IntelliJ vs jar inconsistency HOT 3
- Misleading message for --dry-run with --replace
- MAX_LINE_LENGTH parameterized HOT 1
- Error processing case statements using JVM "17-ea (Azul Systems, Inc. 17-ea+12)" HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-java-format.