File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed
Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,13 @@ implicit/auto-assigning syntax).
9696
9797This check reports an error if a field's ID is negative.
9898
99+ ### ` field.id.zero `
100+
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 `
104+ Apache Thrift compiler option.
105+
99106### ` field.optional `
100107
101108This check warns if a field isn't declared as "optional", which is considered
Original file line number Diff line number Diff line change @@ -37,6 +37,15 @@ func CheckFieldIDNegative() *thriftcheck.Check {
3737 })
3838}
3939
40+ // CheckFieldIDZero reports an error if a field's ID is zero.
41+ func CheckFieldIDZero () * thriftcheck.Check {
42+ return thriftcheck .NewCheck ("field.id.zero" , func (c * thriftcheck.C , f * ast.Field ) {
43+ if f .ID == 0 {
44+ c .Errorf (f , "field ID for %q is zero" , f .Name )
45+ }
46+ })
47+ }
48+
4049// CheckFieldOptional warns if a field isn't declared as "optional".
4150func CheckFieldOptional () * thriftcheck.Check {
4251 return thriftcheck .NewCheck ("field.optional" , func (c * thriftcheck.C , f * ast.Field ) {
Original file line number Diff line number Diff line change @@ -61,6 +61,28 @@ func TestCheckFieldIDNegative(t *testing.T) {
6161 RunTests (t , check , tests )
6262}
6363
64+ func TestCheckFieldIDZero (t * testing.T ) {
65+ tests := []Test {
66+ {
67+ node : & ast.Field {ID : 1 , Name : "Field" },
68+ want : []string {},
69+ },
70+ {
71+ node : & ast.Field {ID : 0 , Name : "Field" },
72+ want : []string {
73+ `t.thrift:0:1: error: field ID for "Field" is zero (field.id.zero)` ,
74+ },
75+ },
76+ {
77+ node : & ast.Field {ID : - 1 , Name : "Field" },
78+ want : []string {},
79+ },
80+ }
81+
82+ check := checks .CheckFieldIDZero ()
83+ RunTests (t , check , tests )
84+ }
85+
6486func TestCheckFieldOptional (t * testing.T ) {
6587 tests := []Test {
6688 {
Original file line number Diff line number Diff line change @@ -155,6 +155,7 @@ func main() {
155155 checks .CheckEnumSize (cfg .Checks .Enum .Size .Warning , cfg .Checks .Enum .Size .Error ),
156156 checks .CheckFieldIDMissing (),
157157 checks .CheckFieldIDNegative (),
158+ checks .CheckFieldIDZero (),
158159 checks .CheckFieldOptional (),
159160 checks .CheckFieldRequiredness (),
160161 checks .CheckIncludePath (),
You can’t perform that action at this time.
0 commit comments