Buf Guide - oppia/oppia-android GitHub Wiki
Table of Contents
Installation
Once you have completed all the installation steps, you will have a buf file in your opensource/oppia-android-tools folder.
Note: Currently, Buf is not available for windows.
Commands
- Check the version of the buf. As of now on GitHub Actions, we are using
0.37.1.../oppia-android-tools/YOUR_BUF_FILE_NAME --version - Lint check
buf lint --config buf.yaml
Configuration File
We have a configuration file buf.yaml at the root of the project. Following is the list of things we are checking and the list of things we are excluding from our check.
Checking:
-
DIRECTORY_SAME_PACKAGEchecks that all files in a given directory are in the same package.- All proto files should be in the same package
-
PACKAGE_SAME_DIRECTORYchecks that all files with a given package are in the same directory.- All proto files with the same package name should be in the same directory
-
PACKAGE_SAME_JAVA_MULTIPLE_FILESchecks that all files with a given package have the same value for the java_multiple_files option.- All proto files should have the same value
option java_multiple_files = true;
- All proto files should have the same value
-
PACKAGE_SAME_JAVA_PACKAGEchecks that all files with a given package have the same value for the java_package option.- All proto files should have the same value
option java_package = "path.to.your.proto.directory";
- All proto files should have the same value
-
ENUM_NO_ALLOW_ALIASchecks that enums do not have the allow_alias option set.- Should not allows multiple enum values to have the same number.
-
FIELD_NO_DESCRIPTORchecks that field names are not named capitalization of "descriptor" with any number of prefix or suffix underscores.- No
descriptorfield name should be there, example -descriptor,Descriptor,descRiptor,_descriptor,descriptor_,__descriptor__
- No
-
IMPORT_NO_PUBLICchecks that imports are not public.- Import should not be declared as
public, example -import public "x.y.proto"
- Import should not be declared as
-
IMPORT_NO_WEAKchecks that imports are not weak.- Import should not be declared as
weak, example -import weak "x.y.proto"
- Import should not be declared as
-
PACKAGE_DEFINEDchecks that all files have a package defined.- All proto files must have a package name specify in it, for example -
package model;
- All proto files must have a package name specify in it, for example -
-
ENUM_PASCAL_CASEchecks that enums are PascalCase.- Enum name should be in pascal case, example -
AudioLanguage
- Enum name should be in pascal case, example -
-
ENUM_VALUE_UPPER_SNAKE_CASEchecks that enum values are UPPER_SNAKE_CASE.- Enum value should be in upper snake case
-
FIELD_LOWER_SNAKE_CASEchecks that field names are lower_snake_case.- Field name should be in lower snake case
-
MESSAGE_PASCAL_CASEchecks that messages are PascalCase.- Message should be in Pascal case, example -
ProfileAvatar
- Message should be in Pascal case, example -
-
ONEOF_LOWER_SNAKE_CASEchecks that oneof names are lower_snake_case.- Oneof should be a lower snake case
-
PACKAGE_LOWER_SNAKE_CASEchecks that packages are lower_snake.case.- Package should be lower snake case, example -
model
- Package should be lower snake case, example -
-
ENUM_ZERO_VALUE_SUFFIXchecks that enum zero values are suffixed with_UNSPECIFIED(the suffix is configurable).- All the enum whose value is zero should be suffixed with
_UNSPECIFIED, example -AUDIO_LANGUAGE_UNSPECIFIED = 0;
- All the enum whose value is zero should be suffixed with
-
FILE_LOWER_SNAKE_CASEchecks that filenames are lower_snake_case.- All the proto file names are should be in lower snake case, for example -
topic.proto
- All the proto file names are should be in lower snake case, for example -
Excluding:
-
PACKAGE_DIRECTORY_MATCHchecks that all files are in a directory that matches their package name.- this verifies that all files that declare a given package foo.bar.baz.v1 is in the directory foo/bar/baz/v1 relative to the root
-
ENUM_VALUE_PREFIXchecks that enum values are prefixed withENUM_NAME_UPPER_SNAKE_CASE.enum Foo { FOO_ONE = 0; }
-
PACKAGE_VERSION_SUFFIXchecks that the last component of all packages is a version of the form v\d+, v\d+test.*, v\d+(alpha|beta)\d+, or v\d+p\d+(alpha|beta)\d+, where numbers are >=1.foo.v1,foo.bar.v1alpha1,foo.bar.v1beta1,foo.bar.v1test