Documentation ¶
Index ¶
- Variables
- func CheckMultiple(linters []Linter, dirPathToDescriptors map[string][]*FileDescriptor, ...) ([]*text.Failure, error)
- func GetDirPathToDescriptors(protoSet *file.ProtoSet, absolutePaths bool) (map[string][]*FileDescriptor, error)
- type FileDescriptor
- type Linter
- type Runner
- type RunnerOption
Constants ¶
This section is empty.
Variables ¶
var ( // AllLinters is the slice of all known Linters. AllLinters = []Linter{ commentsNoCStyleLinter, commentsNoInlineLinter, enumFieldNamesUppercaseLinter, enumFieldNamesUpperSnakeCaseLinter, enumFieldPrefixesLinter, enumFieldPrefixesExceptMessageLinter, enumFieldsHaveCommentsLinter, enumFieldsHaveSentenceCommentsLinter, enumNamesCamelCaseLinter, enumNamesCapitalizedLinter, enumZeroValuesInvalidLinter, enumZeroValuesInvalidExceptMessageLinter, enumsHaveCommentsLinter, enumsHaveSentenceCommentsLinter, enumsNoAllowAliasLinter, fieldsNotReservedLinter, fileHeaderLinter, fileNamesLowerSnakeCaseLinter, fileOptionsCSharpNamespaceSameInDirLinter, fileOptionsEqualCSharpNamespaceCapitalizedLinter, fileOptionsEqualGoPackageV2SuffixLinter, fileOptionsEqualGoPackagePbSuffixLinter, fileOptionsEqualJavaMultipleFilesTrueLinter, fileOptionsEqualJavaOuterClassnameProtoSuffixLinter, fileOptionsEqualJavaPackageComPrefixLinter, fileOptionsEqualJavaPackagePrefixLinter, fileOptionsEqualOBJCClassPrefixAbbrLinter, fileOptionsEqualPHPNamespaceCapitalizedLinter, fileOptionsGoPackageNotLongFormLinter, fileOptionsGoPackageSameInDirLinter, fileOptionsJavaMultipleFilesSameInDirLinter, fileOptionsJavaPackageSameInDirLinter, fileOptionsOBJCClassPrefixSameInDirLinter, fileOptionsPHPNamespaceSameInDirLinter, fileOptionsRequireCSharpNamespaceLinter, fileOptionsRequireGoPackageLinter, fileOptionsRequireJavaMultipleFilesLinter, fileOptionsRequireJavaOuterClassnameLinter, fileOptionsRequireJavaPackageLinter, fileOptionsRequireOBJCClassPrefixLinter, fileOptionsRequirePHPNamespaceLinter, fileOptionsRequireRubyPackageLinter, fileOptionsUnsetJavaMultipleFilesLinter, fileOptionsUnsetJavaOuterClassnameLinter, gogoNotImportedLinter, importsNotPublicLinter, importsNotWeakLinter, messageFieldsDurationLinter, messageFieldsHaveCommentsLinter, messageFieldsHaveSentenceCommentsLinter, messageFieldsNotFloatsLinter, messageFieldsNoJSONNameLinter, messageFieldsTimeLinter, messageFieldNamesFilenameLinter, messageFieldNamesFilepathLinter, messageFieldNamesLowerSnakeCaseLinter, messageFieldNamesLowercaseLinter, messageFieldNamesNoDescriptorLinter, messageNamesCamelCaseLinter, messageNamesCapitalizedLinter, messagesHaveCommentsLinter, messagesHaveCommentsExceptRequestResponseTypesLinter, messagesHaveSentenceCommentsExceptRequestResponseTypesLinter, messagesNotEmptyExceptRequestResponseTypesLinter, namesNoCommonLinter, namesNoDataLinter, namesNoUUIDLinter, oneofNamesLowerSnakeCaseLinter, packageIsDeclaredLinter, packageLowerCaseLinter, packageLowerSnakeCaseLinter, packageMajorBetaVersionedLinter, packageNoKeywordsLinter, packagesSameInDirLinter, rpcsHaveCommentsLinter, rpcsHaveSentenceCommentsLinter, rpcsNoStreamingLinter, rpcNamesCamelCaseLinter, rpcNamesCapitalizedLinter, rpcOptionsNoGoogleAPIHTTPLinter, requestResponseTypesAfterServiceLinter, requestResponseTypesInSameFileLinter, requestResponseTypesOnlyInFileLinter, requestResponseTypesUniqueLinter, requestResponseNamesMatchRPCLinter, servicesHaveCommentsLinter, servicesHaveSentenceCommentsLinter, serviceNamesAPISuffixLinter, serviceNamesCamelCaseLinter, serviceNamesCapitalizedLinter, serviceNamesMatchFileNameLinter, serviceNamesNoPluralsLinter, syntaxProto3Linter, wktDirectlyImportedLinter, wktDurationSuffixLinter, wktTimestampSuffixLinter, } // DefaultLinters is the slice of default Linters. DefaultLinters = Uber1Linters // GoogleLinters is the slice of linters for the google lint group. GoogleLinters = []Linter{ enumFieldNamesUpperSnakeCaseLinter, enumNamesCamelCaseLinter, enumNamesCapitalizedLinter, fileHeaderLinter, messageFieldNamesLowerSnakeCaseLinter, messageNamesCamelCaseLinter, messageNamesCapitalizedLinter, rpcNamesCamelCaseLinter, rpcNamesCapitalizedLinter, serviceNamesCamelCaseLinter, serviceNamesCapitalizedLinter, } // Uber1Linters is the slice of linters for the uber1 lint group. Uber1Linters = []Linter{ commentsNoCStyleLinter, enumFieldNamesUpperSnakeCaseLinter, enumFieldPrefixesLinter, enumNamesCamelCaseLinter, enumNamesCapitalizedLinter, enumZeroValuesInvalidLinter, enumsNoAllowAliasLinter, fileHeaderLinter, fileOptionsEqualGoPackagePbSuffixLinter, fileOptionsEqualJavaMultipleFilesTrueLinter, fileOptionsEqualJavaOuterClassnameProtoSuffixLinter, fileOptionsEqualJavaPackageComPrefixLinter, fileOptionsGoPackageNotLongFormLinter, fileOptionsGoPackageSameInDirLinter, fileOptionsJavaMultipleFilesSameInDirLinter, fileOptionsJavaPackageSameInDirLinter, fileOptionsRequireGoPackageLinter, fileOptionsRequireJavaMultipleFilesLinter, fileOptionsRequireJavaOuterClassnameLinter, fileOptionsRequireJavaPackageLinter, messageFieldNamesLowerSnakeCaseLinter, messageNamesCamelCaseLinter, messageNamesCapitalizedLinter, oneofNamesLowerSnakeCaseLinter, packageIsDeclaredLinter, packageLowerSnakeCaseLinter, packagesSameInDirLinter, rpcNamesCamelCaseLinter, rpcNamesCapitalizedLinter, requestResponseTypesInSameFileLinter, requestResponseTypesUniqueLinter, serviceNamesCamelCaseLinter, serviceNamesCapitalizedLinter, syntaxProto3Linter, wktDirectlyImportedLinter, } // Uber2Linters is the slice of linters for the uber2 lint group. Uber2Linters = []Linter{ commentsNoCStyleLinter, commentsNoInlineLinter, enumFieldNamesUpperSnakeCaseLinter, enumFieldPrefixesExceptMessageLinter, enumNamesCamelCaseLinter, enumNamesCapitalizedLinter, enumZeroValuesInvalidExceptMessageLinter, enumsHaveSentenceCommentsLinter, enumsNoAllowAliasLinter, fieldsNotReservedLinter, fileHeaderLinter, fileNamesLowerSnakeCaseLinter, fileOptionsCSharpNamespaceSameInDirLinter, fileOptionsEqualCSharpNamespaceCapitalizedLinter, fileOptionsEqualGoPackageV2SuffixLinter, fileOptionsEqualJavaMultipleFilesTrueLinter, fileOptionsEqualJavaOuterClassnameProtoSuffixLinter, fileOptionsEqualJavaPackagePrefixLinter, fileOptionsEqualOBJCClassPrefixAbbrLinter, fileOptionsEqualPHPNamespaceCapitalizedLinter, fileOptionsGoPackageNotLongFormLinter, fileOptionsGoPackageSameInDirLinter, fileOptionsJavaMultipleFilesSameInDirLinter, fileOptionsJavaPackageSameInDirLinter, fileOptionsOBJCClassPrefixSameInDirLinter, fileOptionsPHPNamespaceSameInDirLinter, fileOptionsRequireCSharpNamespaceLinter, fileOptionsRequireGoPackageLinter, fileOptionsRequireJavaMultipleFilesLinter, fileOptionsRequireJavaOuterClassnameLinter, fileOptionsRequireJavaPackageLinter, fileOptionsRequireOBJCClassPrefixLinter, fileOptionsRequirePHPNamespaceLinter, importsNotPublicLinter, importsNotWeakLinter, messagesHaveSentenceCommentsExceptRequestResponseTypesLinter, messageFieldNamesFilenameLinter, messageFieldNamesFilepathLinter, messageFieldNamesLowerSnakeCaseLinter, messageFieldNamesNoDescriptorLinter, messageFieldsNoJSONNameLinter, messageNamesCamelCaseLinter, messageNamesCapitalizedLinter, namesNoCommonLinter, namesNoDataLinter, namesNoUUIDLinter, oneofNamesLowerSnakeCaseLinter, packageIsDeclaredLinter, packageLowerCaseLinter, packageMajorBetaVersionedLinter, packageNoKeywordsLinter, packagesSameInDirLinter, rpcsHaveSentenceCommentsLinter, rpcNamesCamelCaseLinter, rpcNamesCapitalizedLinter, requestResponseNamesMatchRPCLinter, requestResponseTypesAfterServiceLinter, requestResponseTypesInSameFileLinter, requestResponseTypesOnlyInFileLinter, requestResponseTypesUniqueLinter, servicesHaveSentenceCommentsLinter, serviceNamesAPISuffixLinter, serviceNamesCamelCaseLinter, serviceNamesCapitalizedLinter, serviceNamesMatchFileNameLinter, syntaxProto3Linter, wktDirectlyImportedLinter, wktDurationSuffixLinter, wktTimestampSuffixLinter, } // EmptyLinters is the slice of linters for the empty lint group. EmptyLinters = []Linter{} // GroupToLinters is the map from linter group to the corresponding slice of linters. GroupToLinters = map[string][]Linter{ "google": GoogleLinters, "uber1": Uber1Linters, "uber2": Uber2Linters, "empty": EmptyLinters, } )
Functions ¶
func CheckMultiple ¶
func CheckMultiple(linters []Linter, dirPathToDescriptors map[string][]*FileDescriptor, 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, absolutePaths bool) (map[string][]*FileDescriptor, error)
GetDirPathToDescriptors is a convenience function that gets the descriptors for the given ProtoSet.
Absolute paths are printed for failures if absolutePaths is true.
Types ¶
type FileDescriptor ¶
FileDescriptor is a wrapper for proto.Proto.
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(config settings.LintConfig) string // Check the file data for the descriptors in a common directory. // 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 []*FileDescriptor) ([]*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 group, if set, is expected to be lower-case.
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, []*FileDescriptor) 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.
func NewSuppressableLinter ¶
func NewSuppressableLinter(id string, purpose string, suppressableAnnotation string, addCheck func(func(*file.ProtoSet, *proto.Comment, *text.Failure), string, []*FileDescriptor) error) Linter
NewSuppressableLinter is a convenience function that returns a new Linter for the given parameters, using a function to record failures. This linter can be suppressed given the annotation.
The ID will be upper-cased.
Failures returned from check do not need to set the ID, this will be overwritten.
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().
Source Files ¶
- base_linter.go
- base_visitor.go
- check_comments_no_c_style.go
- check_comments_no_inline.go
- check_enum_field_names_upper_snake_case.go
- check_enum_field_names_uppercase.go
- check_enum_field_prefixes.go
- check_enum_field_prefixes_except_message.go
- check_enum_fields_have_comments.go
- check_enum_fields_have_sentence_comments.go
- check_enum_names_camel_case.go
- check_enum_names_capitalized.go
- check_enum_zero_values_invalid.go
- check_enum_zero_values_invalid_except_message.go
- check_enums_have_comments.go
- check_enums_have_sentence_comments.go
- check_enums_no_allow_alias.go
- check_fields_not_reserved.go
- check_file_header.go
- check_file_names_lower_snake_case.go
- check_file_options_equal.go
- check_file_options_required.go
- check_file_options_same_in_dir.go
- check_file_options_unset.go
- check_go_package_not_long_form.go
- check_gogo_not_imported.go
- check_imports_not_public.go
- check_imports_not_weak.go
- check_message_field_names_filename.go
- check_message_field_names_filepath.go
- check_message_field_names_lower_snake_case.go
- check_message_field_names_lowercase.go
- check_message_field_names_no_descriptor.go
- check_message_fields_duration.go
- check_message_fields_have_comments.go
- check_message_fields_have_sentence_comments.go
- check_message_fields_no_json_name.go
- check_message_fields_not_floats.go
- check_message_fields_time.go
- check_message_names_camel_case.go
- check_message_names_capitalized.go
- check_messages_have_comments.go
- check_messages_have_comments_except_request_response_types.go
- check_messages_have_sentence_comments_except_request_response_types.go
- check_messages_not_empty_except_request_response_types.go
- check_names.go
- check_oneof_names_lower_snake_case.go
- check_package_is_declared.go
- check_package_lower_case.go
- check_package_lower_snake_case.go
- check_package_major_beta_versioned.go
- check_package_no_keywords.go
- check_packages_same_in_dir.go
- check_request_response_names_match_rpc.go
- check_request_response_types_after_service.go
- check_request_response_types_in_same_file.go
- check_request_response_types_only_in_file.go
- check_request_response_types_unique.go
- check_rpc_names_camel_case.go
- check_rpc_names_capitalized.go
- check_rpc_options_no_google_api_http.go
- check_rpcs_have_comments.go
- check_rpcs_have_sentence_comments.go
- check_rpcs_no_streaming.go
- check_service_names_api_suffix.go
- check_service_names_camel_case.go
- check_service_names_capitalized.go
- check_service_names_match_file_name.go
- check_service_names_singular.go
- check_services_have_comments.go
- check_services_have_sentence_comments.go
- check_syntax_proto3.go
- check_wkt_directly_imported.go
- check_wkt_duration_suffix.go
- check_wkt_timestamp_suffix.go
- lint.go
- runner.go