Repository: uber/prototool
Pull request #274 (2019-01-08 16:58:34)

Add uber2 lint group
This is for our V2 style guide. Since we are still on dev, we can still edit it. This is desired now so that we can stop copy/pasting lint rules between test `prototool.yaml` files. Documentation will be added once complete.


Patch:
diff --git a/internal/lint/lint.go b/internal/lint/lint.go
index 37fae0c..9f35c89 100644
--- a/internal/lint/lint.go
+++ b/internal/lint/lint.go
@@ -146,10 +146,56 @@ var (
 		wktDirectlyImportedLinter,
 	}
 
+	// Uber2Linters is the slice of linters for the uber2 lint group.
+	Uber2Linters = []Linter{
+		commentsNoCStyleLinter,
+		enumFieldNamesUpperSnakeCaseLinter,
+		enumFieldPrefixesExceptMessageLinter,
+		enumNamesCamelCaseLinter,
+		enumNamesCapitalizedLinter,
+		enumZeroValuesInvalidExceptMessageLinter,
+		enumsNoAllowAliasLinter,
+		fieldsNotReservedLinter,
+		fileOptionsEqualGoPackageLastTwoSuffixLinter,
+		fileOptionsEqualJavaMultipleFilesTrueLinter,
+		fileOptionsEqualJavaOuterClassnameProtoSuffixLinter,
+		fileOptionsEqualJavaPackageComPrefixLinter,
+		fileOptionsGoPackageNotLongFormLinter,
+		fileOptionsGoPackageSameInDirLinter,
+		fileOptionsJavaMultipleFilesSameInDirLinter,
+		fileOptionsJavaPackageSameInDirLinter,
+		fileOptionsRequireGoPackageLinter,
+		fileOptionsRequireJavaMultipleFilesLinter,
+		fileOptionsRequireJavaOuterClassnameLinter,
+		fileOptionsRequireJavaPackageLinter,
+		gogoNotImportedLinter,
+		importsNotPublicLinter,
+		importsNotWeakLinter,
+		messageFieldNamesLowerSnakeCaseLinter,
+		messageFieldsNoJSONNameLinter,
+		messageNamesCamelCaseLinter,
+		messageNamesCapitalizedLinter,
+		oneofNamesLowerSnakeCaseLinter,
+		packageIsDeclaredLinter,
+		packageLowerSnakeCaseLinter,
+		packageMajorBetaVersionedLinter,
+		packagesSameInDirLinter,
+		rpcNamesCamelCaseLinter,
+		rpcNamesCapitalizedLinter,
+		requestResponseNamesMatchRPCLinter,
+		requestResponseTypesInSameFileLinter,
+		requestResponseTypesUniqueLinter,
+		serviceNamesCamelCaseLinter,
+		serviceNamesCapitalizedLinter,
+		syntaxProto3Linter,
+		wktDirectlyImportedLinter,
+	}
+
 	// GroupToLinters is the map from linter group to the corresponding slice of linters.
 	GroupToLinters = map[string][]Linter{
 		"google": GoogleLinters,
 		"uber":   UberLinters,
+		"uber2":  Uber2Linters,
 	}
 )
 
diff --git a/internal/reflect/proto/prototool.yaml b/internal/reflect/proto/prototool.yaml
index d768f32..9e10021 100644
--- a/internal/reflect/proto/prototool.yaml
+++ b/internal/reflect/proto/prototool.yaml
@@ -1,25 +1,7 @@
 protoc:
   version: 3.6.1
 lint:
-  rules:
-    add:
-      - ENUM_FIELD_PREFIXES_EXCEPT_MESSAGE
-      - ENUM_ZERO_VALUES_INVALID_EXCEPT_MESSAGE
-      - ENUMS_HAVE_COMMENTS
-      - FIELDS_NOT_RESERVED
-      - FILE_OPTIONS_EQUAL_GO_PACKAGE_LAST_TWO_SUFFIX
-      - GOGO_NOT_IMPORTED
-      - IMPORTS_NOT_PUBLIC
-      - IMPORTS_NOT_WEAK
-      - MESSAGE_FIELDS_NO_JSON_NAME
-      - MESSAGES_HAVE_COMMENTS_EXCEPT_REQUEST_RESPONSE_TYPES
-      - PACKAGE_MAJOR_BETA_VERSIONED
-      - REQUEST_RESPONSE_NAMES_MATCH_RPC
-      - RPCS_HAVE_COMMENTS
-    remove:
-      - ENUM_FIELD_PREFIXES
-      - ENUM_ZERO_VALUES_INVALID
-      - FILE_OPTIONS_EQUAL_GO_PACKAGE_PB_SUFFIX
+  group: uber2
 generate:
   go_options:
     import_path: github.com/uber/prototool/internal/reflect/proto


Test patch:
diff --git a/internal/cmd/cmd_test.go b/internal/cmd/cmd_test.go
index 39da084..865d602 100644
--- a/internal/cmd/cmd_test.go
+++ b/internal/cmd/cmd_test.go
@@ -751,12 +751,13 @@ func TestListAllLinters(t *testing.T) {
 }
 
 func TestListAllLintGroups(t *testing.T) {
-	assertExact(t, 0, "google\nuber", "lint", "--list-all-lint-groups")
+	assertExact(t, 0, "google\nuber\nuber2", "lint", "--list-all-lint-groups")
 }
 
 func TestListLintGroup(t *testing.T) {
 	assertLinters(t, lint.GoogleLinters, "lint", "--list-lint-group", "google")
 	assertLinters(t, lint.UberLinters, "lint", "--list-lint-group", "uber")
+	assertLinters(t, lint.Uber2Linters, "lint", "--list-lint-group", "uber2")
 }
 
 func assertLinters(t *testing.T, linters []lint.Linter, args ...string) {
diff --git a/internal/cmd/testdata/lint/version2/prototool.yaml b/internal/cmd/testdata/lint/version2/prototool.yaml
index a095bc0..092dbf5 100644
--- a/internal/cmd/testdata/lint/version2/prototool.yaml
+++ b/internal/cmd/testdata/lint/version2/prototool.yaml
@@ -1,20 +1,2 @@
 lint:
-  rules:
-    add:
-      - ENUM_FIELD_PREFIXES_EXCEPT_MESSAGE
-      - ENUM_ZERO_VALUES_INVALID_EXCEPT_MESSAGE
-      - ENUMS_HAVE_COMMENTS
-      - FIELDS_NOT_RESERVED
-      - FILE_OPTIONS_EQUAL_GO_PACKAGE_LAST_TWO_SUFFIX
-      - GOGO_NOT_IMPORTED
-      - IMPORTS_NOT_PUBLIC
-      - IMPORTS_NOT_WEAK
-      - MESSAGE_FIELDS_NO_JSON_NAME
-      - MESSAGES_HAVE_COMMENTS_EXCEPT_REQUEST_RESPONSE_TYPES
-      - PACKAGE_MAJOR_BETA_VERSIONED
-      - REQUEST_RESPONSE_NAMES_MATCH_RPC
-      - RPCS_HAVE_COMMENTS
-    remove:
-      - ENUM_FIELD_PREFIXES
-      - ENUM_ZERO_VALUES_INVALID
-      - FILE_OPTIONS_EQUAL_GO_PACKAGE_PB_SUFFIX
+  group: uber2
diff --git a/internal/cmd/testdata/reflect/one/prototool.yaml b/internal/cmd/testdata/reflect/one/prototool.yaml
index a41c2bd..092dbf5 100644
--- a/internal/cmd/testdata/reflect/one/prototool.yaml
+++ b/internal/cmd/testdata/reflect/one/prototool.yaml
@@ -1,14 +1,2 @@
 lint:
-  rules:
-    add:
-      - ENUM_FIELD_PREFIXES_EXCEPT_MESSAGE
-      - ENUM_ZERO_VALUES_INVALID_EXCEPT_MESSAGE
-      - FILE_OPTIONS_EQUAL_GO_PACKAGE_LAST_TWO_SUFFIX
-      - GOGO_NOT_IMPORTED
-      - MESSAGE_FIELDS_NO_JSON_NAME
-      - PACKAGE_MAJOR_BETA_VERSIONED
-      - REQUEST_RESPONSE_NAMES_MATCH_RPC
-    remove:
-      - ENUM_FIELD_PREFIXES
-      - ENUM_ZERO_VALUES_INVALID
-      - FILE_OPTIONS_EQUAL_GO_PACKAGE_PB_SUFFIX
+  group: uber2