Repository: uber/prototool
Pull request #336 (2019-02-12 19:53:34)

Allow google.protobuf.Timestamp field to be named time
This was an oversight - we meant to do this, but didn't actually adjust the code. This was already being done for `google.Protobuf.Duration`.

codecov-io: # [Codecov](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=h1) Report
> Merging [#336](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=desc) into [dev](https://codecov.io/gh/uber/prototool/commit/ad3cc204076a1aa7ccb95c9f602147a65f8d0ae5?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/uber/prototool/pull/336/graphs/tree.svg?width=650&token=A9V0DApqZg&height=150&src=pr)](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##              dev     #336   +/-   ##
=======================================
  Coverage   73.52%   73.52%           
=======================================
  Files         145      145           
  Lines        6379     6379           
=======================================
  Hits         4690     4690           
  Misses       1261     1261           
  Partials      428      428
```


| [Impacted Files](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/lint/check\_wkt\_timestamp\_suffix.go](https://codecov.io/gh/uber/prototool/pull/336/diff?src=pr&el=tree#diff-aW50ZXJuYWwvbGludC9jaGVja193a3RfdGltZXN0YW1wX3N1ZmZpeC5nbw==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=footer). Last update [ad3cc20...a07ae11](https://codecov.io/gh/uber/prototool/pull/336?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/lint/check_wkt_timestamp_suffix.go b/internal/lint/check_wkt_timestamp_suffix.go
index c9a0d2a..7089ebb 100644
--- a/internal/lint/check_wkt_timestamp_suffix.go
+++ b/internal/lint/check_wkt_timestamp_suffix.go
@@ -62,7 +62,7 @@ func (v wktTimestampSuffixVisitor) VisitOneofField(field *proto.OneOfField) {
 }
 
 func (v wktTimestampSuffixVisitor) visitField(field *proto.Field) {
-	if field.Type == "google.protobuf.Timestamp" && !strings.HasSuffix(field.Name, "_time") {
-		v.AddFailuref(field.Position, `Field %q of type "google.protobuf.Timestamp" must end in "_time".`, field.Name)
+	if field.Type == "google.protobuf.Timestamp" && !(field.Name == "time" || strings.HasSuffix(field.Name, "_time")) {
+		v.AddFailuref(field.Position, `Field %q of type "google.protobuf.Timestamp" must be "time" or end in "_time".`, field.Name)
 	}
 }


Test patch:
diff --git a/internal/cmd/testdata/lint/wktsuffix/foo/foo.proto b/internal/cmd/testdata/lint/wktsuffix/foo/foo.proto
index 77886b6..fdd9c79 100644
--- a/internal/cmd/testdata/lint/wktsuffix/foo/foo.proto
+++ b/internal/cmd/testdata/lint/wktsuffix/foo/foo.proto
@@ -17,4 +17,6 @@ message Bar {
     google.protobuf.Timestamp three = 3;
     google.protobuf.Duration four = 4;
   }
+  // Make sure this is allowed.
+  google.protobuf.Timestamp time = 5;
 }