V001

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2022 License: MPL-2.0 Imports: 6 Imported by: 0

README

V001

The V001 analyzer reports when custom SchemaValidateFunc declarations can be replaced with validation.StringMatch() or validation.StringDoesNotMatch().

Flagged Code

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

  if !regexp.MustCompile(`^s-([0-9a-f]{17})$`).MatchString(value) {
    errors = append(errors, fmt.Errorf("%q must begin with s- and contain 17 lowercase alphanumeric characters: %q", k, value))
  }

  return
}

Passing Code

// directly in Schema
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^s-([0-9a-f]{17})$`), "must begin with s- and contain 17 lowercase alphanumeric characters"),

// or saving as a variable
var validateExampleThing = validation.StringMatch(regexp.MustCompile(`^s-([0-9a-f]{17})$`), "must begin with s- and contain 17 lowercase alphanumeric characters")

// or replacing the function
func validateExampleThing() schema.SchemaValidateFunc {
  return validation.StringMatch(regexp.MustCompile(`^s-([0-9a-f]{17})$`), "must begin with s- and contain 17 lowercase alphanumeric characters")
}

Ignoring Reports

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

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

  if !regexp.MustCompile(`^s-([0-9a-f]{17})$`).MatchString(value) {
    errors = append(errors, fmt.Errorf("%q must begin with s- and contain 17 lowercase alphanumeric characters: %q", k, value))
  }

  return
}

Documentation

Overview

Package V001 defines an Analyzer that checks for custom SchemaValidateFunc that implement validation.StringMatch()

Index

Constants

View Source
const Doc = `` /* 228-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