Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
c3c0023
initial Flow setup
kumar303 Mar 25, 2017
36b18a8
ignore flow log
kumar303 Mar 25, 2017
e3869f3
more fixups
kumar303 Mar 25, 2017
a6d999f
moved logs
kumar303 Mar 25, 2017
bcabe90
fixed dedent
kumar303 Mar 25, 2017
776f86c
api fixes, dedent fix
kumar303 Mar 25, 2017
a011fcf
removed userId, fixed action callbacks
kumar303 Mar 25, 2017
b6664e1
better function defs
kumar303 Mar 25, 2017
8ea3b11
api actions, reducers, review actions
kumar303 Mar 25, 2017
560cc22
added flow strip types
kumar303 Mar 25, 2017
6d666b0
make a separate ErrorHandler type
kumar303 Mar 25, 2017
4db137d
fixing tests
kumar303 Mar 26, 2017
502543e
dedent comments
kumar303 Mar 26, 2017
1908d7f
fixed location tests
kumar303 Mar 26, 2017
83c7e87
fixed up more tests
kumar303 Mar 26, 2017
89cd739
fixed setReview problems
kumar303 Mar 26, 2017
ce4a39d
added missing api state types
kumar303 Mar 27, 2017
b935fd7
Add minimal typing to i18n/utils
kumar303 Mar 27, 2017
bd242ea
fix i18n optional keywords
kumar303 Mar 27, 2017
21e9c5b
type hint for the i18n config
kumar303 Mar 27, 2017
3f4d74e
fixed lint errors
kumar303 Mar 27, 2017
eee97ff
added missing ApiStateType
kumar303 Mar 27, 2017
92be514
fixed another missing ApiStateType
kumar303 Mar 27, 2017
86be2fb
added todo comment
kumar303 Mar 27, 2017
09e2570
complete Addon type
kumar303 Mar 27, 2017
cfb67b0
fixed missing review type
kumar303 Mar 27, 2017
a5c3cdb
fixed missing ApiStateType
kumar303 Mar 27, 2017
00c9e4f
Merge branch 'master' into flow-iss2044
kumar303 Mar 27, 2017
213910f
updated yarn.lock
kumar303 Mar 27, 2017
5078b4a
Merge branch 'master' into flow-iss2044
kumar303 Mar 27, 2017
b6c2d6c
dev script with watch
kumar303 Mar 27, 2017
d9d8775
use chokidar for file watching
kumar303 Mar 27, 2017
248356b
docs for flow'ing
kumar303 Mar 27, 2017
3cb62c0
moar readme
kumar303 Mar 27, 2017
1411198
moar readme
kumar303 Mar 27, 2017
77ce29c
more manifesto!
kumar303 Mar 27, 2017
e040275
comment about Redux
kumar303 Mar 27, 2017
cf88101
Clarified flow:dev
kumar303 Mar 29, 2017
b698e5f
remove old artifacts directory
kumar303 Mar 29, 2017
71980b0
run flow:check first
kumar303 Mar 29, 2017
1df442b
more docs
kumar303 Mar 29, 2017
6f23b6e
manifesto
kumar303 Mar 29, 2017
17ee0dd
Merge branch 'master' into flow-iss2044
kumar303 Mar 29, 2017
56a4387
Merge branch 'master' into flow-iss2044
kumar303 Mar 29, 2017
4d5b6fc
disable no-duplicate-imports
kumar303 Mar 30, 2017
a4394a4
Merge branch 'master' into flow-iss2044
kumar303 Mar 30, 2017
052e097
update yarn.lock after merge
kumar303 Mar 30, 2017
0ddff93
Merge branch 'master' into flow-iss2044
kumar303 Mar 30, 2017
eae1a6b
update yarn.lock
kumar303 Mar 30, 2017
f7ec38a
Merge branch 'master' into flow-iss2044
kumar303 Apr 5, 2017
732cebd
No more separation of params vs options because I forgot that this is…
kumar303 Apr 5, 2017
c5d9b19
sync yarn.lock and alphabetize babel plugins
kumar303 Apr 10, 2017
cd8712b
better import/export comment
kumar303 Apr 10, 2017
ec24254
fixed flow comment
kumar303 Apr 10, 2017
892fe90
todo: remove dedent declarations later
kumar303 Apr 10, 2017
cf66983
improved sass comment
kumar303 Apr 10, 2017
48cf36f
more concise intro
kumar303 Apr 10, 2017
898a45e
no spaces between slashes
kumar303 Apr 10, 2017
aa46b39
fixed avoiding magic section
kumar303 Apr 10, 2017
9ab7b38
fixed flow docs
kumar303 Apr 10, 2017
68a4d8a
fix JS
kumar303 Apr 10, 2017
cec7c56
fix docs
kumar303 Apr 10, 2017
69ff789
better Exact workaround explanation
kumar303 Apr 10, 2017
7085a4d
made 'rabbit hole' more explicit
kumar303 Apr 10, 2017
d643a3c
flow docs
kumar303 Apr 10, 2017
2bc4a66
reformat imports
kumar303 Apr 10, 2017
6494585
Use func not fn abbreviation
kumar303 Apr 10, 2017
830d23d
use 'any' not star
kumar303 Apr 10, 2017
ff60473
Fn -> Func
kumar303 Apr 10, 2017
8ce880f
remove irrelevant typeof declarations
kumar303 Apr 10, 2017
8d7f1d8
More thorough Exact<T> explanation
kumar303 Apr 10, 2017
a7524a2
Merge branch 'master' into flow-iss2044
kumar303 Apr 10, 2017
04f6e84
alphabetize
kumar303 Apr 10, 2017
7a78042
removed type suffix from type files
kumar303 Apr 10, 2017
1a5e2e0
Merge branch 'master' into flow-iss2044
kumar303 Apr 11, 2017
ee16518
rename -> core/types/util
kumar303 Apr 12, 2017
7dd4d3e
capitalize GitHub
kumar303 Apr 12, 2017
2c3d08c
rename data -> review
kumar303 Apr 12, 2017
f379431
alphabetize all type params
kumar303 Apr 12, 2017
3f512df
add leading pipe for pretty formatting
kumar303 Apr 12, 2017
c21ed00
Merge branch 'master' into flow-iss2044
kumar303 Apr 12, 2017
52d88a0
Merge branch 'master' into flow-iss2044
kumar303 Apr 17, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"plugins": [
"babel-plugin-dedent",
"transform-class-properties",
"transform-es2015-modules-commonjs"
"transform-es2015-modules-commonjs",
"transform-flow-strip-types"
]
}
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}],
// This ensures imports are at the top of the file.
"import/imports-first": ["error"],
// This catches duplicate exports.
// This reports when you accidentally import/export an object twice.
"import/no-duplicates": ["error"],
// This ensures import statements never provide a file extension in the path.
"import/extensions": ["error", "never"],
Expand All @@ -72,6 +72,8 @@
"import/newline-after-import": ["error"],
"jsx-a11y/no-static-element-interactions": "off",
"no-console": "error",
// We use import/no-duplicates instead because it supports Flow types.
"no-duplicate-imports": "off",
"no-plusplus": "off",
"no-underscore-dangle": "off",
"space-before-function-paren": ["error", "never"],
Expand Down
26 changes: 26 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[ignore]
# Ignore built/minified addons-frontend code.
<PROJECT_ROOT>/dist/.*

# These modules opt into Flow but we don't need to check them.
.*/node_modules/babel.*
.*/node_modules/react-nested-status
.*/node_modules/stylelint

[include]

[libs]
# TODO: this can go away after
# https://github.com/mozilla/addons-frontend/issues/2092
./flow/libs/dedent.js.flow

[options]
# This maps all Sass/SCSS imports to a dummy Flow file to suppress import
# errors. It's not necessary for Flow to analyze Sass/SCSS files.
module.name_mapper.extension='scss' -> '<PROJECT_ROOT>/flow/flowStub.js.flow'
module.system=node
module.system.node.resolve_dirname=node_modules
module.system.node.resolve_dirname=./src
log.file=./flow/logs/flow.log
suppress_comment= \\(.\\|\n\\)*\\$FLOW_FIXME
suppress_comment= \\(.\\|\n\\)*\\$FLOW_IGNORE
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
logs
*.log
npm-debug.log*
flow/logs/*log*

# Runtime data
pids
Expand Down
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Generic scripts that don't need env vars. Use these for development:
| npm run dev:amo | Starts the dev server and proxy (amo) |
| npm run dev:amo:no-proxy| Starts the dev server without proxy (amo) |
| npm run dev:disco | Starts the dev server (discovery pane) |
| npm run flow:check | Check for Flow errors and exit |
| npm run flow:dev | Continuously check for Flow errors |
| npm run eslint | Lints the JS |
| npm run stylelint | Lints the SCSS |
| npm run lint | Runs all the JS + SCSS linters |
Expand Down Expand Up @@ -84,6 +86,70 @@ or have `InfoDialog` in their behavior text.
Any option after the double dash (`--`) gets sent to `mocha`. Check out
[mocha's usage](https://mochajs.org/#usage) for ideas.

### Flow

There is limited support for using [Flow](https://flowtype.org/)
to check for problems in the source code.

To check for Flow issues during development while you edit files, run:

npm run flow:dev

If you are new to working with Flow, here are some tips:
* Check out the [getting started](https://flow.org/en/docs/getting-started/) guide.
Copy link
Contributor

Choose a reason for hiding this comment

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

Frustrating that you can't link to the docs without a locale and let it pick up the user's locale. 😒

* Read through the [web-ext guide](https://github.com/mozilla/web-ext/blob/master/CONTRIBUTING.md#check-for-flow-errors)
for hints on how to solve common Flow errors.

To add flow coverage to a source file, put a `/* @flow */` comment at the top.
The more source files you can opt into Flow, the better.

Here is our Flow manifesto:

* We use Flow to **declare the intention of our code** and help others
Copy link
Contributor

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 👍

refactor it with confidence.
Flow also makes it easier to catch mistakes before spending hours in a debugger
trying to find out what happened.
* Avoid magic [Flow declarations](https://flowtype.org/en/docs/config/libs/)
for any *internal* code. Just declare a
[type alias](https://flowtype.org/en/docs/types/aliases/) next to the code
where it's used and
[export/import](https://flow.org/en/docs/types/modules/) it like any other object.
* Never import a real JS object just to reference its type. Make a type alias
and import that instead.
* Never add more type annotations than you need. Flow is really good at
inferring types from standard JS code; it will tell you
when you need to add explicit annotations.
* When a function like `getAllAddons` takes object arguments, call its
type object `GetAllAddonsParams`. Example:

````js
type GetAllAddonsParams = {|
categoryId: number,
|};

function getAllAddons({ categoryId }: GetAllAddonsParams = {}) {
...
}
````

* Use [Exact object types](https://flowtype.org/en/docs/types/objects/#toc-exact-object-types)
via the pipe syntax (`{| key: ... |}`) when possible. Sometimes the
spread operator triggers an error like
'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/util`](https://github.com/mozilla/addons-frontend/blob/master/src/core/types/util.js)
if you have to. This is meant as a working replacement for
[$Exact<T>](https://flow.org/en/docs/types/utilities/#toc-exact).
* Try to avoid loose types like `Object` or `any` but feel free to use
them if you are spending too much time declaring types that depend on other
types that depend on other types, and so on.
* You can add a `$FLOW_FIXME` comment to skip a Flow check if you run
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.

### Code coverage

The `npm run unittest` command generates a report of how well the unit tests
Expand Down
1 change: 1 addition & 0 deletions flow/flowStub.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This file is just a stub that will suppress 'missing file' errors.
3 changes: 3 additions & 0 deletions flow/libs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The files in this directory (when declared in `[libs]` of `.flowconfig`)
will declare global objects. These declarations should be a last resort.
Try to export/import types in the actual source code first.
6 changes: 6 additions & 0 deletions flow/libs/dedent.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// TODO: this can go away after
// https://github.com/mozilla/addons-frontend/issues/2092

// I'm not sure exactly what this should be. I was using this issue as a guide.
// https://github.com/facebook/flow/issues/2616#issuecomment-289257544
declare function dedent(params: Array<*>): string;
Copy link
Contributor

@muffinresearch muffinresearch Mar 30, 2017

Choose a reason for hiding this comment

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

dedent is getting removed so we should remove it and then it doesn't matter.

1 change: 1 addition & 0 deletions flow/logs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flow server logs are written to this directory.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"dev:amo:no-proxy": "better-npm-run dev:amo:no-proxy",
"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",
Copy link
Contributor

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?

Copy link
Contributor Author

@kumar303 kumar303 Apr 12, 2017

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."

"stylelint": "stylelint --syntax scss **/*.scss",
"lint": "npm run eslint && npm run stylelint",
"servertest": "bin/config-check.js && ADDONS_FRONTEND_BUILD_ALL=1 npm run build && better-npm-run servertest && better-npm-run servertest:amo && better-npm-run servertest:disco && better-npm-run servertest:admin",
Expand Down Expand Up @@ -118,7 +120,7 @@
}
},
"test": {
"command": "npm run version-check && npm run unittest && npm run servertest && npm run eslint && npm run stylelint",
"command": "npm run version-check && npm run flow:check && npm run unittest && npm run servertest && npm run eslint && npm run stylelint",
"env": {
"NODE_PATH": "./:./src",
"NODE_ENV": "test"
Expand Down Expand Up @@ -229,6 +231,7 @@
"babel-plugin-react-transform": "2.0.2",
"babel-plugin-transform-class-properties": "6.18.0",
"babel-plugin-transform-decorators-legacy": "1.3.4",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"babel-plugin-transform-object-rest-spread": "6.20.2",
"babel-preset-es2015": "6.24.0",
"babel-preset-react": "6.16.0",
Expand All @@ -238,6 +241,7 @@
"chai": "3.5.0",
"chalk": "1.1.3",
"cheerio": "0.22.0",
"chokidar-cli": "1.2.0",
"concurrently": "3.4.0",
"cookie": "0.3.1",
"css-loader": "0.28.0",
Expand All @@ -249,6 +253,7 @@
"eslint-plugin-react": "6.10.3",
"fetch-mock": "5.9.4",
"file-loader": "0.10.1",
"flow-bin": "0.38.0",
"glob": "7.1.1",
"http-proxy": "1.16.2",
"json-loader": "0.5.4",
Expand Down
56 changes: 45 additions & 11 deletions src/amo/actions/reviews.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
/* @flow */
import { SET_ADDON_REVIEWS, SET_REVIEW } from 'amo/constants';
import type { ApiReviewType } from 'amo/api';

export function denormalizeReview(review) {
export type UserReviewType = {|
addonId: number,
addonSlug: string,
body: string,
created: Date,
id: number,
isLatest: boolean,
rating: number,
title: string,
userId: number,
userName: string,
userUrl: string,
versionId: ?number,
|};

export function denormalizeReview(review: ApiReviewType): UserReviewType {
return {
addonId: review.addon.id,
addonSlug: review.addon.slug,
body: review.body,
created: review.created,
title: review.title,
id: review.id,
isLatest: review.is_latest,
rating: review.rating,
title: review.title,
userId: review.user.id,
userName: review.user.name,
userUrl: review.user.url,
Expand All @@ -18,26 +35,43 @@ export function denormalizeReview(review) {
};
}

const setReviewAction = (review) => ({ type: SET_REVIEW, payload: review });
export type SetReviewAction = {|
type: string,
payload: UserReviewType,
|};

export const setReview = (review, reviewOverrides = {}) => {
export const setReview = (review: ApiReviewType): SetReviewAction => {
if (!review) {
throw new Error('review cannot be empty');
}
return setReviewAction({
...denormalizeReview(review),
...reviewOverrides,
});
return { type: SET_REVIEW, payload: denormalizeReview(review) };
};

export const setDenormalizedReview = (review) => {
export const setDenormalizedReview = (
review: UserReviewType
): SetReviewAction => {
if (!review) {
throw new Error('review cannot be empty');
}
return setReviewAction(review);
return { type: SET_REVIEW, payload: review };
};

export const setAddonReviews = ({ addonSlug, reviews }) => {
export type SetAddonReviewsAction = {|
type: string,
payload: {|
addonSlug: string,
reviews: Array<UserReviewType>,
|},
|};

type SetAddonReviewsParams = {|
addonSlug: string,
reviews: Array<ApiReviewType>,
|};

export const setAddonReviews = (
{ addonSlug, reviews }: SetAddonReviewsParams
): SetAddonReviewsAction => {
if (!addonSlug) {
throw new Error('addonSlug cannot be empty');
}
Expand Down
Loading