Skip to content

Commit 5b9b761

Browse files
author
Oliver Rumbelow
committed
Merge pull request #116 from holidayextras/flow
Use Flow for some Static Analysis
2 parents 75689c4 + 4e8a5e6 commit 5b9b761

34 files changed

+61
-1
lines changed

.flowconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[include]
2+
./lib/
3+
4+
[ignore]
5+
.*bad-locale\.json
6+
7+
[options]
8+
module.ignore_non_literal_requires=true
9+
munge_underscores=true
10+
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ script: "npm run $TEST_STEP"
55
env:
66
matrix:
77
- TEST_STEP=lint
8+
- TEST_STEP=flow
89
- TEST_STEP=test
910
notifications:
1011
email: false

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ To verify all the code changes pass our style guidelines:
2626
npm run lint
2727
```
2828

29+
To run the static analysis tool (provided by Flow):
30+
```
31+
npm run flow
32+
```
33+
2934
To verify everything still behaves as expected:
3035
```
3136
npm test

lib/MemoryHandler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
var _ = {
34
assign: require("lodash.assign")

lib/debugging.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
module.exports = {
34
handler: {

lib/handlerEnforcer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
var handlerEnforcer = module.exports = { };
34

@@ -12,6 +13,10 @@ handlerEnforcer.wrap = function(handlers) {
1213
};
1314

1415
handlerEnforcer._wrapHandler = function(handlers, operation, outCount) {
16+
if (typeof outCount !== "number") {
17+
throw new Error("Invalid use of handlerEnforcer._wrapHandler!");
18+
}
19+
1520
var original = handlers[operation];
1621
return function() {
1722
var argsIn = Array.prototype.slice.call(arguments);
@@ -20,6 +25,7 @@ handlerEnforcer._wrapHandler = function(handlers, operation, outCount) {
2025
argsIn.push(function() {
2126
var argsOut = Array.prototype.slice.call(arguments);
2227
argsOut = argsOut.slice(0, outCount);
28+
// $FlowFixMe: We've already ruled out any other possible types for outCount?
2329
while (argsOut.length < outCount) {
2430
argsOut.push(null);
2531
}

lib/jsonApi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
var jsonApi = module.exports = { };
34
jsonApi._resources = { };

lib/ourJoi.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
var ourJoi = module.exports = { };
34

lib/pagination.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
var pagination = module.exports = { };
34

lib/postProcess.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* @flow weak */
12
"use strict";
23
var postProcess = module.exports = { };
34

@@ -69,6 +70,8 @@ postProcess._fetchRelatedResources = function(request, mainResource, callback) {
6970
json = null;
7071
}
7172

73+
if (!json) return done(null, [ ]);
74+
7275
if (externalRes.statusCode >= 400) {
7376
return done(json.errors);
7477
}

0 commit comments

Comments
 (0)