From 332c4571f94e23a48e6b95ff30c931f58b928de9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 13 Apr 2019 12:49:27 +0200 Subject: [PATCH] golint: capitalize acronyms jsonLoader.go:353:6: func decodeJsonUsingNumber should be decodeJSONUsingNumber schemaPool.go:153:2: var refToUrl should be refToURL utils.go:75:6: func marshalToJsonString should be marshalToJSONString utils.go:108:6: func isJsonNumber should be isJSONNumber utils.go:119:6: func checkJsonInteger should be checkJSONInteger utils.go:183:6: func resultErrorFormatJsonNumber should be resultErrorFormatJSONNumber Signed-off-by: Sebastiaan van Stijn --- jsonLoader.go | 24 ++++++++++++------------ jsonschema_test.go | 4 ++-- result.go | 2 +- schema.go | 8 ++++---- schemaPool.go | 10 +++++----- utils.go | 20 ++++++++++---------- utils_test.go | 4 ++-- validation.go | 18 +++++++++--------- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/jsonLoader.go b/jsonLoader.go index e17e3aa..4f57ff7 100644 --- a/jsonLoader.go +++ b/jsonLoader.go @@ -137,14 +137,14 @@ func (l *jsonReferenceLoader) LoadJSON() (interface{}, error) { return nil, err } - refToUrl := reference - refToUrl.GetUrl().Fragment = "" + refToURL := reference + refToURL.GetUrl().Fragment = "" var document interface{} if reference.HasFileScheme { - filename := strings.TrimPrefix(refToUrl.String(), "file://") + filename := strings.TrimPrefix(refToURL.String(), "file://") if runtime.GOOS == "windows" { // on Windows, a file URL may have an extra leading slash, use slashes // instead of backslashes, and have spaces escaped @@ -159,7 +159,7 @@ func (l *jsonReferenceLoader) LoadJSON() (interface{}, error) { } else { - document, err = l.loadFromHTTP(refToUrl.String()) + document, err = l.loadFromHTTP(refToURL.String()) if err != nil { return nil, err } @@ -175,7 +175,7 @@ func (l *jsonReferenceLoader) loadFromHTTP(address string) (interface{}, error) // returned cached versions for metaschemas for drafts 4, 6 and 7 // for performance and allow for easier offline use if metaSchema := drafts.GetMetaSchema(address); metaSchema != "" { - return decodeJsonUsingNumber(strings.NewReader(metaSchema)) + return decodeJSONUsingNumber(strings.NewReader(metaSchema)) } resp, err := http.Get(address) @@ -193,7 +193,7 @@ func (l *jsonReferenceLoader) loadFromHTTP(address string) (interface{}, error) return nil, err } - return decodeJsonUsingNumber(bytes.NewReader(bodyBuff)) + return decodeJSONUsingNumber(bytes.NewReader(bodyBuff)) } func (l *jsonReferenceLoader) loadFromFile(path string) (interface{}, error) { @@ -208,7 +208,7 @@ func (l *jsonReferenceLoader) loadFromFile(path string) (interface{}, error) { return nil, err } - return decodeJsonUsingNumber(bytes.NewReader(bodyBuff)) + return decodeJSONUsingNumber(bytes.NewReader(bodyBuff)) } @@ -237,7 +237,7 @@ func NewStringLoader(source string) JSONLoader { func (l *jsonStringLoader) LoadJSON() (interface{}, error) { - return decodeJsonUsingNumber(strings.NewReader(l.JsonSource().(string))) + return decodeJSONUsingNumber(strings.NewReader(l.JsonSource().(string))) } @@ -265,7 +265,7 @@ func NewBytesLoader(source []byte) JSONLoader { } func (l *jsonBytesLoader) LoadJSON() (interface{}, error) { - return decodeJsonUsingNumber(bytes.NewReader(l.JsonSource().([]byte))) + return decodeJSONUsingNumber(bytes.NewReader(l.JsonSource().([]byte))) } // JSON Go (types) loader @@ -301,7 +301,7 @@ func (l *jsonGoLoader) LoadJSON() (interface{}, error) { return nil, err } - return decodeJsonUsingNumber(bytes.NewReader(jsonBytes)) + return decodeJSONUsingNumber(bytes.NewReader(jsonBytes)) } @@ -326,7 +326,7 @@ func (l *jsonIOLoader) JsonSource() interface{} { } func (l *jsonIOLoader) LoadJSON() (interface{}, error) { - return decodeJsonUsingNumber(l.buf) + return decodeJSONUsingNumber(l.buf) } func (l *jsonIOLoader) JsonReference() (gojsonreference.JsonReference, error) { @@ -362,7 +362,7 @@ func (l *jsonRawLoader) LoaderFactory() JSONLoaderFactory { return &DefaultJSONLoaderFactory{} } -func decodeJsonUsingNumber(r io.Reader) (interface{}, error) { +func decodeJSONUsingNumber(r io.Reader) (interface{}, error) { var document interface{} diff --git a/jsonschema_test.go b/jsonschema_test.go index 5224129..75a666f 100644 --- a/jsonschema_test.go +++ b/jsonschema_test.go @@ -96,8 +96,8 @@ func executeTests(t *testing.T, path string) error { } if result.Valid() != testCase.Valid { - schemaString, _ := marshalToJsonString(test.Schema) - testCaseString, _ := marshalToJsonString(testCase.Data) + schemaString, _ := marshalToJSONString(test.Schema) + testCaseString, _ := marshalToJSONString(testCase.Data) t.Errorf("Test failed : %s\n"+ "%s.\n"+ diff --git a/result.go b/result.go index 6033cbb..0a01791 100644 --- a/result.go +++ b/result.go @@ -164,7 +164,7 @@ func (v ResultErrorFields) String() string { if v.value == nil { valueString = TYPE_NULL } else { - if vs, err := marshalToJsonString(v.value); err == nil { + if vs, err := marshalToJSONString(v.value); err == nil { if vs == nil { valueString = TYPE_NULL } else { diff --git a/schema.go b/schema.go index e7ae4bc..e0250bd 100644 --- a/schema.go +++ b/schema.go @@ -509,7 +509,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema) currentSchema.exclusiveMinimum = currentSchema.minimum currentSchema.minimum = nil } - } else if isJsonNumber(m[KEY_EXCLUSIVE_MINIMUM]) { + } else if isJSONNumber(m[KEY_EXCLUSIVE_MINIMUM]) { currentSchema.exclusiveMinimum = mustBeNumber(m[KEY_EXCLUSIVE_MINIMUM]) } else { return errors.New(formatErrorDescription( @@ -521,7 +521,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema) )) } default: - if isJsonNumber(m[KEY_EXCLUSIVE_MINIMUM]) { + if isJSONNumber(m[KEY_EXCLUSIVE_MINIMUM]) { currentSchema.exclusiveMinimum = mustBeNumber(m[KEY_EXCLUSIVE_MINIMUM]) } else { return errors.New(formatErrorDescription( @@ -580,7 +580,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema) currentSchema.exclusiveMaximum = currentSchema.maximum currentSchema.maximum = nil } - } else if isJsonNumber(m[KEY_EXCLUSIVE_MAXIMUM]) { + } else if isJSONNumber(m[KEY_EXCLUSIVE_MAXIMUM]) { currentSchema.exclusiveMaximum = mustBeNumber(m[KEY_EXCLUSIVE_MAXIMUM]) } else { return errors.New(formatErrorDescription( @@ -592,7 +592,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema) )) } default: - if isJsonNumber(m[KEY_EXCLUSIVE_MAXIMUM]) { + if isJSONNumber(m[KEY_EXCLUSIVE_MAXIMUM]) { currentSchema.exclusiveMaximum = mustBeNumber(m[KEY_EXCLUSIVE_MAXIMUM]) } else { return errors.New(formatErrorDescription( diff --git a/schemaPool.go b/schemaPool.go index f124e03..35b1cc6 100644 --- a/schemaPool.go +++ b/schemaPool.go @@ -150,12 +150,12 @@ func (p *schemaPool) GetDocument(reference gojsonreference.JsonReference) (*sche } // Create a deep copy, so we can remove the fragment part later on without altering the original - refToUrl, _ := gojsonreference.NewJsonReference(reference.String()) + refToURL, _ := gojsonreference.NewJsonReference(reference.String()) // First check if the given fragment is a location independent identifier // http://json-schema.org/latest/json-schema-core.html#rfc.section.8.2.3 - if spd, ok = p.schemaPoolDocuments[refToUrl.String()]; ok { + if spd, ok = p.schemaPoolDocuments[refToURL.String()]; ok { if internalLogEnabled { internalLog(" From pool") } @@ -165,9 +165,9 @@ func (p *schemaPool) GetDocument(reference gojsonreference.JsonReference) (*sche // If the given reference is not a location independent identifier, // strip the fragment and look for a document with it's base URI - refToUrl.GetUrl().Fragment = "" + refToURL.GetUrl().Fragment = "" - if cachedSpd, ok := p.schemaPoolDocuments[refToUrl.String()]; ok { + if cachedSpd, ok := p.schemaPoolDocuments[refToURL.String()]; ok { document, _, err := reference.GetPointer().Get(cachedSpd.Document) if err != nil { @@ -200,7 +200,7 @@ func (p *schemaPool) GetDocument(reference gojsonreference.JsonReference) (*sche } // add the whole document to the pool for potential re-use - p.parseReferences(document, refToUrl, true) + p.parseReferences(document, refToURL, true) _, draft, _ = parseSchemaURL(document) diff --git a/utils.go b/utils.go index 0b6810a..b960a3c 100644 --- a/utils.go +++ b/utils.go @@ -35,7 +35,7 @@ import ( func isKind(what interface{}, kinds ...reflect.Kind) bool { target := what - if isJsonNumber(what) { + if isJSONNumber(what) { // JSON Numbers are strings! target = *mustBeNumber(what) } @@ -72,7 +72,7 @@ func indexStringInSlice(s []string, what string) int { return -1 } -func marshalToJsonString(value interface{}) (*string, error) { +func marshalToJSONString(value interface{}) (*string, error) { mBytes, err := json.Marshal(value) if err != nil { @@ -90,7 +90,7 @@ func marshalWithoutNumber(value interface{}) (*string, error) { // One way to eliminate these differences is to decode and encode the JSON one more time without Decoder.UseNumber // so that these differences in representation are removed - jsonString, err := marshalToJsonString(value) + jsonString, err := marshalToJSONString(value) if err != nil { return nil, err } @@ -102,10 +102,10 @@ func marshalWithoutNumber(value interface{}) (*string, error) { return nil, err } - return marshalToJsonString(document) + return marshalToJSONString(document) } -func isJsonNumber(what interface{}) bool { +func isJSONNumber(what interface{}) bool { switch what.(type) { @@ -116,7 +116,7 @@ func isJsonNumber(what interface{}) bool { return false } -func checkJsonInteger(what interface{}) (isInt bool) { +func checkJSONInteger(what interface{}) (isInt bool) { jsonNumber := what.(json.Number) @@ -143,11 +143,11 @@ func isFloat64AnInteger(f float64) bool { func mustBeInteger(what interface{}) *int { - if isJsonNumber(what) { + if isJSONNumber(what) { number := what.(json.Number) - isInt := checkJsonInteger(number) + isInt := checkJSONInteger(number) if isInt { @@ -167,7 +167,7 @@ func mustBeInteger(what interface{}) *int { func mustBeNumber(what interface{}) *big.Rat { - if isJsonNumber(what) { + if isJSONNumber(what) { number := what.(json.Number) float64Value, success := new(big.Rat).SetString(string(number)) if success { @@ -180,7 +180,7 @@ func mustBeNumber(what interface{}) *big.Rat { } // formats a number so that it is displayed as the smallest string possible -func resultErrorFormatJsonNumber(n json.Number) string { +func resultErrorFormatJSONNumber(n json.Number) string { if int64Value, err := n.Int64(); err == nil { return fmt.Sprintf("%d", int64Value) diff --git a/utils_test.go b/utils_test.go index 2450d93..94a7051 100644 --- a/utils_test.go +++ b/utils_test.go @@ -84,8 +84,8 @@ func TestCheckJsonNumber(t *testing.T) { } for _, testCase := range testCases { - assert.Equal(t, testCase.isInt, checkJsonInteger(testCase.value)) - assert.Equal(t, testCase.isInt, checkJsonInteger(testCase.value)) + assert.Equal(t, testCase.isInt, checkJSONInteger(testCase.value)) + assert.Equal(t, testCase.isInt, checkJSONInteger(testCase.value)) } } diff --git a/validation.go b/validation.go index c2f33dd..91f43a1 100644 --- a/validation.go +++ b/validation.go @@ -101,11 +101,11 @@ func (v *subSchema) validateRecursive(currentSubSchema *subSchema, currentNode i } else { // Not a null value - if isJsonNumber(currentNode) { + if isJSONNumber(currentNode) { value := currentNode.(json.Number) - isInt := checkJsonInteger(value) + isInt := checkJSONInteger(value) validType := currentSubSchema.types.Contains(TYPE_NUMBER) || (isInt && currentSubSchema.types.Contains(TYPE_INTEGER)) @@ -750,7 +750,7 @@ func (v *subSchema) validatePatternProperty(currentSubSchema *subSchema, key str func (v *subSchema) validateString(currentSubSchema *subSchema, value interface{}, result *Result, context *JsonContext) { // Ignore JSON numbers - if isJsonNumber(value) { + if isJSONNumber(value) { return } @@ -819,7 +819,7 @@ func (v *subSchema) validateString(currentSubSchema *subSchema, value interface{ func (v *subSchema) validateNumber(currentSubSchema *subSchema, value interface{}, result *Result, context *JsonContext) { // Ignore non numbers - if !isJsonNumber(value) { + if !isJSONNumber(value) { return } @@ -837,7 +837,7 @@ func (v *subSchema) validateNumber(currentSubSchema *subSchema, value interface{ result.addInternalError( new(MultipleOfError), context, - resultErrorFormatJsonNumber(number), + resultErrorFormatJSONNumber(number), ErrorDetails{"multiple": new(big.Float).SetRat(currentSubSchema.multipleOf)}, ) } @@ -849,7 +849,7 @@ func (v *subSchema) validateNumber(currentSubSchema *subSchema, value interface{ result.addInternalError( new(NumberLTEError), context, - resultErrorFormatJsonNumber(number), + resultErrorFormatJSONNumber(number), ErrorDetails{ "max": currentSubSchema.maximum, }, @@ -861,7 +861,7 @@ func (v *subSchema) validateNumber(currentSubSchema *subSchema, value interface{ result.addInternalError( new(NumberLTError), context, - resultErrorFormatJsonNumber(number), + resultErrorFormatJSONNumber(number), ErrorDetails{ "max": currentSubSchema.exclusiveMaximum, }, @@ -875,7 +875,7 @@ func (v *subSchema) validateNumber(currentSubSchema *subSchema, value interface{ result.addInternalError( new(NumberGTEError), context, - resultErrorFormatJsonNumber(number), + resultErrorFormatJSONNumber(number), ErrorDetails{ "min": currentSubSchema.minimum, }, @@ -888,7 +888,7 @@ func (v *subSchema) validateNumber(currentSubSchema *subSchema, value interface{ result.addInternalError( new(NumberGTError), context, - resultErrorFormatJsonNumber(number), + resultErrorFormatJSONNumber(number), ErrorDetails{ "min": currentSubSchema.exclusiveMinimum, },