fix: P1 — classifyOperation accepts any underscore prefix + format.Source warns instead of silently writing broken Go
This commit is contained in:
@@ -620,10 +620,7 @@ func writeInstanceResource(outDir string, svc GenResource) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
formatted, err := format.Source(buf.Bytes())
|
formatted := formatSourceOrWarn(filePath, buf.Bytes())
|
||||||
if err != nil {
|
|
||||||
formatted = buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.WriteFile(filePath, formatted, 0644)
|
return os.WriteFile(filePath, formatted, 0644)
|
||||||
}
|
}
|
||||||
@@ -654,10 +651,7 @@ func writeSubresource(outDir string, sr GenSubresource) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
formatted, err := format.Source(buf.Bytes())
|
formatted := formatSourceOrWarn(filePath, buf.Bytes())
|
||||||
if err != nil {
|
|
||||||
formatted = buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.WriteFile(filePath, formatted, 0644)
|
return os.WriteFile(filePath, formatted, 0644)
|
||||||
}
|
}
|
||||||
@@ -686,10 +680,7 @@ func writeActionResource(outDir string, act GenAction) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
formatted, err := format.Source(buf.Bytes())
|
formatted := formatSourceOrWarn(filePath, buf.Bytes())
|
||||||
if err != nil {
|
|
||||||
formatted = buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.WriteFile(filePath, formatted, 0644)
|
return os.WriteFile(filePath, formatted, 0644)
|
||||||
}
|
}
|
||||||
@@ -713,12 +704,10 @@ func writeRegistry(outDir string, services []GenResource, subs []GenSubresource,
|
|||||||
buf.WriteString("\t}\n")
|
buf.WriteString("\t}\n")
|
||||||
buf.WriteString("}\n")
|
buf.WriteString("}\n")
|
||||||
|
|
||||||
formatted, err := format.Source(buf.Bytes())
|
regPath := filepath.Join(outDir, "registry.go")
|
||||||
if err != nil {
|
formatted := formatSourceOrWarn(regPath, buf.Bytes())
|
||||||
formatted = buf.Bytes()
|
|
||||||
}
|
|
||||||
|
|
||||||
return os.WriteFile(filepath.Join(outDir, "registry.go"), formatted, 0644)
|
return os.WriteFile(regPath, formatted, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toCamel(s string) string {
|
func toCamel(s string) string {
|
||||||
@@ -2077,6 +2066,17 @@ func validateSpec(path string, spec *ServiceSpec) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// formatSourceOrWarn форматирует Go-код. При ошибке пишет warning в stderr и возвращает неформатированный код.
|
||||||
|
func formatSourceOrWarn(filePath string, src []byte) []byte {
|
||||||
|
formatted, err := format.Source(src)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "WARNING: gofmt failed for %s: %v — writing unformatted code\n", filePath, err)
|
||||||
|
return src
|
||||||
|
}
|
||||||
|
return formatted
|
||||||
|
}
|
||||||
|
|
||||||
func buildSubresourceForceNewCodes(sr *GenSubresource, createOnly map[string]struct{}) map[string]struct{} {
|
func buildSubresourceForceNewCodes(sr *GenSubresource, createOnly map[string]struct{}) map[string]struct{} {
|
||||||
forceNew := map[string]struct{}{}
|
forceNew := map[string]struct{}{}
|
||||||
if sr.ModifyOpName == "" {
|
if sr.ModifyOpName == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user