github.com/googleapis/api-linter@v1.65.2/docs/rules/0191/file-option-consistency.md (about) 1 --- 2 rule: 3 aip: 191 4 name: [core, '0191', file-option-consistency] 5 summary: All proto files must set file packaging options consistently. 6 permalink: /191/file-option-consistency 7 redirect_from: 8 - /0191/file-option-consistency 9 --- 10 11 # File option consistency 12 13 This rule enforces that every proto file for a public API surface sets file 14 packaging options consistently, as mandated in [AIP-191][]. 15 16 ## Details 17 18 This rule looks at each proto file, and reads any files that it imports that 19 are in the same proto package. It iterates over the file packaging options in 20 each one and complains if they are inconsistent. 21 22 The following annotations are included: 23 24 - `csharp_namespace` 25 - `go_package` 26 - `java_multiple_files` 27 - `java_package` 28 - `php_class_prefix` 29 - `php_metadata_namespace` 30 - `php_namespace` 31 - `objc_class_prefix` 32 - `ruby_package` 33 - `swift_prefix` 34 35 ## Examples 36 37 **Incorrect** code for this rule: 38 39 In `foo.proto`: 40 41 ```proto 42 // Incorrect. 43 syntax = "proto3"; 44 45 package google.example.v1; 46 47 option csharp_namespace = "Google\\Example\\V1"; 48 option ruby_namespace = "Google::Example::V1"; 49 ``` 50 51 In `bar.proto`: 52 53 ```proto 54 // Incorrect. 55 syntax = "proto3"; 56 57 package google.example.v1; 58 59 import "foo.proto"; 60 61 option csharp_namespace = "Example\\V1"; // Inconsistent. 62 // option ruby_namespace is missing, which is also inconsistent. 63 ``` 64 65 **Correct** code for this rule: 66 67 In `foo.proto`: 68 69 ```proto 70 // Correct. 71 syntax = "proto3"; 72 73 package google.example.v1; 74 75 option csharp_namespace = "Google\\Example\\V1"; 76 option ruby_namespace = "Google::Example::V1"; 77 ``` 78 79 In `bar.proto`: 80 81 ```proto 82 // Correct. 83 syntax = "proto3"; 84 85 package google.example.v1; 86 87 import "foo.proto"; 88 89 option csharp_namespace = "Google\\Example\\V1"; 90 option ruby_namespace = "Google::Example::V1"; 91 ``` 92 93 ## Disabling 94 95 If you need to violate this rule, use a comment at the top of the file. 96 Remember to also include an [aip.dev/not-precedent][] comment explaining why. 97 98 ```proto 99 // (-- api-linter: core::0191::file-option-consistency=disabled 100 // aip.dev/not-precedent: We need to do this because reasons. --) 101 syntax = "proto3"; 102 103 package google.example.v1; 104 105 import "foo.proto"; 106 107 option csharp_namespace = "Example\\V1"; 108 ``` 109 110 [aip-191]: https://aip.dev/191 111 [aip.dev/not-precedent]: https://aip.dev/not-precedent