Error on duplicate keys
This commit is contained in:
@@ -264,6 +264,7 @@ func ValidateProject(p *project.Project) ValidationReport {
|
||||
})
|
||||
validateTopPackageAssets(sourceDir, dataDir, &report)
|
||||
validateNativeOutputCatalog(dataDir, &report)
|
||||
validateNativeEntryKeyUniqueness(dataDir, &report)
|
||||
validateNativeLockAllocation(dataDir, &report)
|
||||
validateGeneratedFeatFamilies(dataDir, &report)
|
||||
validateItempropsRegistryGraph(dataDir, &report)
|
||||
@@ -1001,6 +1002,64 @@ func validateNativeOutputCatalog(dataDir string, report *ValidationReport) {
|
||||
}
|
||||
}
|
||||
|
||||
func validateNativeEntryKeyUniqueness(dataDir string, report *ValidationReport) {
|
||||
datasets, err := discoverNativeDatasets(dataDir)
|
||||
if err != nil {
|
||||
report.Diagnostics = append(report.Diagnostics, Diagnostic{
|
||||
Severity: SeverityError,
|
||||
Path: dataDir,
|
||||
Message: fmt.Sprintf("discover native datasets for entry key uniqueness validation: %v", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
for _, dataset := range datasets {
|
||||
if dataset.Kind != nativeDatasetBase {
|
||||
continue
|
||||
}
|
||||
entryKeyPath := map[string]string{}
|
||||
for _, dir := range []string{dataset.ModulesDir, dataset.GeneratedDir} {
|
||||
paths, err := collectModulePaths(dir)
|
||||
if err != nil {
|
||||
report.Diagnostics = append(report.Diagnostics, Diagnostic{
|
||||
Severity: SeverityError,
|
||||
Path: dir,
|
||||
Message: fmt.Sprintf("collect module paths for entry key uniqueness validation: %v", err),
|
||||
})
|
||||
continue
|
||||
}
|
||||
for _, path := range paths {
|
||||
obj, err := loadJSONObject(path)
|
||||
if err != nil {
|
||||
report.Diagnostics = append(report.Diagnostics, Diagnostic{
|
||||
Severity: SeverityError,
|
||||
Path: path,
|
||||
Message: fmt.Sprintf("load module for entry key uniqueness validation: %v", err),
|
||||
})
|
||||
continue
|
||||
}
|
||||
entries, ok := obj["entries"].(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, key := range sortedKeys(entries) {
|
||||
if key == "" {
|
||||
continue
|
||||
}
|
||||
if previousPath, exists := entryKeyPath[key]; exists {
|
||||
report.Diagnostics = append(report.Diagnostics, Diagnostic{
|
||||
Severity: SeverityError,
|
||||
Path: path,
|
||||
Message: fmt.Sprintf("duplicate entries key %q declared by %s and %s", key, previousPath, path),
|
||||
})
|
||||
continue
|
||||
}
|
||||
entryKeyPath[key] = path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func validateNativeLockAllocation(dataDir string, report *ValidationReport) {
|
||||
datasets, err := discoverNativeDatasets(dataDir)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user