bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmdpolicy
|
|
|
|
import (
|
|
"github.com/larksuite/cli/extension/platform"
|
|
"github.com/larksuite/cli/internal/suggest"
|
|
)
|
|
|
|
// suggestRisk returns the closest valid Risk literal by edit distance
|
|
// for risk_invalid diagnostics; input is never silently substituted.
|
|
// Case-insensitive ("WRITE" → "write"); empty in, empty out (the
|
|
// absent-annotation case goes to risk_not_annotated, not here).
|
|
func suggestRisk(bad string) string {
|
|
if bad == "" {
|
|
return ""
|
|
}
|
|
lowered := toLower(bad)
|
|
candidates := []platform.Risk{
|
|
platform.RiskRead, platform.RiskWrite, platform.RiskHighRiskWrite,
|
|
}
|
|
best := string(candidates[0])
|
|
bestDist := suggest.Levenshtein(lowered, best)
|
|
for _, c := range candidates[1:] {
|
|
if d := suggest.Levenshtein(lowered, string(c)); d < bestDist {
|
|
bestDist, best = d, string(c)
|
|
}
|
|
}
|
|
return best
|
|
}
|
|
|
|
// toLower is an ASCII-only lowercase. Risk taxonomy values are
|
|
// ASCII; pulling in unicode here would be overkill.
|
|
func toLower(s string) string {
|
|
b := []byte(s)
|
|
for i, c := range b {
|
|
if c >= 'A' && c <= 'Z' {
|
|
b[i] = c + ('a' - 'A')
|
|
}
|
|
}
|
|
return string(b)
|
|
}
|