Skip to content

Commit

Permalink
flow: Upgrade to v0.127.
Browse files Browse the repository at this point in the history
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] #4433 (comment)
  • Loading branch information
chrisbobbe authored and gnprice committed Mar 10, 2021
1 parent 669899c commit 03e6bdf
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ module.file_ext=.json
module.file_ext=.ios.js

[version]
^0.126.0
^0.127.0
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-react-hooks": "^4.2.0",
"flow-bin": "^0.126.0",
"flow-bin": "^0.127.0",
"flow-coverage-report": "^0.6.0",
"flow-typed": "^2.4.0",
"immutable-devtools": "^0.1.5",
Expand Down
22 changes: 12 additions & 10 deletions src/autocomplete/PeopleAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,18 @@ class PeopleAutocomplete extends PureComponent<Props> {

return (
<Popup>
{/*
$FlowFixMe[incompatible-variance]
$FlowFixMe[prop-missing]
SectionList type is confused; should take $ReadOnly objects.
*/}
<SectionList
keyboardShouldPersistTaps="always"
initialNumToRender={10}
sections={sections}
/>
{/* eslint-disable-next-line react/jsx-curly-brace-presence */}
{
// $FlowFixMe[incompatible-variance]
/* $FlowFixMe[prop-missing]
SectionList type is confused; should take $ReadOnly
objects. */
<SectionList
keyboardShouldPersistTaps="always"
initialNumToRender={10}
sections={sections}
/>
}
</Popup>
);
}
Expand Down
9 changes: 7 additions & 2 deletions src/boot/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ export const cacheKeys: Array<$Keys<GlobalState>> = [
function dropCache(state: GlobalState): $Shape<GlobalState> {
const result: $Shape<GlobalState> = {};
storeKeys.forEach(key => {
/* $FlowFixMe[incompatible-type]: This is well-typed only because
it's the same `key` twice. */
// $FlowFixMe[incompatible-indexer]
// $FlowFixMe[incompatible-exact]
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-variance]
// $FlowFixMe[incompatible-type-arg]
/* $FlowFixMe[incompatible-type]
This is well-typed only because it's the same `key` twice. */
result[key] = state[key];
});
return result;
Expand Down
4 changes: 3 additions & 1 deletion src/compose/ComposeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ class ComposeMenu extends PureComponent<Props> {
return;
}

// $FlowFixMe[sketchy-null-bool]: Upstream API is unclear.
// $FlowFixMe[sketchy-null-string]
/* $FlowFixMe[sketchy-null-bool]
Upstream API is unclear. */
const error: string | null = response.error || null;
if (error !== null) {
showErrorAlert('Error', error);
Expand Down
6 changes: 4 additions & 2 deletions src/redux-persist-migrate/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ export function createMigrationImpl(
throw new Error('createMigration: bad arguments');
}
if (action.type === REHYDRATE) {
/* $FlowFixMe[incompatible-type]: this really is a lie
-- and kind of central to migration */
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-exact]
/* $FlowFixMe[incompatible-type]
this really is a lie -- and kind of central to migration */
const incomingState: State = action.payload;
const incomingVersion = parseInt(versionSelector(incomingState), 10);
if (Number.isNaN(incomingVersion)) {
Expand Down
5 changes: 3 additions & 2 deletions src/unread/UnreadCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export default function UnreadCards(props: Props) {
}

return (
/* $FlowFixMe[prop-missing]: SectionList libdef seems confused;
should take $ReadOnly objects. */
// $FlowFixMe[incompatible-type-arg]
/* $FlowFixMe[prop-missing]
SectionList libdef seems confused; should take $ReadOnly objects. */
<SectionList
stickySectionHeadersEnabled
initialNumToRender={20}
Expand Down
1 change: 1 addition & 0 deletions src/webview/js/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ const handleMessageEvent: MessageEventListener = e => {

inboundEvents.forEach((uevent: WebViewInboundEvent) => {
eventLogger.maybeCaptureInboundEvent(uevent);
// $FlowFixMe[incompatible-type]
// $FlowFixMe[prop-missing]
inboundEventHandlers[uevent.type](uevent);
});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5621,10 +5621,10 @@ flow-annotation-check@1.8.1:
glob "7.1.1"
load-pkg "^3.0.1"

flow-bin@^0.126.0:
version "0.126.1"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.126.1.tgz#2726595e1891dc35b379b5994627432df4ead52c"
integrity sha512-RI05x7rVzruRVJQN3M4vLEjZMwUHJKhGz9FmL8HN7WiSo66/131EyJS6Vo8PkKyM2pgT9GRWfGP/tXlqS54XUg==
flow-bin@^0.127.0:
version "0.127.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.127.0.tgz#0614cff4c1b783beef1feeb7108d536e09d77632"
integrity sha512-ywvCCdV4NJWzrqjFrMU5tAiVGyBiXjsJQ1+/kj8thXyX15V17x8BFvNwoAH97NrUU8T1HzmFBjLzWc0l2319qg==

flow-coverage-report@^0.6.0:
version "0.6.2"
Expand Down

0 comments on commit 03e6bdf

Please sign in to comment.