diff options
author | James Fargher <jfargher@gitlab.com> | 2022-04-06 02:06:40 +0300 |
---|---|---|
committer | James Fargher <jfargher@gitlab.com> | 2022-04-29 02:14:24 +0300 |
commit | 317c59fc930dee8ce68d39cb798460b760bde46b (patch) | |
tree | 99d44a96fe50fd172748e908fb92b577197c0cfe | |
parent | fce0a7487ccf90a866bf6a2428b23b428cd67c5c (diff) |
Add protolint to Makefile
From https://github.com/yoheimuta/protolint this linter is configurable
and much more strict than protoc.
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | proto/.protolint.yaml | 32 |
2 files changed, 38 insertions, 1 deletions
@@ -49,6 +49,7 @@ GIT := $(shell command -v git) GOIMPORTS := ${TOOLS_DIR}/goimports GOFUMPT := ${TOOLS_DIR}/gofumpt GOLANGCI_LINT := ${TOOLS_DIR}/golangci-lint +PROTOLINT := ${TOOLS_DIR}/protolint GO_LICENSES := ${TOOLS_DIR}/go-licenses PROTOC := ${TOOLS_DIR}/protoc PROTOC_GEN_GO := ${TOOLS_DIR}/protoc-gen-go @@ -76,6 +77,7 @@ endif # Dependency versions GOLANGCI_LINT_VERSION ?= 1.44.2 +PROTOLINT_VERSION ?= 0.37.1 GOCOVER_COBERTURA_VERSION ?= aaee18c8195c3f2d90e5ef80ca918d265463842a GOFUMPT_VERSION ?= 0.3.1 GOIMPORTS_VERSION ?= 2538eef75904eff384a2551359968e40c207d9d2 @@ -452,8 +454,9 @@ proto: ${PROTOC} ${PROTOC_GEN_GO} ${PROTOC_GEN_GO_GRPC} ${SOURCE_DIR}/.ruby-bund check-proto: proto no-proto-changes lint-proto .PHONY: lint-proto -lint-proto: ${PROTOC} ${PROTOC_GEN_GITALY} +lint-proto: ${PROTOC} ${PROTOC_GEN_GITALY} ${PROTOLINT} ${Q}${PROTOC} --plugin=${PROTOC_GEN_GITALY} -I ${SOURCE_DIR}/proto -I ${PROTOC_INSTALL_DIR}/include --gitaly_out=proto_dir=${SOURCE_DIR}/proto,gitalypb_dir=${SOURCE_DIR}/proto/go/gitalypb:${SOURCE_DIR} ${SOURCE_DIR}/proto/*.proto + ${Q}${PROTOLINT} lint -config_dir_path=${SOURCE_DIR}/proto ${SOURCE_DIR}/proto .PHONY: no-changes no-changes: @@ -605,6 +608,8 @@ ${GOIMPORTS}: TOOL_PACKAGE = golang.org/x/tools/cmd/goimports ${GOIMPORTS}: TOOL_VERSION = ${GOIMPORTS_VERSION} ${GOLANGCI_LINT}: TOOL_PACKAGE = github.com/golangci/golangci-lint/cmd/golangci-lint ${GOLANGCI_LINT}: TOOL_VERSION = v${GOLANGCI_LINT_VERSION} +${PROTOLINT}: TOOL_PACKAGE = github.com/yoheimuta/protolint/cmd/protolint +${PROTOLINT}: TOOL_VERSION = v${PROTOLINT_VERSION} ${GOTESTSUM}: TOOL_PACKAGE = gotest.tools/gotestsum ${GOTESTSUM}: TOOL_VERSION = ${GOTESTSUM_VERSION} ${GO_LICENSES}: TOOL_PACKAGE = github.com/google/go-licenses diff --git a/proto/.protolint.yaml b/proto/.protolint.yaml new file mode 100644 index 000000000..995f81bb7 --- /dev/null +++ b/proto/.protolint.yaml @@ -0,0 +1,32 @@ +--- +lint: + rules: + all_default: true + remove: + # Our use of enums isn't conforming to best practices, and it's hard to + # change retroactively. We may eventually enable these linters and then + # create exceptions for preexisting definitions. + - ENUM_FIELD_NAMES_PREFIX + - ENUM_FIELD_NAMES_ZERO_VALUE_END_WITH + # We don't specify any line length limits. + - MAX_LINE_LENGTH + # Many of our definitions aren't commented at all. We want to eventually + # opt-in to enable these linting warnings, but right now we just want to + # get protolint included in our workflow with minimal required changes. + - FILE_HAS_COMMENT + - RPCS_HAVE_COMMENT + - FIELDS_HAVE_COMMENT + - SERVICES_HAVE_COMMENT + - MESSAGES_HAVE_COMMENT + - ENUMS_HAVE_COMMENT + - ENUM_FIELDS_HAVE_COMMENT + # Many of our fields and messages have prepositions in them, and + # furthermore this rule doesn't feel all that sensible after all. We thus + # disable it. + - FIELD_NAMES_EXCLUDE_PREPOSITIONS + - MESSAGE_NAMES_EXCLUDE_PREPOSITIONS + + rules_option: + file_names_lower_snake_case: + excludes: + - proto/repository-service.proto |