Skip to content

Commit 9b51142

Browse files
committed
Fix findings
1 parent 104b06e commit 9b51142

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

cmd/action/zapdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type ZAPDiff struct {
3232

3333
func (z *ZAPDiff) Run(cc *cli.Context) (err error) {
3434
slog.Info("Running ZAP generation", "attributes", z.GenAttributes)
35-
zapCmd := &cli.ZAP{}
35+
zapCmd := &cli.ZAPXML{}
3636
zapCmd.Root = z.SpecRoot
3737
zapCmd.SdkRoot = z.GeneratedSDKRoot
3838
zapCmd.Attribute = []string{z.GenAttributes}

zap/regen/case.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"unicode"
77

88
"github.com/mailgun/raymond/v2"
9-
"github.com/project-chip/alchemy/internal/text"
109
)
1110

1211
func asUpperCamelCaseHelper(value string) raymond.SafeString {
@@ -18,7 +17,7 @@ func asUpperCamelCaseIgnoreAcronymsHelper(value string) raymond.SafeString {
1817
}
1918

2019
func asLowerCamelCaseHelper(value string) raymond.SafeString {
21-
if len(value) > 1 && text.IsUpperCase(value) {
20+
if len(value) > 1 && isUpperCase(value) {
2221
return raymond.SafeString(strings.ToLower(value))
2322
}
2423
return raymond.SafeString(caseify(value, true, true))

zap/regen/helper.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ func maxValue(field matter.Field, fs matter.FieldSet) (max types.DataTypeExtreme
142142
return
143143
}
144144

145-
var maxDueToNullable bool
146-
if hasNumericMax {
147-
maxDueToNullable = types.Max(sdk.ToUnderlyingType(sdk.FindBaseType(field.Type)), types.NullabilityNullable).ValueEquals(max)
148-
}
145+
maxDueToNullable := types.Max(sdk.ToUnderlyingType(sdk.FindBaseType(field.Type)), types.NullabilityNullable).ValueEquals(max)
149146
if maxDueToNullable {
150147
return
151148
}
@@ -208,7 +205,7 @@ func accessStringHelper(a matter.Access) raymond.SafeString {
208205
list.WriteString("read: ")
209206
list.WriteString(strings.ToLower(a.Read.String()))
210207
}
211-
if a.Write != matter.PrivilegeUnknown && a.Write != matter.PrivilegeView {
208+
if a.Write != matter.PrivilegeUnknown && a.Write != matter.PrivilegeOperate {
212209
if list.Len() > 0 {
213210
list.WriteString(", ")
214211
}
@@ -253,7 +250,7 @@ func descriptionCommentHelper(description string) raymond.SafeString {
253250
var comment strings.Builder
254251
var line strings.Builder
255252
line.WriteString("/**")
256-
words := strings.Split(description, " ")
253+
words := strings.Fields(description)
257254
for _, word := range words {
258255
if line.Len() > 100 {
259256
comment.WriteString(line.String())

zap/regen/render.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (p IdlRenderer) Process(cxt context.Context, input *pipeline.Data[*zap.File
8888
clusters := make(map[*matter.Cluster]*ClusterInfo)
8989

9090
for _, endpoint := range input.Content.Endpoints {
91-
if endpoint.EndpointTypeIndex > len(input.Content.EndpointTypes)-1 {
91+
if endpoint.EndpointTypeIndex < 0 || endpoint.EndpointTypeIndex >= len(input.Content.EndpointTypes) {
9292
continue
9393
}
9494
endpointType := input.Content.EndpointTypes[endpoint.EndpointTypeIndex]
@@ -120,6 +120,9 @@ func (p IdlRenderer) Process(cxt context.Context, input *pipeline.Data[*zap.File
120120
clusterList := make([]*ClusterInfo, 0, len(clusters))
121121
clusterEntities := make(map[*matter.Cluster]map[types.Entity]struct{})
122122
globalEntities := make(map[types.Entity]bool)
123+
for entity := range p.spec.GlobalObjects {
124+
globalEntities[entity] = false
125+
}
123126
for cluster, ci := range clusters {
124127
clusterList = append(clusterList, ci)
125128
clusterEntities[cluster] = make(map[types.Entity]struct{})
@@ -196,7 +199,7 @@ func (p IdlRenderer) Process(cxt context.Context, input *pipeline.Data[*zap.File
196199
en.Name = fieldName + "Tag"
197200
en.Type = types.NewDataType(types.BaseDataTypeEnum8, types.DataTypeRankScalar)
198201
for _, tag := range ns.SemanticTags {
199-
nst := matter.NewEnumValue(tag.Source(), ns)
202+
nst := matter.NewEnumValue(tag.Source(), en)
200203
nst.Name = tag.Name
201204
nst.Value = tag.ID
202205
en.Values = append(en.Values, nst)

zap/regen/targeter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func getZapPaths(sdkRoot string) (zapPaths []string, err error) {
1616
zapPaths = append(zapPaths, filepath.Join(sdkRoot, "src/controller/data_model/controller-clusters.zap"))
1717
srcRoot := filepath.Join(sdkRoot, "/examples/")
1818
err = filepath.WalkDir(srcRoot, func(path string, d fs.DirEntry, err error) error {
19+
if err != nil {
20+
return err
21+
}
1922
if filepath.Ext(path) == ".zap" {
2023
zapPaths = append(zapPaths, path)
2124
}

0 commit comments

Comments
 (0)