Skip to content

Commit

Permalink
feat: make snippet validator warning
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Jan 17, 2024
1 parent bba0b7c commit 585ae25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions extension/snippet_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,17 @@ func compareSnippets(mainFile []byte, file string, context *ValidationContext, e
normalizedPath := strings.ReplaceAll(file, extensionRoot+"/", "")

if diff.Type == jsondiff.OperationReplace && reflect.TypeOf(diff.OldValue) != reflect.TypeOf(diff.Value) {
context.AddError(fmt.Sprintf("Snippet file: %s, key: %s, has the type %s, but in the main language it is %s", normalizedPath, diff.Path, reflect.TypeOf(diff.OldValue), reflect.TypeOf(diff.Value)))
context.AddWarning(fmt.Sprintf("Snippet file: %s, key: %s, has the type %s, but in the main language it is %s", normalizedPath, diff.Path, reflect.TypeOf(diff.OldValue), reflect.TypeOf(diff.Value)))
continue
}

if diff.Type == jsondiff.OperationAdd {
context.AddError(fmt.Sprintf("Snippet file: %s, missing key \"%s\" in this snippet file, but defined in the main language", normalizedPath, diff.Path))
context.AddWarning(fmt.Sprintf("Snippet file: %s, missing key \"%s\" in this snippet file, but defined in the main language", normalizedPath, diff.Path))
continue
}

if diff.Type == jsondiff.OperationRemove {
context.AddError(fmt.Sprintf("Snippet file: %s, key %s is missing, but defined in the main language file", normalizedPath, diff.Path))
context.AddWarning(fmt.Sprintf("Snippet file: %s, key %s is missing, but defined in the main language file", normalizedPath, diff.Path))
continue
}
}
Expand Down
8 changes: 4 additions & 4 deletions extension/snippet_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func TestSnippetValidateStorefrontByPathTestDifferent(t *testing.T) {
_ = os.WriteFile(path.Join(tmpDir, "Resources", "snippet", "storefront.de-DE.json"), []byte(`{"b": "2"}`), os.ModePerm)

assert.NoError(t, validateStorefrontSnippetsByPath(tmpDir, tmpDir, context))
assert.Len(t, context.errors, 2)
assert.Len(t, context.warnings, 0)
assert.Contains(t, context.errors[0], "key /a is missing, but defined in the main language file")
assert.Contains(t, context.errors[1], "missing key \"/b\" in this snippet file, but defined in the main language")
assert.Len(t, context.errors, 0)
assert.Len(t, context.warnings, 2)
assert.Contains(t, context.warnings[0], "key /a is missing, but defined in the main language file")
assert.Contains(t, context.warnings[1], "missing key \"/b\" in this snippet file, but defined in the main language")
}

0 comments on commit 585ae25

Please sign in to comment.