-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PolicyOps: use newlines.ignoreInSyntax
#3613
Conversation
docs/configuration.md
Outdated
@@ -2531,6 +2531,36 @@ newlines.inInterpolation | |||
- `avoid`: attemps to avoid breaks within the spliced code, regardless of line overflow | |||
- `oneline`: formats the splice on a single line, or breaks after `${` if overflows | |||
|
|||
### `newlines.ignoreInSyntax` | |||
|
|||
This boolean parameter controls whether to ignore newlines in strings (or other |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this only be used for strings? It's a bit unclear what other possibly multi-line tokens
could entail. Overall, would that be a setting for that one user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- the code doesn't really specify which tokens could have embedded newlines; other possible options are comment and xml.
- as to the target audience: i would definitely use it in our codebase, not a big fan of ignored embedded newlines myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tgodzik any additional thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am missing the exact meaning here. whether to ignore newlines in strings
yet the newlines are outside the strings, so this only affects strings if they are inside some other srtucture?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... let me add a longer explanation :)
Specifically, for PenalizeAllNewlines and SingleLineBlock policies.
The formatter frequently chooses between adding a newline and continuing the | ||
same line but either prohibiting or heavily discouraging subsequent newlines | ||
_between_ tokens, to fit the rest of the expression on the same line. | ||
|
||
However, in many cases and, for historical reasons, intentionally, newlines | ||
_within_ tokens have been frequently ignored, leading to "single-line" blocks | ||
which actually span multiple lines. | ||
|
||
This boolean parameter now allows controlling whether to ignore newlines found | ||
in syntax of strings or other possibly multi-line tokens when newlines are | ||
otherwise prohibited or undesirable (such as for single-line formatting). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tgodzik do you think this explanation makes it a bit clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leading to "single-line" blocks which actually span multiple lines.
is a bit unclear to me, though I guess the example here would need to be the best explanation we can get
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for expanding the explanation!
The formatter frequently chooses between adding a newline and continuing the | ||
same line but either prohibiting or heavily discouraging subsequent newlines | ||
_between_ tokens, to fit the rest of the expression on the same line. | ||
|
||
However, in many cases and, for historical reasons, intentionally, newlines | ||
_within_ tokens have been frequently ignored, leading to "single-line" blocks | ||
which actually span multiple lines. | ||
|
||
This boolean parameter now allows controlling whether to ignore newlines found | ||
in syntax of strings or other possibly multi-line tokens when newlines are | ||
otherwise prohibited or undesirable (such as for single-line formatting). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leading to "single-line" blocks which actually span multiple lines.
is a bit unclear to me, though I guess the example here would need to be the best explanation we can get
newlines.ignoreInSyntax = true | ||
--- | ||
// ignores newline in string, pretends everything fits on one line | ||
println(s"""${1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is an example. contains newline but will be formatted without breaks around open and close parentheses.
Specifically, for PenalizeAllNewlines and SingleLineBlock policies. Fixes #3608.