-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add linter error preventing use of
async
outside the test suite
We want to keep the runtime dependency footprint small, so that means avoiding use of `async` at runtime (which creates a dependency on the Regenerator runtime). There is no built-in eslint rule for this, so we make a custom one. Test plan: Add an `async` function to a file, run `yarn run lint` and see: graphql-js/src/subscription/subscribe.js 288:1 error async functions are not allowed outside of the test suite no-async ✖ 1 problem (1 error, 0 warnings) Note that no errors are issued for the `async` functions in the test suite. Closes: #1008
- Loading branch information
Showing
3 changed files
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) 2017, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
module.exports = function(context) { | ||
if (context.getFilename().match(/\b__tests__\b/)) { | ||
return {}; | ||
} else { | ||
return { | ||
FunctionDeclaration: function(node) { | ||
if (node.async) { | ||
context.report( | ||
node, | ||
'async functions are not allowed outside of the test suite' | ||
); | ||
} | ||
}, | ||
}; | ||
} | ||
}; |