Repository: uber/prototool
Pull request #292 (2019-01-11 17:32:22)

Make MESSAGE_FIELDS_NOT_FLOATS only fail on floats and not doubles
Per internal discussion

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

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

```diff
@@           Coverage Diff           @@
##              dev     #292   +/-   ##
=======================================
  Coverage   72.51%   72.51%           
=======================================
  Files         124      124           
  Lines        5639     5639           
=======================================
  Hits         4089     4089           
  Misses       1163     1163           
  Partials      387      387
```


| [Impacted Files](https://codecov.io/gh/uber/prototool/pull/292?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [internal/lint/check\_message\_fields\_not\_floats.go](https://codecov.io/gh/uber/prototool/pull/292/diff?src=pr&el=tree#diff-aW50ZXJuYWwvbGludC9jaGVja19tZXNzYWdlX2ZpZWxkc19ub3RfZmxvYXRzLmdv) | `90% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/uber/prototool/pull/292?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/292?src=pr&el=footer). Last update [fb93ac4...d9b7cf0](https://codecov.io/gh/uber/prototool/pull/292?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/internal/lint/check_message_fields_not_floats.go b/internal/lint/check_message_fields_not_floats.go
index 787ae5f..0927aaf 100644
--- a/internal/lint/check_message_fields_not_floats.go
+++ b/internal/lint/check_message_fields_not_floats.go
@@ -31,7 +31,7 @@ const messageFieldsNotFloatsSuppressableAnnotation = "floats"
 
 var messageFieldsNotFloatsLinter = NewLinter(
 	"MESSAGE_FIELDS_NOT_FLOATS",
-	fmt.Sprintf(`Suppressable with "@suppresswarnings %s". Verifies that all message fields are not floats or doubles.`, messageFieldsNotFloatsSuppressableAnnotation),
+	fmt.Sprintf(`Suppressable with "@suppresswarnings %s". Verifies that all message fields are not floats.`, messageFieldsNotFloatsSuppressableAnnotation),
 	checkMessageFieldsNotFloats,
 )
 
@@ -69,10 +69,10 @@ func (v messageFieldsNotFloatsVisitor) VisitMapField(field *proto.MapField) {
 
 func (v messageFieldsNotFloatsVisitor) checkNotFloat(field *proto.Field) {
 	switch field.Type {
-	case "double", "float":
+	case "float":
 		if isSuppressed(field.Comment, messageFieldsNotFloatsSuppressableAnnotation) {
 			return
 		}
-		v.AddFailuref(field.Position, `Field %q is a float and floating point types should generally not be used, consider using an int64 while representing your value in micros or nanos. This can be suppressed by adding "@suppresswarnings %s" to the field comment.`, field.Name, messageFieldsNotFloatsSuppressableAnnotation)
+		v.AddFailuref(field.Position, `Field %q is a float and floats should generally not be used, consider using a double, or an int64 while representing your value in micros or nanos. This can be suppressed by adding "@suppresswarnings %s" to the field comment.`, field.Name, messageFieldsNotFloatsSuppressableAnnotation)
 	}
 }


Test patch:
diff --git a/internal/cmd/testdata/lint/floats/foo/v1/foo.proto b/internal/cmd/testdata/lint/floats/foo/v1/foo.proto
index 702a515..0b3852f 100644
--- a/internal/cmd/testdata/lint/floats/foo/v1/foo.proto
+++ b/internal/cmd/testdata/lint/floats/foo/v1/foo.proto
@@ -14,9 +14,10 @@ message One {
   // This is a field we are ok with having floats.
   //
   // @suppresswarnings floats
-  double one = 1;
+  float one = 1;
   // @suppresswarnings floats
   float two = 2;
-  double three = 3;
-  double four = 4;
+  float three = 3;
+  float four = 4;
+  double five = 5;
 }