Skip to content

Commit

Permalink
golint: capitalize acronyms
Browse files Browse the repository at this point in the history
    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 <[email protected]>
  • Loading branch information
thaJeztah authored and johandorland committed Apr 18, 2019
1 parent 5fcca16 commit 332c457
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
24 changes: 12 additions & 12 deletions jsonLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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)
Expand All @@ -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) {
Expand All @@ -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))

}

Expand Down Expand Up @@ -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)))

}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -301,7 +301,7 @@ func (l *jsonGoLoader) LoadJSON() (interface{}, error) {
return nil, err
}

return decodeJsonUsingNumber(bytes.NewReader(jsonBytes))
return decodeJSONUsingNumber(bytes.NewReader(jsonBytes))

}

Expand All @@ -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) {
Expand Down Expand Up @@ -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{}

Expand Down
4 changes: 2 additions & 2 deletions jsonschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down
2 changes: 1 addition & 1 deletion result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions schemaPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
20 changes: 10 additions & 10 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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) {

Expand All @@ -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)

Expand All @@ -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 {

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
18 changes: 9 additions & 9 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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)},
)
}
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down

0 comments on commit 332c457

Please sign in to comment.