Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flow [nfc]: Mark specific rules that are being suppressed. #4433

Merged
merged 2 commits into from
Jan 27, 2021

Conversation

chrisbobbe
Copy link
Contributor

When we start using Flow v0.137+, along with React Native v0.64
(that's issue #4426), we'll be asked to specify what rule(s) we're
suppressing with each suppression comment. Conveniently, the
warnings will tell us the applicable rule(s) we need to write down.

So, having peeked ahead at the warnings seen in the RN 0.64.0-rc.2
world, get a head start on doing so. There will probably be more of
these (we haven't yet started enforcing the requirement now, so some
unmarked $FlowFixMes will naturally accumulate), but we might as
well get this chunk out of the way.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Will be glad to start using this feature. Comments below.

Comment on lines 86 to 87
// Upstream API is unclear.
// $FlowFixMe[sketchy-null-bool]
const error: string | null = response.error || null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to keep the explanatory text after the $FlowFixMe, so between the $FlowFixMe and the code it's about. That helps keep it clear what text is there to explain the fixme, and what's there to explain something else about the code.

In particular that will help us delete the explanatory text when we delete the fixme, because of either a Flow upgrade or an improvement in the types. Otherwise it'd be easy to pretty often leave it behind because the person deleting the fixme didn't fully understand the comment at that moment, and then there'd be a puzzling comment lingering there to confuse people.

When it's too long for one line, we can use a /* … */ comment, like in a few of our existing comments and in the docs at https://flow.org/en/docs/errors/ .

Comment on lines 346 to 350
// Store data through our own wrapper for AsyncStorage, in particular
// to get compression.
// $FlowFixMe: https://github.com/rt2zz/redux-persist/issues/823
// https://github.com/rt2zz/redux-persist/issues/823
// $FlowFixMe[incompatible-variance]
storage: ZulipAsyncStorage,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is another nice illustration of how it's helpful to keep the text explaining the fixme explicitly attached to the fixme. As is, it looks like this issue link is probably there to add more context on the "Store data through … compression" comment, rather than to explain the fixme.

@@ -14,7 +14,7 @@ import escape from 'lodash.escape';
* template`Hello $\!${&<world}` -> 'Hello $!&amp;&lt;world'
*/
export default (strings: string[], ...values: Array<string | number>) => {
// $FlowFixMe github.com/facebook/flow/issues/2616
// $FlowFixMe[prop-missing] github.com/facebook/flow/issues/2616
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separately: this change in Flow called my attention to a feature/convention that's long existed, and would be handy to use here!

$FlowIssue: for a type error that you suspect is an issue with Flow

https://flow.org/en/docs/errors/

No rush to do this at the same time as adding the error codes, but probably we should use $FlowIssue for at least the cases where we actually link to an issue in the Flow tracker 🙂

@chrisbobbe
Copy link
Contributor Author

Thanks for the review! Revision pushed.

Copy link
Member

@gnprice gnprice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the revision! Small comments below -- otherwise looks good.

Comment on lines 452 to 455
{/*
`MentionWarnings` should use a type-checked `connect`
$FlowFixMe[incompatible-use]
*/}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's one remaining comment that gets out of order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, indeed, thanks (and for the other one too).

Comment on lines 160 to 161
/* realm_ is URL | void, but complains of out-of-bounds access
$FlowFixMe[invalid-tuple-index] */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's another (I think the only other.)

Comment on lines 59 to +60
// Flow bug: https://github.com/facebook/flow/issues/6110
case (ZulipVersion.prototype: $FlowFixMe):
case (ZulipVersion.prototype: $FlowIssue):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit in commit message:

flow [nfc]: Better indicate flow bugs in a few suppressions.

Should read "Flow bugs".

When we start using Flow v0.137+, along with React Native v0.64
(that's issue zulip#4426), we'll be asked to specify what rule(s) we're
suppressing with each suppression comment. Conveniently, the
warnings will tell us the applicable rule(s) we need to write down.

So, having peeked ahead at the warnings seen in the RN 0.64.0-rc.2
world, get a head start on doing so. There will probably be more of
these (we haven't yet started enforcing the requirement now, so some
unmarked `$FlowFixMe`s will naturally accumulate), but we might as
well get this chunk out of the way.
@chrisbobbe chrisbobbe merged commit c0ffc37 into zulip:master Jan 27, 2021
@chrisbobbe
Copy link
Contributor Author

chrisbobbe commented Jan 27, 2021

Thanks for the review! Merged, after fixing those nits.

chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Mar 10, 2021
Like with the other Flow upgrades in this series, we're departing
from our usual practice of only upgrading Flow along with React
Native. But we seem to get away with this one -- it doesn't flag any
new errors in node_modules/react-native!

One highlight of this version in the changelog is "Standardized
error suppression syntax, added ability to suppress errors based on
error codes" [1]. We couldn't have taken this upgrade without first
removing our use of the `suppress_comment` option in our
.flowconfig [2].

One slightly annoying feature of the standardized syntax (still
present in v0.146, the latest) is that, when you put more than one
error-code-specific suppression in a multi-line comment, Flow will
ignore some of them. Neither the doc [3] nor the suppression-syntax
tests [4] suggest that multiple suppressions in one multi-line
comment is supported.

We'd been using multi-line comments to keep a suppression's
explanatory text (when it's too long for one line) between the
suppression and the code that it's about [5].

So, to keep doing that: work around by using single-line suppression
comments for all but the last error-code-specific suppression
(chosen arbitrarily), and use a multi-line comment for that last
one, squeezing the explanatory text in there.

Apparently this Flow version finds more to complain about at some of
our existing suppressions, so this workaround gets a good bit of
exercise, especially in src/boot/store.js.

[1] https://github.com/facebook/flow/blob/master/Changelog.md#01270
[2] https://flow.org/en/docs/config/options/#toc-suppress-comment-regex
[3] https://flow.org/en/docs/errors/
[4] https://github.com/facebook/flow/blob/v0.146.0/tests/error_codes/test.js
[5] zulip#4433 (comment)
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Mar 10, 2021
Like with the other Flow upgrades in this series, we're departing
from our usual practice of only upgrading Flow along with React
Native. But we seem to get away with this one -- it doesn't flag any
new errors in node_modules/react-native!

One highlight of this version in the changelog is "Standardized
error suppression syntax, added ability to suppress errors based on
error codes" [1]. We couldn't have taken this upgrade without first
removing our use of the `suppress_comment` option in our
.flowconfig [2].

One slightly annoying feature of the standardized syntax (still
present in v0.146, the latest) is that, when you put more than one
error-code-specific suppression in a multi-line comment, Flow will
ignore some of them. Neither the doc [3] nor the suppression-syntax
tests [4] suggest that multiple suppressions in one multi-line
comment is supported.

We'd been using multi-line comments to keep a suppression's
explanatory text (when it's too long for one line) between the
suppression and the code that it's about [5].

So, to keep doing that: work around by using single-line suppression
comments for all but the last error-code-specific suppression
(chosen arbitrarily), and use a multi-line comment for that last
one, squeezing the explanatory text in there.

Apparently this Flow version finds more to complain about at some of
our existing suppressions, so this workaround gets a good bit of
exercise, especially in src/boot/store.js.

[1] https://github.com/facebook/flow/blob/master/Changelog.md#01270
[2] https://flow.org/en/docs/config/options/#toc-suppress-comment-regex
[3] https://flow.org/en/docs/errors/
[4] https://github.com/facebook/flow/blob/v0.146.0/tests/error_codes/test.js
[5] zulip#4433 (comment)
chrisbobbe added a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 9, 2021
This is another round in the spirit of zulip#4433, to prepare for Flow
v0.132 and later; there's this in the changelog entry [1]:

> Added warnings against suppressions without error codes

As we noted there, we still haven't enforced that suppressions have
error codes, but at least we can clean up these ones that have crept
in.

[1] https://github.com/facebook/flow/blob/master/Changelog.md#01320
gnprice pushed a commit to chrisbobbe/zulip-mobile that referenced this pull request Jul 13, 2021
This is another round in the spirit of zulip#4433, to prepare for Flow
v0.132 and later; there's this in the changelog entry [1]:

> Added warnings against suppressions without error codes

As we noted there, we still haven't enforced that suppressions have
error codes, but at least we can clean up these ones that have crept
in.

[1] https://github.com/facebook/flow/blob/master/Changelog.md#01320
@chrisbobbe chrisbobbe mentioned this pull request Sep 8, 2021
@chrisbobbe chrisbobbe deleted the pr-mark-suppression-comments branch November 4, 2021 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants