Browse Source

remove eslint-disable-next-line no-await-in-loop lines

Yuki Takei 2 months ago
parent
commit
8881e00781

+ 2 - 1
apps/app/playwright/60-home/home.spec.ts

@@ -1,3 +1,5 @@
+/** biome-ignore-all lint/performance/noAwaitInLoops: Allow in tests */
+
 import { expect, test } from '@playwright/test';
 
 test('Visit User home', async ({ page }) => {
@@ -74,7 +76,6 @@ test('Access Password setting', async ({ page }) => {
 
   const toastElementsCount = await toastElements.count();
   for (let i = 0; i < toastElementsCount; i++) {
-    // eslint-disable-next-line no-await-in-loop
     await toastElements.nth(i).click();
   }
 

+ 2 - 1
apps/app/src/features/rate-limiter/middleware/consume-points.integ.ts

@@ -1,3 +1,5 @@
+/** biome-ignore-all lint/performance/noAwaitInLoops: Allow in tests */
+
 import { faker } from '@faker-js/faker';
 
 const testRateLimitErrorWhenExceedingMaxRequests = async (
@@ -12,7 +14,6 @@ const testRateLimitErrorWhenExceedingMaxRequests = async (
   try {
     for (let i = 1; i <= maxRequests + 1; i++) {
       count += 1;
-      // eslint-disable-next-line no-await-in-loop
       const res = await consumePoints(method, key, { method, maxRequests });
       if (count === maxRequests) {
         // Expect consumedPoints to be equal to maxRequest when maxRequest is reached

+ 2 - 4
apps/app/src/migrations/20181019114028-abolish-page-group-relation.js

@@ -52,8 +52,8 @@ module.exports = {
       .find()
       .toArray();
 
-    /* eslint-disable no-await-in-loop */
     for (const relation of relations) {
+      // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
       const page = await Page.findOne({ _id: relation.targetPage });
 
       // skip if grant mismatch
@@ -71,7 +71,6 @@ module.exports = {
       page.grantedGroup = userGroup;
       await page.save();
     }
-    /* eslint-enable no-await-in-loop */
 
     // drop collection
     await db.collection('pagegrouprelations').drop();
@@ -89,12 +88,12 @@ module.exports = {
     // retrieve all Page documents which granted by UserGroup
     const relatedPages = await Page.find({ grant: Page.GRANT_USER_GROUP });
     const insertDocs = [];
-    /* eslint-disable no-await-in-loop */
     for (const page of relatedPages) {
       if (page.grantedGroup == null) {
         continue;
       }
 
+      // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
       const userGroup = await UserGroup.findOne({ _id: page.grantedGroup });
 
       // skip if userGroup does not exist
@@ -113,7 +112,6 @@ module.exports = {
       page.grantedGroup = undefined;
       await page.save();
     }
-    /* eslint-enable no-await-in-loop */
 
     if (insertDocs.length > 0) {
       await db.collection('pagegrouprelations').insertMany(insertDocs);

+ 1 - 1
apps/app/src/server/models/password-reset-order.ts

@@ -62,7 +62,7 @@ schema.statics.createPasswordResetOrder = async function (email) {
 
   do {
     token = this.generateOneTimeToken();
-    // eslint-disable-next-line no-await-in-loop
+    // biome-ignore lint/performance/noAwaitInLoops: The loop is necessary to process one after another
     duplicateToken = await this.findOne({ token });
   } while (duplicateToken != null);
 

+ 1 - 1
apps/app/src/server/models/user-registration-order.ts

@@ -60,7 +60,7 @@ schema.statics.createUserRegistrationOrder = async function (email) {
 
   do {
     token = this.generateOneTimeToken();
-    // eslint-disable-next-line no-await-in-loop
+    // biome-ignore lint/performance/noAwaitInLoops: The loop is necessary to process one after another
     duplicateToken = await this.findOne({ token });
   } while (duplicateToken != null);
 

+ 1 - 1
apps/app/src/server/models/user.js

@@ -651,7 +651,7 @@ const factory = (crowi) => {
 
     for (const email of creationEmailList) {
       try {
-        // eslint-disable-next-line no-await-in-loop
+        // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
         const createdUser = await this.createUserByEmail(email);
         createdUserList.push(createdUser);
       } catch (err) {

+ 1 - 2
apps/app/src/server/routes/apiv3/users.js

@@ -213,7 +213,7 @@ module.exports = (crowi) => {
 
     for (const user of userList) {
       try {
-        // eslint-disable-next-line no-await-in-loop
+        // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
         await mailService.send({
           to: user.email,
           subject: `Invitation to ${appTitle}`,
@@ -228,7 +228,6 @@ module.exports = (crowi) => {
             appTitle,
           },
         });
-        // eslint-disable-next-line no-await-in-loop
         await User.updateIsInvitationEmailSended(user.user.id);
       } catch (err) {
         logger.error(err);

+ 1 - 1
apps/app/src/server/service/file-uploader/aws/index.ts

@@ -468,11 +468,11 @@ module.exports = (crowi: Crowi) => {
 
     // handle pagination
     while (shouldContinue) {
-      // eslint-disable-next-line no-await-in-loop
       const {
         Contents = [],
         IsTruncated,
         NextMarker,
+        // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
       } = await s3.send(
         new ListObjectsCommand({
           ...params,

+ 1 - 2
apps/app/src/server/util/createGrowiPagesFromImports.js

@@ -18,12 +18,12 @@ module.exports = (crowi) => {
     const promises = [];
     const errors = [];
 
-    /* eslint-disable no-await-in-loop */
     for (const page of pages) {
       const path = page.path;
       const user = page.user;
       const body = page.body;
       const isCreatableName = isCreatablePage(path);
+      // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
       const isPageNameTaken = await Page.findByPathAndViewer(path, user);
 
       if (isCreatableName && !isPageNameTaken) {
@@ -45,7 +45,6 @@ module.exports = (crowi) => {
         }
       }
     }
-    /* eslint-enable no-await-in-loop */
 
     await Promise.all(promises);
 

+ 1 - 1
apps/app/src/utils/promise.ts

@@ -18,7 +18,7 @@ export const batchProcessPromiseAll = async <I, O>(
   for (let start = 0; start < items.length; start += limit) {
     const end = Math.min(start + limit, items.length);
 
-    // eslint-disable-next-line no-await-in-loop
+    // biome-ignore lint/performance/noAwaitInLoops: Allow for memory consumption control
     const slicedResults = await Promise.allSettled(
       items.slice(start, end).map(fn),
     );

+ 1 - 2
apps/pdf-converter/src/service/pdf-convert.ts

@@ -145,7 +145,7 @@ class PdfConvertService implements OnInit {
     appId?: number,
   ): Promise<void> {
     while (!this.isJobCompleted(jobId)) {
-      // eslint-disable-next-line no-await-in-loop
+      // biome-ignore lint/performance/noAwaitInLoops: Allow in this case to wait between iterations
       await new Promise((resolve) => setTimeout(resolve, 10 * 1000));
 
       try {
@@ -157,7 +157,6 @@ class PdfConvertService implements OnInit {
         const pdfWritable = this.getPdfWritable();
         this.jobList[jobId].currentStream = htmlReadable;
 
-        // eslint-disable-next-line no-await-in-loop
         await pipelinePromise(htmlReadable, pdfWritable);
         this.jobList[jobId].currentStream = undefined;
       } catch (err) {

+ 3 - 0
biome.json

@@ -63,6 +63,9 @@
       "suspicious": {
         "noConsole": "error"
       },
+      "performance": {
+        "noAwaitInLoops": "warn"
+      },
       "correctness": {
         "useUniqueElementIds": "warn"
       }