-
Notifications
You must be signed in to change notification settings - Fork 400
Begin adding Flow annotations #2196
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
Conversation
@tofumatt thanks for the thorough review. I expanded the docs to help clarify everything and addressed each issue. Can you take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about those single pipes in the type declarations and the filenames... mostly the rest of the stuff is r+wc types of things. This is looking great, I'm definitely getting more comfortable with the syntax and the comments/docs looks great.
|
||
Here is our Flow manifesto: | ||
|
||
* We use Flow to **declare the intention of our code** and help others |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs are really awesome now, thanks so much for doing another pass. Super easy to grok and the links are great 👍
README.md
Outdated
'Inexact type is incompatible with exact type' but that's a | ||
[bug](https://github.com/facebook/flow/issues/2405). | ||
You can use the `Exact<T>` workaround from | ||
[`src/core/types/coreTypes`](https://github.com/mozilla/addons-frontend/blob/master/src/core/types/coreTypes.js) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we call the file coreTypes
when it's already in the types/
dir? I think I at least meant to ask but forgot or it got buried. Seems redundant though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I did change the name but I forgot to update this link! Fixed.
README.md
Outdated
into a bug or if you hit something that's making you bang your head on | ||
the keyboard. If it's something you think is unfixable then use | ||
`$FLOW_IGNORE` instead. Please explain your rationale in the comment and link | ||
to a github issue if possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick but GitHub is a proper noun.
"dev:disco": "better-npm-run dev:disco", | ||
"eslint": "eslint .", | ||
"flow:check": "flow check", | ||
"flow:dev": "chokidar .flowconfig flow/ src/ tests/ -i flow/logs/flow.log -c 'flow status' --initial", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forget, is this safe to run if you don't have chokidar
installed globally? I'm rusty on my npm run
command knowledge. Maybe it's okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's safe. "In addition to the shell's pre-existing PATH, npm run adds node_modules/.bin
to the PATH provided to scripts."
src/amo/api/index.js
Outdated
return new Promise( | ||
(resolve) => { | ||
const data = { rating, version: versionId, body, title }; | ||
const data = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick but postData
, ratingData
, or reviewData
might be a bit less generic. data
is a vague variable name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I changed it. However, I feel like a short and concise variable name makes code easier to understand when it only spans 10 lines or so. Otherwise the verbosity can slow a reader down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, naming it review
instead achieves the same conciseness that data
provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, I didn't even consider that, oops 😲
src/core/api/index.js
Outdated
} | ||
|
||
type CallApiParams = {| | ||
endpoint: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be nice to alphabetise I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did another sweep and I think all param lists should be alphabetized now
src/core/types/addonTypes.js
Outdated
|}; | ||
|
||
export type AddonTypeProp = | ||
typeof ADDON_TYPE_DICT | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look like they should be ||
OR
s not bitwise OR
s, as I assume we want string
here not 0
. Odd that the type being 0
didn't mess stuff up somewhere...
review_url: string, | ||
slug: string, | ||
status: 'beta' | ||
| 'lite' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see single pipes being used here too. I know the pipes can surround the object syntax and it's something special in Flow. But are they also used as regular OR
in Flow? What would a double pipe here do? Normally I'm used to catching bitwise OR
operators as typos so they set off alarm bells in my head. 😖
src/core/types/coreTypes.js
Outdated
@@ -0,0 +1,6 @@ | |||
/* @flow */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for wanting types
in the folder and filename?
src/core/types/reduxTypes.js
Outdated
// It may be possible to use an official library for this. | ||
// See: https://github.com/reactjs/react-redux/pull/389 | ||
// and: https://github.com/reactjs/redux/pull/1887/files#diff-46d86d39c8da613247f843ee8ca43ebc | ||
export type DispatchFn = (action: Object) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be changed to DispatchFunc
like other function type names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added my comment about bitwise pipes.
GitHub was having me comment on old code so my thoughts on filenames are no longer a thing.
A few things needing cleaning up but I'm mostly wondering about the single pipes in src/core/types/addons.js
.
review_url: string, | ||
slug: string, | ||
status: 'beta' | ||
| 'lite' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These look like they should be ||
OR
s not bitwise OR
s. Odd that this resulting in 0
didn't mess stuff up somewhere...
Are they also used as regular OR
in Flow? What would a double pipe here do? Normally I'm used to catching bitwise OR
operators as typos so they set off alarm bells in my head. 😖
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a Union type so I think it's correct but, huh, maybe there is a bug here because it's not protecting me from referencing an invalid status
value (which is what I intended). Well, at the very least it's good documentation and when the bug is fixed it will produce errors.
@tofumatt thanks, this helped me dig into a few more issues. It should be ready for another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for dealing with my constant nitpicks and for doing all this work. Let's hope Flow helps us bash our heads on keyboards less! 👍 😆 🎉
Fixes mozilla/addons#10241
I have entered into the valley of darkness [1] to seek out the Light of Truth. Who will walk with me?
I started by annotating one component (I swear). I tried to follow its dependencies and annotate each one but I didn't finish because we have so much shared logic. I think this paints an interesting picture of what Flow can buy us.
Here are some observations:
Let me know what you think!
[1] during my 8-hour flight back from London to Chicago