Skip to content

Commit 88fb116

Browse files
authored
ci: improve linter & avoid crash with garbage input (#761)
Signed-off-by: spacewander <[email protected]>
1 parent 8f54616 commit 88fb116

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

tools/cmd/linter/main.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,11 @@ func getFeatureMaturityLevel(category string) ([]maturityLevel, error) {
556556
// the third row is the status
557557
scanner.Scan()
558558
ss := strings.Split(scanner.Text(), "|")
559-
if len(ss) > 2 {
560-
status = strings.ToLower(strings.TrimSpace(ss[2]))
559+
if len(ss) < 3 {
560+
return fmt.Errorf("status is missing in the `## Attribute` table of %s", path)
561561
}
562+
563+
status = strings.ToLower(strings.TrimSpace(ss[2]))
562564
break
563565
}
564566
}
@@ -614,22 +616,32 @@ func lintFeatureMaturityLevel() error {
614616

615617
for category, recs := range records {
616618
for _, record := range recs {
617-
if record.Status == "experimental" && record.ExperimentalSince == "" {
618-
return fmt.Errorf("experimental_since of %s %s is missing in %s", category, record.Name, recordFile)
619+
if record.Status == "experimental" {
620+
if record.ExperimentalSince == "" {
621+
return fmt.Errorf("experimental_since of %s %s is missing in %s", category, record.Name, recordFile)
622+
}
623+
} else if record.Status == "stable" {
624+
if record.StableSince == "" {
625+
return fmt.Errorf("stable_since of %s %s is missing in %s", category, record.Name, recordFile)
626+
}
627+
} else {
628+
return fmt.Errorf("status '%s' of %s %s is invalid in %s", record.Status, category, record.Name, recordFile)
619629
}
630+
620631
found := false
621632
for i, r := range actualRecords[category] {
622633
if r.Name == record.Name {
623634
found = true
624635
if r.Status != record.Status {
625-
return fmt.Errorf("status of %s %s is mismatched between %s and the documentation", category, record.Name, recordFile)
636+
return fmt.Errorf("status of %s %s is mismatched between %s and the documentation. Please update the record in %s.",
637+
category, record.Name, recordFile, recordFile)
626638
}
627639
actualRecords[category] = slices.Delete(actualRecords[category], i, i+1)
628640
break
629641
}
630642
}
631643
if !found {
632-
return fmt.Errorf("%s %s is missing in the documentation", category, record.Name)
644+
return fmt.Errorf("feature maturity record of %s %s is missing in the documentation", category, record.Name)
633645
}
634646
}
635647
}

types/plugins/plugins_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func snakeToCamel(s string) string {
4040
}
4141

4242
func getSecondColumn(line string) string {
43-
return strings.TrimSpace(strings.Split(line, "|")[2])
43+
cols := strings.Split(line, "|")
44+
if len(cols) < 3 {
45+
return ""
46+
}
47+
return strings.TrimSpace(cols[2])
4448
}
4549

4650
func TestCheckPluginAttributes(t *testing.T) {

0 commit comments

Comments
 (0)