V012

package
v0.30.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MPL-2.0 Imports: 8 Imported by: 2

README

V012

The V012 analyzer reports when custom SchemaValidateFunc declarations can be replaced with validation.IntAtLeast(), validation.IntAtMost(), or validation.IntBetween().

Flagged Code

func validateExampleThing(v interface{}, k string) (ws []string, errors []error) {
  value := v.(int)

  if value < 1 || value > 255 {
    errors = append(errors, fmt.Errorf("%q must be between 1 and 255: %d", k, value))
  }

  return
}

Passing Code

// directly in Schema
ValidateFunc: validation.IntBetween(1, 255),

// or saving as a variable
var validateExampleThing = validation.IntBetween(1, 255)

// or replacing the function
func validateExampleThing() schema.SchemaValidateFunc {
  return validation.IntBetween(1, 255)
}

Ignoring Reports

Singular reports can be ignored by adding the a //lintignore:V012 Go code comment at the end of the offending line or on the line immediately proceding, e.g.

//lintignore:V012
func validateExampleThing(v interface{}, k string) (ws []string, errors []error) {
  value := v.(int)

  if value < 1 || value > 255 {
    errors = append(errors, fmt.Errorf("%q must be between 1 and 255: %d", k, value))
  }

  return
}

Documentation

Index

Constants

View Source
const Doc = `` /* 295-byte string literal not displayed */

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name: analyzerName,
	Doc:  Doc,
	Requires: []*analysis.Analyzer{
		commentignore.Analyzer,
		schemavalidatefuncinfo.Analyzer,
	},
	Run: run,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL