Просмотр исходного кода

fix non-autofixable biome lint errors

Futa Arai 10 месяцев назад
Родитель
Сommit
34ec356fff

+ 6 - 4
packages/remark-attachment-refs/src/client/components/util/refs-context.ts

@@ -35,9 +35,11 @@ export class RefsContext {
     this.pagePath = pagePath;
     this.pagePath = pagePath;
 
 
     // remove undefined keys
     // remove undefined keys
-    Object.keys(options).forEach(
-      (key) => options[key] === undefined && delete options[key],
-    );
+    for (const key of Object.keys(options)) {
+      if (options[key] === undefined) {
+        delete options[key];
+      }
+    }
 
 
     this.options = options;
     this.options = options;
   }
   }
@@ -78,7 +80,7 @@ export class RefsContext {
 
 
   isOptGridColumnEnabled(): boolean {
   isOptGridColumnEnabled(): boolean {
     const optGrid = this.getOptGrid();
     const optGrid = this.getOptGrid();
-    return optGrid != null && optGrid.startsWith('col-');
+    return optGrid?.startsWith('col-') ?? false;
   }
   }
 
 
   /**
   /**

+ 10 - 7
packages/remark-attachment-refs/src/client/services/renderer/refs.ts

@@ -57,7 +57,10 @@ export const remarkPlugin: Plugin = () => (tree) => {
       if (typeof node.name !== 'string') {
       if (typeof node.name !== 'string') {
         return;
         return;
       }
       }
-      const data = node.data ?? (node.data = {});
+      if (node.data == null) {
+        node.data = {};
+      }
+      const data = node.data;
       const attributes = (node.attributes as DirectiveAttributes) || {};
       const attributes = (node.attributes as DirectiveAttributes) || {};
       const attrEntries = Object.entries(attributes);
       const attrEntries = Object.entries(attributes);
 
 
@@ -166,9 +169,9 @@ export const rehypePlugin: Plugin<[RefRehypePluginParams]> = (options = {}) => {
       tree as HastNode,
       tree as HastNode,
     );
     );
 
 
-    elements.forEach((refElem) => {
+    for (const refElem of elements) {
       if (refElem.properties == null) {
       if (refElem.properties == null) {
-        return;
+        continue;
       }
       }
 
 
       const prefix = refElem.properties.prefix;
       const prefix = refElem.properties.prefix;
@@ -183,17 +186,17 @@ export const rehypePlugin: Plugin<[RefRehypePluginParams]> = (options = {}) => {
       // set basePagePath when pagePath is undefined or invalid
       // set basePagePath when pagePath is undefined or invalid
       if (pagePath == null || typeof pagePath !== 'string') {
       if (pagePath == null || typeof pagePath !== 'string') {
         refElem.properties.pagePath = basePagePath;
         refElem.properties.pagePath = basePagePath;
-        return;
+        continue;
       }
       }
 
 
-      // return when page is already determined and aboslute path
+      // return when page is already determined and absolute path
       if (pathUtils.hasHeadingSlash(pagePath)) {
       if (pathUtils.hasHeadingSlash(pagePath)) {
-        return;
+        continue;
       }
       }
 
 
       // resolve relative path
       // resolve relative path
       refElem.properties.pagePath = getAbsolutePathFor(pagePath, basePagePath);
       refElem.properties.pagePath = getAbsolutePathFor(pagePath, basePagePath);
-    });
+    }
   };
   };
 };
 };
 
 

+ 1 - 1
packages/remark-attachment-refs/src/server/index.ts

@@ -1,6 +1,6 @@
 import { routesFactory } from './routes/refs';
 import { routesFactory } from './routes/refs';
 
 
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
+// biome-ignore lint/suspicious/noExplicitAny: ignore
 const middleware = (crowi: any, app: any): void => {
 const middleware = (crowi: any, app: any): void => {
   const refs = routesFactory(crowi);
   const refs = routesFactory(crowi);
 
 

+ 11 - 11
packages/remark-attachment-refs/src/server/routes/refs.ts

@@ -65,7 +65,7 @@ const loginRequiredFallback = (req, res) => {
   return res.status(403).send('login required');
   return res.status(403).send('login required');
 };
 };
 
 
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
+// biome-ignore lint/suspicious/noExplicitAny: ignore
 export const routesFactory = (crowi): any => {
 export const routesFactory = (crowi): any => {
   const loginRequired = crowi.require('../middlewares/login-required')(
   const loginRequired = crowi.require('../middlewares/login-required')(
     crowi,
     crowi,
@@ -78,11 +78,12 @@ export const routesFactory = (crowi): any => {
 
 
   const ObjectId = Types.ObjectId;
   const ObjectId = Types.ObjectId;
 
 
+  // biome-ignore lint/suspicious/noExplicitAny: ignore
   const Page = mongoose.model<HydratedDocument<IPage>, Model<any> & any>(
   const Page = mongoose.model<HydratedDocument<IPage>, Model<any> & any>(
     'Page',
     'Page',
   );
   );
 
 
-  // eslint-disable-next-line @typescript-eslint/no-explicit-any
+  // biome-ignore lint/suspicious/noExplicitAny: ignore
   const { PageQueryBuilder } = Page as any;
   const { PageQueryBuilder } = Page as any;
 
 
   /**
   /**
@@ -122,7 +123,7 @@ export const routesFactory = (crowi): any => {
       }
       }
 
 
       // convert ObjectId
       // convert ObjectId
-      // eslint-disable-next-line @typescript-eslint/no-explicit-any
+      // biome-ignore lint/suspicious/noExplicitAny: ignore
       const orConditions: any[] = [{ originalName: fileNameOrId }];
       const orConditions: any[] = [{ originalName: fileNameOrId }];
       if (fileNameOrId != null && ObjectId.isValid(fileNameOrId.toString())) {
       if (fileNameOrId != null && ObjectId.isValid(fileNameOrId.toString())) {
         orConditions.push({ _id: new ObjectId(fileNameOrId.toString()) });
         orConditions.push({ _id: new ObjectId(fileNameOrId.toString()) });
@@ -155,7 +156,7 @@ export const routesFactory = (crowi): any => {
       );
       );
       if (!isAccessible) {
       if (!isAccessible) {
         logger.debug(
         logger.debug(
-          `attachment '${attachment.id}' is forbidden for user '${user && user.username}'`,
+          `attachment '${attachment.id}' is forbidden for user '${user?.username}'`,
         );
         );
         res.status(403).send(`page '${attachment.page}' is forbidden.`);
         res.status(403).send(`page '${attachment.page}' is forbidden.`);
         return;
         return;
@@ -207,6 +208,7 @@ export const routesFactory = (crowi): any => {
         }
         }
       }
       }
 
 
+      // biome-ignore lint/suspicious/noImplicitAnyLet: ignore
       let builder;
       let builder;
 
 
       // builder to retrieve descendance
       // builder to retrieve descendance
@@ -251,13 +253,11 @@ export const routesFactory = (crowi): any => {
 
 
       const attachments = await query.populate('creator').exec();
       const attachments = await query.populate('creator').exec();
 
 
-      res
-        .status(200)
-        .send({
-          attachments: attachments.map((attachment) =>
-            serializeAttachmentSecurely(attachment),
-          ),
-        });
+      res.status(200).send({
+        attachments: attachments.map((attachment) =>
+          serializeAttachmentSecurely(attachment),
+        ),
+      });
     },
     },
   );
   );