File tree Expand file tree Collapse file tree 3 files changed +16
-8
lines changed
Expand file tree Collapse file tree 3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -94,13 +94,13 @@ implicit/auto-assigning syntax).
9494
9595### ` field.id.negative `
9696
97- This check reports an error if a field's ID is negative.
97+ This check reports an error if a field's ID is explicitly negative.
9898
9999### ` field.id.zero `
100100
101- This check reports an error if a field's ID is zero, which is generally
102- unsupported by the Apache Thrift compiler. This is distinct from the
103- ` field.id.negative ` check given the existence of the ` --allow-neg-keys `
101+ This check reports an error if a field's ID is explicitly zero, which is
102+ generally unsupported by the Apache Thrift compiler. This is distinct from
103+ the ` field.id.negative ` check given the existence of the ` --allow-neg-keys `
104104Apache Thrift compiler option.
105105
106106### ` field.optional `
Original file line number Diff line number Diff line change @@ -28,19 +28,19 @@ func CheckFieldIDMissing() *thriftcheck.Check {
2828 })
2929}
3030
31- // CheckFieldIDNegative reports an error if a field's ID is negative.
31+ // CheckFieldIDNegative reports an error if a field's ID is explicitly negative.
3232func CheckFieldIDNegative () * thriftcheck.Check {
3333 return thriftcheck .NewCheck ("field.id.negative" , func (c * thriftcheck.C , f * ast.Field ) {
34- if f .ID < 0 {
34+ if ! f . IDUnset && f .ID < 0 {
3535 c .Errorf (f , "field ID for %q (%d) is negative" , f .Name , f .ID )
3636 }
3737 })
3838}
3939
40- // CheckFieldIDZero reports an error if a field's ID is zero.
40+ // CheckFieldIDZero reports an error if a field's ID is explicitly zero.
4141func CheckFieldIDZero () * thriftcheck.Check {
4242 return thriftcheck .NewCheck ("field.id.zero" , func (c * thriftcheck.C , f * ast.Field ) {
43- if f .ID == 0 {
43+ if ! f . IDUnset && f .ID == 0 {
4444 c .Errorf (f , "field ID for %q is zero" , f .Name )
4545 }
4646 })
Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ func TestCheckFieldIDNegative(t *testing.T) {
5555 `t.thrift:0:1: error: field ID for "Field" (-1) is negative (field.id.negative)` ,
5656 },
5757 },
58+ {
59+ node : & ast.Field {IDUnset : true },
60+ want : []string {},
61+ },
5862 }
5963
6064 check := checks .CheckFieldIDNegative ()
@@ -77,6 +81,10 @@ func TestCheckFieldIDZero(t *testing.T) {
7781 node : & ast.Field {ID : - 1 , Name : "Field" },
7882 want : []string {},
7983 },
84+ {
85+ node : & ast.Field {IDUnset : true },
86+ want : []string {},
87+ },
8088 }
8189
8290 check := checks .CheckFieldIDZero ()
You can’t perform that action at this time.
0 commit comments