File tree Expand file tree Collapse file tree
packages/eslint-plugin/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const recommended = {
55 "@calcom/eslint/deprecated-imports" : "error" ,
66 "@calcom/eslint/avoid-web-storage" : "error" ,
77 "@calcom/eslint/avoid-prisma-client-import-for-enums" : "error" ,
8+ "@calcom/eslint/no-async-foreach-callback" : "error" ,
89 } ,
910} ;
1011
Original file line number Diff line number Diff line change @@ -5,4 +5,5 @@ export default {
55 "deprecated-imports" : require ( "./deprecated-imports" ) . default ,
66 "avoid-web-storage" : require ( "./avoid-web-storage" ) . default ,
77 "avoid-prisma-client-import-for-enums" : require ( "./avoid-prisma-client-import-for-enums" ) . default ,
8+ "no-async-foreach-callback" : require ( "./no-async-foreach-callback" ) . default ,
89} as ESLint . Plugin [ "rules" ] ;
Original file line number Diff line number Diff line change 1+ import { ESLintUtils } from "@typescript-eslint/utils" ;
2+
3+ const createRule = ESLintUtils . RuleCreator ( ( name ) => `https://developer.cal.com/eslint/rule/${ name } ` ) ;
4+
5+ const rule = createRule ( {
6+ create ( context ) {
7+ return {
8+ CallExpression ( node ) {
9+ const { callee } = node ;
10+ if (
11+ callee . type === "MemberExpression" &&
12+ callee . property . type === "Identifier" &&
13+ callee . property . name === "forEach"
14+ ) {
15+ const firstArg = node . arguments [ 0 ] ;
16+ if (
17+ ( firstArg . type === "ArrowFunctionExpression" || firstArg . type === "FunctionExpression" ) &&
18+ firstArg . async
19+ ) {
20+ context . report ( {
21+ node,
22+ messageId : "async-foreach" ,
23+ } ) ;
24+ }
25+ }
26+ } ,
27+ } ;
28+ } ,
29+ name : "no-async-foreach-callback" ,
30+ meta : {
31+ docs : {
32+ description : "Disallow using an async function as a forEach callback" ,
33+ recommended : "warn" ,
34+ } ,
35+ messages : {
36+ "async-foreach" : "forEach callbacks should not be async, did you mean to use Promise.all?" ,
37+ } ,
38+ type : "suggestion" ,
39+ schema : [ ] ,
40+ } ,
41+ defaultOptions : [ ] ,
42+ } ) ;
43+
44+ export default rule ;
You can’t perform that action at this time.
0 commit comments