Skip to content

Commit 52151eb

Browse files
committed
Alphabetize quality column
1 parent 49e6e98 commit 52151eb

8 files changed

Lines changed: 81 additions & 4 deletions

File tree

disco/attributes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func (b *Baller) organizeAttributesSection(cxt *discoContext) (err error) {
4040
return err
4141
}
4242

43+
err = b.fixQualityCells(cxt, attributes)
44+
if err != nil {
45+
return err
46+
}
47+
4348
err = b.fixConstraintCells(cxt, attributes.section, attributesTable)
4449
if err != nil {
4550
return err

disco/commands.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ func (b *Baller) organizeCommandsSection(cxt *discoContext) (err error) {
3535
return fmt.Errorf("error fixing access cells in commands table in %s: %w", cxt.doc.Path, err)
3636
}
3737

38+
err = b.fixQualityCells(cxt, commands)
39+
if err != nil {
40+
return err
41+
}
42+
3843
err = b.fixConformanceCells(cxt, commands, commands.table.Rows, commands.table.ColumnMap)
3944
if err != nil {
4045
return fmt.Errorf("error fixing conformance cells in commands table in %s: %w", cxt.doc.Path, err)

disco/event.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func (b *Baller) organizeEventsSection(cxt *discoContext) (err error) {
3434
return fmt.Errorf("error fixing access cells in section %s in %s: %w", cxt.doc.SectionName(events.section), cxt.doc.Path, err)
3535
}
3636

37+
err = b.fixQualityCells(cxt, events)
38+
if err != nil {
39+
return err
40+
}
41+
3742
err = b.fixConformanceCells(cxt, events, eventsTable.Rows, eventsTable.ColumnMap)
3843
if err != nil {
3944
return fmt.Errorf("error fixing conformance cells for event table in section %s in %s: %w", cxt.doc.SectionName(events.section), cxt.doc.Path, err)

disco/option.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type DiscoOptions struct {
88
ReorderColumns bool `default:"true" aliases:"reorderColumns" help:"rearrange table columns into disco-ball order" group:"Discoballing:"`
99
RenameTableHeaders bool `default:"true" aliases:"renameTableHeaders" help:"rename table headers to disco-ball standard names" group:"Discoballing:"`
1010
FormatAccess bool `default:"true" aliases:"formatAccess" help:"reformat access columns in disco-ball order" group:"Discoballing:"`
11+
FormatQuality bool `default:"true" help:"reformat quality columns in disco-ball order" group:"Discoballing:"`
1112
PromoteDataTypes bool `default:"true" aliases:"promoteDataTypes" help:"promote inline data types to Data Types section" group:"Discoballing:"`
1213
ReorderSections bool `default:"true" aliases:"reorderSections" help:"reorder sections in disco-ball order" group:"Discoballing:"`
1314
NormalizeTableOptions bool `default:"true" aliases:"normalizeTableOptions" help:"remove existing table options and replace with standard disco-ball options" group:"Discoballing:"`
@@ -29,6 +30,7 @@ var DefaultOptions = DiscoOptions{
2930
ReorderColumns: true,
3031
RenameTableHeaders: true,
3132
FormatAccess: true,
33+
FormatQuality: true,
3234
PromoteDataTypes: true,
3335
ReorderSections: true,
3436
NormalizeTableOptions: true,

disco/quality.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package disco
2+
3+
import (
4+
"strings"
5+
6+
"github.com/project-chip/alchemy/errata"
7+
"github.com/project-chip/alchemy/matter"
8+
"github.com/project-chip/alchemy/matter/spec"
9+
)
10+
11+
func (b *Baller) fixQualityCells(cxt *discoContext, subSection *subSection) (err error) {
12+
if !b.options.FormatQuality {
13+
return nil
14+
}
15+
if cxt.errata.IgnoreSection(cxt.doc.SectionName(subSection.section), errata.DiscoPurposeTableQuality) {
16+
return nil
17+
}
18+
table := subSection.table
19+
if len(table.Rows) < 2 {
20+
return
21+
}
22+
qualityIndex, ok := table.ColumnMap[matter.TableColumnQuality]
23+
if !ok {
24+
return
25+
}
26+
27+
for _, row := range table.Rows[1:] {
28+
qualityCell := row.Cell(qualityIndex)
29+
vc, e := spec.RenderTableCell(qualityCell)
30+
if e != nil {
31+
continue
32+
}
33+
vc = strings.TrimSpace(vc)
34+
if len(vc) == 0 {
35+
continue
36+
}
37+
quality := matter.ParseQuality(vc)
38+
replacementQuality := quality.String()
39+
if vc != replacementQuality {
40+
setCellString(qualityCell, replacementQuality)
41+
}
42+
}
43+
return
44+
}

disco/struct.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ func (b *Baller) organizeStructSection(cxt *discoContext, ss *subSection) (err e
4848
return fmt.Errorf("error fixing access cells in struct table in %s: %w", cxt.doc.Path, err)
4949
}
5050

51+
err = b.fixQualityCells(cxt, ss)
52+
if err != nil {
53+
return err
54+
}
55+
5156
err = b.fixConstraintCells(cxt, ss.section, fieldsTable)
5257
if err != nil {
5358
return err

errata/disco.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ const (
4545
DiscoPurposeDataTypeCommandFixDirection = 1 << (iota - 1)
4646
DiscoPurposeDataTypePromoteInline = 1 << (iota - 1)
4747
DiscoPurposeNormalizeAnchor = 1 << (iota - 1)
48+
DiscoPurposeTableQuality = 1 << (iota - 1)
4849

49-
DiscoPurposeAll DiscoPurpose = DiscoPurposeTableAccess | DiscoPurposeTableConformance | DiscoPurposeTableConstraint | DiscoPurposeTableLinkIndexes | DiscoPurposeTableRenameHeaders | DiscoPurposeTableAddMissingColumns | DiscoPurposeTableReorderColumns | DiscoPurposeDataTypeAppendSuffix | DiscoPurposeDataTypeRename
50+
DiscoPurposeAll DiscoPurpose = DiscoPurposeTableAccess | DiscoPurposeTableConformance | DiscoPurposeTableConstraint | DiscoPurposeTableLinkIndexes | DiscoPurposeTableQuality | DiscoPurposeTableRenameHeaders | DiscoPurposeTableAddMissingColumns | DiscoPurposeTableReorderColumns | DiscoPurposeDataTypeAppendSuffix | DiscoPurposeDataTypeRename
5051
)
5152

5253
var discoPurposes = map[string]DiscoPurpose{
5354
"table-access": DiscoPurposeTableAccess,
5455
"table-conformance": DiscoPurposeTableConformance,
5556
"table-constraint": DiscoPurposeTableConstraint,
57+
"table-quality": DiscoPurposeTableQuality,
5658
"table-link-indexes": DiscoPurposeTableLinkIndexes,
5759
"table-rename-headers": DiscoPurposeTableRenameHeaders,
5860
"table-add-missing-columns": DiscoPurposeTableRenameHeaders,

matter/quality.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package matter
22

33
import (
4+
"slices"
45
"strings"
56

67
"github.com/project-chip/alchemy/matter/types"
@@ -79,13 +80,21 @@ func (q Quality) Any(o Quality) bool {
7980
}
8081

8182
func (q Quality) String() string {
82-
var s strings.Builder
83+
var qualities []rune
8384
for tq, i := range qualityIdentifiers {
8485
if (q & tq) == tq {
85-
s.WriteRune(i)
86+
qualities = append(qualities, i)
8687
}
8788
}
88-
return s.String()
89+
slices.Sort(qualities)
90+
var sb strings.Builder
91+
for _, r := range qualities {
92+
if sb.Len() > 0 {
93+
sb.WriteRune(' ')
94+
}
95+
sb.WriteRune(r)
96+
}
97+
return sb.String()
8998
}
9099

91100
func (q *Quality) Inherit(oq Quality) {

0 commit comments

Comments
 (0)