Skip to content

Commit

Permalink
cue/format: keep blank between ast.EmbedDecl and comment
Browse files Browse the repository at this point in the history
Formater would disallow blank after `ast.EmbedDecl` which removed
the blank between `ast.EmbedDecl` and comment.

This removes `noblank` to keep the space.

Fixes #3291

Change-Id: Ib9be903b04a222cc311aebce1bdaf66cacc059b7
Signed-off-by: haoqixu <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199054
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
haoqixu authored and mvdan committed Aug 8, 2024
1 parent 596a8c3 commit a6f1b76
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cue/format/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (f *formatter) decl(decl ast.Decl) {
f.print(formfeed)
}
f.expr(n.Expr)
f.print(newline, noblank)
f.print(newline)

case *ast.Attribute:
f.print(n.At, n)
Expand Down
20 changes: 20 additions & 0 deletions cue/format/testdata/issue3291.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- file.input --
A: true
B: [
1, // this comment is fine
2, // this comment is fine
if A {
3 // this comment ends up touching its element
},
4, // this comment is fine
]
-- file.golden --
A: true
B: [
1, // this comment is fine
2, // this comment is fine
if A {
3 // this comment ends up touching its element
},
4, // this comment is fine
]
10 changes: 5 additions & 5 deletions encoding/protobuf/testdata/gateway.proto.out.cue
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,19 @@ package v1alpha3

// TLS protocol versions.
#TLSProtocol: {
"TLS_AUTO"// Automatically choose the optimal TLS version.
"TLS_AUTO" // Automatically choose the optimal TLS version.
#enumValue: 0
} | {
"TLSV1_0"// TLS version 1.0
"TLSV1_0" // TLS version 1.0
#enumValue: 1
} | {
"TLSV1_1"// TLS version 1.1
"TLSV1_1" // TLS version 1.1
#enumValue: 2
} | {
"TLSV1_2"// TLS version 1.2
"TLSV1_2" // TLS version 1.2
#enumValue: 3
} | {
"TLSV1_3"// TLS version 1.3
"TLSV1_3" // TLS version 1.3
#enumValue: 4
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ package descriptor
"TYPE_GROUP"
#enumValue: 10
} | {
"TYPE_MESSAGE"// Length-delimited aggregate.
"TYPE_MESSAGE" // Length-delimited aggregate.
#enumValue: 11
} | {
// New in version 2.
Expand All @@ -185,10 +185,10 @@ package descriptor
{"TYPE_ENUM", #enumValue: 14} |
{"TYPE_SFIXED32", #enumValue: 15} |
{"TYPE_SFIXED64", #enumValue: 16} | {
"TYPE_SINT32"// Uses ZigZag encoding.
"TYPE_SINT32" // Uses ZigZag encoding.
#enumValue: 17
} | {
"TYPE_SINT64"// Uses ZigZag encoding.
"TYPE_SINT64" // Uses ZigZag encoding.
#enumValue: 18
}

Expand Down Expand Up @@ -362,14 +362,14 @@ package descriptor

// Generated classes can be optimized for speed or code size.
#OptimizeMode: {
"SPEED"// Generate complete code for parsing, serialization,
"SPEED" // Generate complete code for parsing, serialization,
#enumValue: 1
} | {
// etc.
"CODE_SIZE"// Use ReflectionOps to implement these methods.
"CODE_SIZE" // Use ReflectionOps to implement these methods.
#enumValue: 2
} | {
"LITE_RUNTIME"// Generate code using MessageLite and the lite runtime.
"LITE_RUNTIME" // Generate code using MessageLite and the lite runtime.
#enumValue: 3
}

Expand Down Expand Up @@ -674,10 +674,10 @@ package descriptor
// or neither? HTTP based RPC implementation may choose GET verb for safe
// methods, and PUT verb for idempotent methods instead of the default POST.
#IdempotencyLevel: {"IDEMPOTENCY_UNKNOWN", #enumValue: 0} | {
"NO_SIDE_EFFECTS"// implies idempotent
"NO_SIDE_EFFECTS" // implies idempotent
#enumValue: 1
} | {
"IDEMPOTENT"// idempotent, but may have side effects
"IDEMPOTENT" // idempotent, but may have side effects
#enumValue: 2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ import (
#ReferencedAttributes: {
// How an attribute's value was matched
#Condition: {
"CONDITION_UNSPECIFIED"// should not occur
"CONDITION_UNSPECIFIED" // should not occur
#enumValue: 0
} | {
"ABSENCE"// match when attribute doesn't exist
"ABSENCE" // match when attribute doesn't exist
#enumValue: 1
} | {
"EXACT"// match when attribute value is an exact byte-for-byte match
"EXACT" // match when attribute value is an exact byte-for-byte match
#enumValue: 2
} | {
"REGEX"// match when attribute value matches the included regex
"REGEX" // match when attribute value matches the included regex
#enumValue: 3
}

Expand Down Expand Up @@ -165,13 +165,13 @@ import (
#HeaderOperation: {
// Operation type.
#Operation: {
"REPLACE"// replaces the header with the given name
"REPLACE" // replaces the header with the given name
#enumValue: 0
} | {
"REMOVE"// removes the header with the given name (the value is ignored)
"REMOVE" // removes the header with the given name (the value is ignored)
#enumValue: 1
} | {
"APPEND"// appends the value to the header value, or sets it if not present
"APPEND" // appends the value to the header value, or sets it if not present
#enumValue: 2
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,19 +404,19 @@ package v1alpha3

// TLS protocol versions.
#TLSProtocol: {
"TLS_AUTO"// Automatically choose the optimal TLS version.
"TLS_AUTO" // Automatically choose the optimal TLS version.
#enumValue: 0
} | {
"TLSV1_0"// TLS version 1.0
"TLSV1_0" // TLS version 1.0
#enumValue: 1
} | {
"TLSV1_1"// TLS version 1.1
"TLSV1_1" // TLS version 1.1
#enumValue: 2
} | {
"TLSV1_2"// TLS version 1.2
"TLSV1_2" // TLS version 1.2
#enumValue: 3
} | {
"TLSV1_3"// TLS version 1.3
"TLSV1_3" // TLS version 1.3
#enumValue: 4
}

Expand Down

0 comments on commit a6f1b76

Please sign in to comment.