Skip to content

Conversation

dsnet
Copy link
Collaborator

@dsnet dsnet commented Apr 12, 2024

Changes made:

  • Further separate the behavior of SpaceAfterColon and SpaceAfterComma from Multiline. That is, use of Multiline does not affect the behavior of SpaceAfterColon or SpaceAfterComma unless it has not been set. For example, specifying (SpaceAfterColon(false), Multiline(true)) should avoid the space after the colon even if we expect this combination of options to be seldom used.

  • Exclude whitespace formatting flags from DefaultOptionsV1 since v1 has API support for both single-line and multi-line output, so setting (or clearing) them cannot be classified as v1 behavior. Similarly, exclude whitespace formatting flags from DefaultOptionsV2.

  • Simplify the TestMarshal cases.

  • Add explicit TestEncoder cases to exercise all Encoder.WriteValue code paths.

Changes made:

* Further separate the behavior of SpaceAfterColon and SpaceAfterComma
  from Multiline. That is, use of Multiline does not affect the behavior
  of SpaceAfterColon or SpaceAfterComma unless it has not been set.
  For example, specifying (SpaceAfterColon(false), Multiline(true))
  should avoid the space after the colon even if we expect this
  combination of options to be seldom used.

* Exclude whitespace formatting flags from DefaultOptionsV1
  since v1 has API support for both single-line and multi-line output,
  so setting (or clearing) them cannot be classified as v1 behavior.
  Similarly, exclude whitespace formatting flags from DefaultOptionsV2.

* Simplify the TestMarshal cases.

* Add explicit TestEncoder cases to exercise all
  Encoder.WriteValue code paths.
@dsnet dsnet requested review from johanbrandhorst and mvdan April 12, 2024 01:01
@dsnet
Copy link
Collaborator Author

dsnet commented Apr 12, 2024

\cc @veqryn

@mvdan
Copy link
Collaborator

mvdan commented Apr 12, 2024

Thanks, done.

@mvdan mvdan merged commit 37be135 into master Apr 12, 2024
@mvdan
Copy link
Collaborator

mvdan commented Apr 12, 2024

Err, I meant to merge #25, but this one also LGTM, so hopefully that's not a problem 😅

@dsnet
Copy link
Collaborator Author

dsnet commented Apr 12, 2024

No worries, it was done.

@dsnet dsnet deleted the single-line-flags branch April 12, 2024 20:21
gopherbot pushed a commit to golang/go that referenced this pull request Oct 14, 2025
Originally, DefaultOptionsV1 and DefaultOptionsV2 represented
the full set of all options with specific ones set to true or false.

However, there are certain options such as WithIndent or WithMarshalers
that are neither v1 or v2 specific.
At some point we removed whitespace related options from the set:
go-json-experiment/json#26

This avoids DefaultOptionsV1 or DefaultOptionsV2 from affecting
any previously set whitespace. However, why are whitespace options
special and thus excluded from the set? What about Marshalers?

As a more principaled way to address this, we restrict
DefaultOptionsV1 and DefaultOptionsV2 to only be the options
where the default setting changes between v1 and v2.
All other options are unpopulated.

This avoids a panic with GetOption(DefaultOptionsV2, WithMarshalers)
since DefaultOptionsV2 previously had the presence bit for
Marshalers set to true, but had no actual value.
Now, the presence bit is set to false, so the value is not consulted.

Fixes #75149

Change-Id: I30b45abd35404578b4135cc3bad1a1a2993cb0cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/710878
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants