Skip to content

Commit 4a378b9

Browse files
authored
Merge pull request #1010 from wincent/glh/lint
Add linter error preventing use of `async` outside the test suite
2 parents 31ebb1f + 84e0ad8 commit 4a378b9

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@
219219
"vars-on-top": 0,
220220
"wrap-iife": 2,
221221
"wrap-regex": 0,
222-
"yoda": [2, "never", {"exceptRange": true}]
222+
"yoda": [2, "never", {"exceptRange": true}],
223+
224+
"no-async": 2
223225
}
224226
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"test": "npm run lint && npm run check && npm run testonly",
2525
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
2626
"t": "babel-node ./node_modules/.bin/_mocha --require ./resources/mocha-bootload",
27-
"lint": "eslint src || (printf '\\033[33mTry: \\033[7m npm run lint -- --fix \\033[0m\\n' && exit 1)",
27+
"lint": "eslint --rulesdir ./resources/lint src || (printf '\\033[33mTry: \\033[7m npm run lint -- --fix \\033[0m\\n' && exit 1)",
2828
"check": "flow check",
2929
"check-cover": "for file in {src/*.js,src/**/*.js}; do echo $file; flow coverage $file; done",
3030
"build": "babel src --optional runtime --ignore __tests__ --out-dir dist/ && cp package.json dist/ && npm run build-dot-flow",

resources/lint/no-async.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) 2017, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
module.exports = function(context) {
11+
if (context.getFilename().match(/\b__tests__\b/)) {
12+
return {};
13+
} else {
14+
return {
15+
FunctionDeclaration: function(node) {
16+
if (node.async) {
17+
context.report(
18+
node,
19+
'async functions are not allowed outside of the test suite ' +
20+
'because older versions of NodeJS do not support them ' +
21+
'without additional runtime dependencies. Instead, use explicit ' +
22+
'Promises.'
23+
);
24+
}
25+
},
26+
};
27+
}
28+
};

0 commit comments

Comments
 (0)