Skip to content

Commit cb958f1

Browse files
committed
review
1 parent acfd4df commit cb958f1

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg/commands/config_verify.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http"
99
"os"
1010
"path/filepath"
11+
"strconv"
1112
"strings"
1213
"time"
1314

@@ -44,9 +45,7 @@ func (c *configCommand) executeVerify(cmd *cobra.Command, _ []string) error {
4445
return fmt.Errorf("[%s] validate: %w", usedConfigFile, err)
4546
}
4647

47-
detail := v.DetailedOutput()
48-
49-
printValidationDetail(cmd, detail)
48+
printValidationDetail(cmd, v.DetailedOutput())
5049

5150
return errors.New("the configuration contains invalid elements")
5251
}
@@ -102,11 +101,10 @@ func createSchemaURL(flags *pflag.FlagSet, buildInfo BuildInfo) (string, error)
102101

103102
func validateConfiguration(schemaPath, targetFile string) error {
104103
compiler := jsonschema.NewCompiler()
105-
loader := jsonschema.SchemeURLLoader{
104+
compiler.UseLoader(jsonschema.SchemeURLLoader{
106105
"file": jsonschema.FileLoader{},
107106
"https": newJSONSchemaHTTPLoader(),
108-
}
109-
compiler.UseLoader(loader)
107+
})
110108
compiler.DefaultDraft(jsonschema.Draft7)
111109

112110
schema, err := compiler.Compile(schemaPath)
@@ -139,9 +137,11 @@ func validateConfiguration(schemaPath, targetFile string) error {
139137

140138
func printValidationDetail(cmd *cobra.Command, detail *jsonschema.OutputUnit) {
141139
if detail.Error != nil {
142-
b, _ := json.Marshal(detail.Error)
140+
data, _ := json.Marshal(detail.Error)
141+
details, _ := strconv.Unquote(string(data))
142+
143143
cmd.PrintErrf("jsonschema: %q does not validate with %q: %s\n",
144-
strings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, "/"), "/", "."), detail.KeywordLocation, b)
144+
strings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, "/"), "/", "."), detail.KeywordLocation, details)
145145
}
146146

147147
for _, d := range detail.Errors {

test/configuration_file_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
)
1616

1717
func Test_validateTestConfigurationFiles(t *testing.T) {
18-
err := validateTestConfigurationFiles("../../jsonschema/golangci.next.jsonschema.json", ".")
18+
err := validateTestConfigurationFiles("../jsonschema/golangci.next.jsonschema.json", ".")
1919
require.NoError(t, err)
2020
}
2121

0 commit comments

Comments
 (0)