lint

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2018 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllLinters is the slice of all known Linters.
	AllLinters = []Linter{
		commentsNoCStyleLinter,
		enumFieldNamesUppercaseLinter,
		enumFieldNamesUpperSnakeCaseLinter,
		enumFieldPrefixesLinter,
		enumNamesCamelCaseLinter,
		enumNamesCapitalizedLinter,
		enumZeroValuesInvalidLinter,
		enumsHaveCommentsLinter,
		enumsNoAllowAliasLinter,
		fileOptionsEqualGoPackagePbSuffixLinter,
		fileOptionsEqualJavaMultipleFilesTrueLinter,
		fileOptionsEqualJavaOuterClassnameProtoSuffixLinter,
		fileOptionsEqualJavaPackageComPrefixLinter,
		fileOptionsGoPackageSameInDirLinter,
		fileOptionsJavaMultipleFilesSameInDirLinter,
		fileOptionsJavaPackageSameInDirLinter,
		fileOptionsRequireGoPackageLinter,
		fileOptionsRequireJavaMultipleFilesLinter,
		fileOptionsRequireJavaOuterClassnameLinter,
		fileOptionsRequireJavaPackageLinter,
		fileOptionsUnsetJavaMultipleFilesLinter,
		fileOptionsUnsetJavaOuterClassnameLinter,
		messageFieldsNotFloatsLinter,
		messageFieldNamesLowerSnakeCaseLinter,
		messageFieldNamesLowercaseLinter,
		messageNamesCamelCaseLinter,
		messageNamesCapitalizedLinter,
		messagesHaveCommentsLinter,
		messagesHaveCommentsExceptRequestResponseTypesLinter,
		oneofNamesLowerSnakeCaseLinter,
		packageIsDeclaredLinter,
		packageLowerSnakeCaseLinter,
		packagesSameInDirLinter,
		rpcsHaveCommentsLinter,
		rpcNamesCamelCaseLinter,
		rpcNamesCapitalizedLinter,
		requestResponseTypesInSameFileLinter,
		requestResponseTypesUniqueLinter,
		requestResponseNamesMatchRPCLinter,
		servicesHaveCommentsLinter,
		serviceNamesCamelCaseLinter,
		serviceNamesCapitalizedLinter,
		syntaxProto3Linter,
		wktDirectlyImportedLinter,
	}

	// DefaultLinters is the slice of default Linters.
	DefaultLinters = copyLintersWithout(
		AllLinters,
		enumFieldNamesUppercaseLinter,
		enumsHaveCommentsLinter,
		fileOptionsUnsetJavaMultipleFilesLinter,
		fileOptionsUnsetJavaOuterClassnameLinter,
		messageFieldsNotFloatsLinter,
		messagesHaveCommentsLinter,
		messagesHaveCommentsExceptRequestResponseTypesLinter,
		messageFieldNamesLowercaseLinter,
		requestResponseNamesMatchRPCLinter,
		rpcsHaveCommentsLinter,
		servicesHaveCommentsLinter,
	)

	// DefaultGroup is the default group.
	DefaultGroup = "default"

	// AllGroup is the group of all known linters.
	AllGroup = "all"

	// GroupToLinters is the map from linter group to the corresponding slice of linters.
	GroupToLinters = map[string][]Linter{
		DefaultGroup: DefaultLinters,
		AllGroup:     AllLinters,
	}
)

Functions

func CheckMultiple

func CheckMultiple(linters []Linter, dirPathToDescriptors map[string][]*proto.Proto, ignoreIDToFilePaths map[string][]string) ([]*text.Failure, error)

CheckMultiple is a convenience function that checks multiple linters and multiple descriptors.

func GetDirPathToDescriptors

func GetDirPathToDescriptors(protoSet *file.ProtoSet) (map[string][]*proto.Proto, error)

GetDirPathToDescriptors is a convenience function that gets the descriptors for the given ProtoSet.

Types

type Linter

type Linter interface {
	// Return the ID of this Linter. This should be all UPPER_SNAKE_CASE.
	ID() string
	// Return the purpose of this Linter. This should be a human-readable string.
	Purpose() string
	// Check the file data for the descriptors in a common directgory.
	// If there is a lint failure, this returns it in the
	// slice and does not return an error. An error is returned if something
	// unexpected happens. Callers should verify the files are compilable
	// before running this.
	Check(dirPath string, descriptors []*proto.Proto) ([]*text.Failure, error)
}

Linter is a linter for Protobuf files.

func GetLinters

func GetLinters(config settings.LintConfig) ([]Linter, error)

GetLinters returns the Linters for the LintConfig.

The configuration is expected to be valid, deduplicated, and all upper-case. IncludeIDs and ExcludeIDs MUST NOT have an intersection.

If the config came from the settings package, this is already validated.

func NewLinter

func NewLinter(id string, purpose string, addCheck func(func(*text.Failure), string, []*proto.Proto) error) Linter

NewLinter is a convenience function that returns a new Linter for the given parameters, using a function to record failures.

The ID will be upper-cased.

Failures returned from check do not need to set the ID, this will be overwritten.

type Runner

type Runner interface {
	Run(*file.ProtoSet) ([]*text.Failure, error)
}

Runner runs a lint job.

func NewRunner

func NewRunner(options ...RunnerOption) Runner

NewRunner returns a new Runner.

type RunnerOption

type RunnerOption func(*runner)

RunnerOption is an option for a new Runner.

func RunnerWithLogger

func RunnerWithLogger(logger *zap.Logger) RunnerOption

RunnerWithLogger returns a RunnerOption that uses the given logger.

The default is to use zap.NewNop().

Jump to

Keyboard shortcuts

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