From 328ca63c162688334ef1a1738c005bcf54a25f23 Mon Sep 17 00:00:00 2001 From: Maria Adriana <97130795+mariadriana-deemaze@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:25:08 +0000 Subject: [PATCH] [SOA-24] Review linting configuration (#29) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore 🏗️ (format): add prettierignore until address linting issues * chore 🏗️ (format):address linting warns * fix ✅ (tests): correction to re-used constant --- .prettierignore | 3 ++ app/controllers/post_reactions_controller.ts | 35 +++++++++---------- app/controllers/posts_controller.ts | 4 +-- app/interfaces/attachment.ts | 2 +- .../{base-entity.ts => base_entity.ts} | 0 app/interfaces/post.ts | 8 ++--- app/interfaces/user.ts | 4 +-- app/models/attachment.ts | 2 +- .../{link-metadata.ts => link_metadata.ts} | 2 +- app/models/post.ts | 4 +-- app/models/post_reaction.ts | 2 +- app/models/post_report.ts | 2 +- app/models/session.ts | 2 +- app/models/user.ts | 2 +- app/services/attachment_service.ts | 2 +- app/services/link_parser_service.ts | 4 +-- app/services/post_reaction_service.ts | 2 +- app/services/post_report_service.ts | 2 +- app/services/posts_service.ts | 4 +-- app/services/user_service.ts | 2 +- database/factories/post_report_factory.ts | 2 +- ...ad-preview.tsx => file_upload_preview.tsx} | 0 inertia/components/posts/delete.tsx | 2 +- .../posts/{feed-list.tsx => feed_list.tsx} | 6 ++-- inertia/components/posts/form.tsx | 6 ++-- .../posts/{post-card.tsx => post_card.tsx} | 20 +++++------ inertia/components/posts/report.tsx | 18 +++++----- .../{dropdown-menu.tsx => dropdown_menu.tsx} | 0 .../ui/{hover-card.tsx => hover_card.tsx} | 0 inertia/components/ui/toaster.tsx | 2 +- .../ui/{use-toast.ts => use_toast.ts} | 11 +++--- inertia/components/users/nav.tsx | 2 +- ...server.ts => use_intersection_observer.ts} | 3 +- inertia/pages/feed.tsx | 2 +- inertia/pages/posts/show.tsx | 2 +- inertia/pages/{sign-in.tsx => sign_in.tsx} | 2 +- inertia/pages/{sign-up.tsx => sign_up.tsx} | 2 +- inertia/pages/users/settings.tsx | 2 +- inertia/pages/users/show.tsx | 2 +- package.json | 23 +++++++++++- start/routes.ts | 16 ++++----- .../{user-feed.spec.ts => user_feed.spec.ts} | 0 tests/browser/post_report.spec.ts | 6 ++-- 43 files changed, 119 insertions(+), 98 deletions(-) create mode 100644 .prettierignore rename app/interfaces/{base-entity.ts => base_entity.ts} (100%) rename app/models/{link-metadata.ts => link_metadata.ts} (96%) rename inertia/components/generic/{file-upload-preview.tsx => file_upload_preview.tsx} (100%) rename inertia/components/posts/{feed-list.tsx => feed_list.tsx} (92%) rename inertia/components/posts/{post-card.tsx => post_card.tsx} (95%) rename inertia/components/ui/{dropdown-menu.tsx => dropdown_menu.tsx} (100%) rename inertia/components/ui/{hover-card.tsx => hover_card.tsx} (100%) rename inertia/components/ui/{use-toast.ts => use_toast.ts} (94%) rename inertia/hooks/{use-intersection-observer.ts => use_intersection_observer.ts} (96%) rename inertia/pages/{sign-in.tsx => sign_in.tsx} (98%) rename inertia/pages/{sign-up.tsx => sign_up.tsx} (98%) rename tests/browser/pages/{user-feed.spec.ts => user_feed.spec.ts} (100%) diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..5f6d4ed --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +build/** +database/migrations/** +README.md \ No newline at end of file diff --git a/app/controllers/post_reactions_controller.ts b/app/controllers/post_reactions_controller.ts index 235113d..43fb4ee 100644 --- a/app/controllers/post_reactions_controller.ts +++ b/app/controllers/post_reactions_controller.ts @@ -1,38 +1,35 @@ -import PostReactionService from '#services/post_reaction_service'; -import { errorsReducer } from '#utils/index'; -import { postReactionValidator } from '#validators/post'; -import { inject } from '@adonisjs/core'; +import PostReactionService from '#services/post_reaction_service' +import { errorsReducer } from '#utils/index' +import { postReactionValidator } from '#validators/post' +import { inject } from '@adonisjs/core' import type { HttpContext } from '@adonisjs/core/http' -import { errors } from '@vinejs/vine'; +import { errors } from '@vinejs/vine' @inject() export default class PostReactionsController { - - constructor( - private readonly service: PostReactionService - ) { } + constructor(private readonly service: PostReactionService) {} async create(ctx: HttpContext) { - const postId = ctx.params.id; - const userId = ctx.auth.user?.id!; - const payload = ctx.request.body(); + const postId = ctx.params.id + const userId = ctx.auth.user?.id! + const payload = ctx.request.body() try { const { reaction } = await postReactionValidator.validate(payload) - const [preExistant, resource] = await this.service.create(userId, postId, reaction); - return preExistant ? ctx.response.ok(resource) : ctx.response.created(resource); + const [preExistant, resource] = await this.service.create(userId, postId, reaction) + return preExistant ? ctx.response.ok(resource) : ctx.response.created(resource) } catch (error) { if (error instanceof errors.E_VALIDATION_ERROR) { const reducedErrors = errorsReducer(error.messages) - return ctx.response.badRequest(reducedErrors); + return ctx.response.badRequest(reducedErrors) } - return ctx.response.badRequest(); + return ctx.response.badRequest() } } async destroy(ctx: HttpContext) { - const postId = ctx.params.id; - const userId = ctx.auth.user?.id!; - await this.service.destroy(userId, postId); + const postId = ctx.params.id + const userId = ctx.auth.user?.id! + await this.service.destroy(userId, postId) return ctx.response.noContent() } } diff --git a/app/controllers/posts_controller.ts b/app/controllers/posts_controller.ts index c641b0d..0a395e9 100644 --- a/app/controllers/posts_controller.ts +++ b/app/controllers/posts_controller.ts @@ -1,7 +1,7 @@ import { inject } from '@adonisjs/core' import { errors } from '@vinejs/vine' import type { HttpContext } from '@adonisjs/core/http' -import service from '#services/posts_service' +import PostsService from '#services/posts_service' import policy from '#policies/posts_policy' import Post from '#models/post' import { errorsReducer } from '#utils/index' @@ -10,7 +10,7 @@ import { PageObject } from '@adonisjs/inertia/types' @inject() export default class PostsController { - constructor(private service: service) {} + constructor(private service: PostsService) {} async show(ctx: HttpContext): Promise< | string diff --git a/app/interfaces/attachment.ts b/app/interfaces/attachment.ts index d182c8f..1b2c1ff 100644 --- a/app/interfaces/attachment.ts +++ b/app/interfaces/attachment.ts @@ -1,5 +1,5 @@ import { AttachmentType } from '#models/attachment' -import { UUID } from 'crypto' +import { UUID } from 'node:crypto' export interface AttachmentMetadataJSON { filename: string diff --git a/app/interfaces/base-entity.ts b/app/interfaces/base_entity.ts similarity index 100% rename from app/interfaces/base-entity.ts rename to app/interfaces/base_entity.ts diff --git a/app/interfaces/post.ts b/app/interfaces/post.ts index 47d5dec..681dcfb 100644 --- a/app/interfaces/post.ts +++ b/app/interfaces/post.ts @@ -1,5 +1,5 @@ -import { BaseEntity } from 'app/interfaces/base-entity' -import { UUID } from 'crypto' +import { BaseEntity } from '#interfaces/base_entity' +import { UUID } from 'node:crypto' import { UserResponse } from './user' import { AttachmentResponse } from 'app/interfaces/attachment' import { PostReactionType } from '#enums/post' @@ -25,8 +25,8 @@ export interface PostResponse extends BaseEntity { user: UserResponse link: LinkResponse | null reactions: { - reacted: PostReactionType | null, + reacted: PostReactionType | null reactionsCounts: Record - total:number; + total: number } } diff --git a/app/interfaces/user.ts b/app/interfaces/user.ts index ace9cbd..61ed413 100644 --- a/app/interfaces/user.ts +++ b/app/interfaces/user.ts @@ -1,7 +1,7 @@ import { AttachmentResponse } from '#interfaces/attachment' import { AccountRole } from '#models/user' -import { BaseEntity } from 'app/interfaces/base-entity' -import { UUID } from 'crypto' +import { BaseEntity } from '#interfaces/base_entity' +import { UUID } from 'node:crypto' export interface UserResponse extends BaseEntity { id: UUID diff --git a/app/models/attachment.ts b/app/models/attachment.ts index ad5d71e..b40ee53 100644 --- a/app/models/attachment.ts +++ b/app/models/attachment.ts @@ -1,6 +1,6 @@ import { DateTime } from 'luxon' import { BaseModel, column } from '@adonisjs/lucid/orm' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' import { AttachmentMetadataJSON } from 'app/interfaces/attachment' export enum AttachmentProvider { diff --git a/app/models/link-metadata.ts b/app/models/link_metadata.ts similarity index 96% rename from app/models/link-metadata.ts rename to app/models/link_metadata.ts index 73218b0..2ef7425 100644 --- a/app/models/link-metadata.ts +++ b/app/models/link_metadata.ts @@ -1,7 +1,7 @@ import { DateTime } from 'luxon' import { BaseModel, column } from '@adonisjs/lucid/orm' import { LinkMetadataJSONResponse } from 'app/interfaces/post' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' export class LinkMetadataJSON { // TODO: Could benefit in adding class-validator? diff --git a/app/models/post.ts b/app/models/post.ts index bd65266..bcd98b6 100644 --- a/app/models/post.ts +++ b/app/models/post.ts @@ -14,7 +14,7 @@ import { extractFirstLink, sanitizePostContent } from '#utils/index' import PostReaction from '#models/post_reaction' import PostReport from '#models/post_report' import { PostStatus } from '#enums/post' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' import type { BelongsTo, HasMany } from '@adonisjs/lucid/types/relations' export default class Post extends BaseModel { @@ -57,7 +57,7 @@ export default class Post extends BaseModel { } @beforeDelete() - public static async deleteAssociations(post: Post) { + static async deleteAssociations(post: Post) { await post.related('reactions').query().delete() } } diff --git a/app/models/post_reaction.ts b/app/models/post_reaction.ts index aedd8b7..ea8fc70 100644 --- a/app/models/post_reaction.ts +++ b/app/models/post_reaction.ts @@ -4,7 +4,7 @@ import Post from '#models/post' import User from '#models/user' import { PostReactionType } from '#enums/post' import type { BelongsTo } from '@adonisjs/lucid/types/relations' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' export default class PostReaction extends BaseModel { @column({ isPrimary: true }) diff --git a/app/models/post_report.ts b/app/models/post_report.ts index 17bc1f6..c9524e2 100644 --- a/app/models/post_report.ts +++ b/app/models/post_report.ts @@ -4,7 +4,7 @@ import { PostReportReason, PostReportStatus, PostStatus } from '#enums/post' import User from '#models/user' import Post from '#models/post' import type { BelongsTo } from '@adonisjs/lucid/types/relations' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' export default class PostReport extends BaseModel { @column({ isPrimary: true }) diff --git a/app/models/session.ts b/app/models/session.ts index 190e5f0..a269eac 100644 --- a/app/models/session.ts +++ b/app/models/session.ts @@ -1,6 +1,6 @@ import { BaseModel, column } from '@adonisjs/lucid/orm' import { DateTime } from 'luxon' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' export default class Session extends BaseModel { @column({ isPrimary: true }) diff --git a/app/models/user.ts b/app/models/user.ts index 5bc3064..f23f536 100644 --- a/app/models/user.ts +++ b/app/models/user.ts @@ -5,7 +5,7 @@ import { BaseModel, column, hasMany } from '@adonisjs/lucid/orm' import type { HasMany } from '@adonisjs/lucid/types/relations' import { withAuthFinder } from '@adonisjs/auth/mixins/lucid' import { DbRememberMeTokensProvider } from '@adonisjs/auth/session' -import { randomUUID, type UUID } from 'crypto' +import { randomUUID, type UUID } from 'node:crypto' import Session from '#models/session' import Post from '#models/post' diff --git a/app/services/attachment_service.ts b/app/services/attachment_service.ts index 68dd728..c55ed78 100644 --- a/app/services/attachment_service.ts +++ b/app/services/attachment_service.ts @@ -3,7 +3,7 @@ import { MultipartFile } from '@adonisjs/core/bodyparser' import { cuid } from '@adonisjs/core/helpers' import drive from '@adonisjs/drive/services/main' import { AttachmentResponse } from 'app/interfaces/attachment' -import { UUID } from 'crypto' +import { UUID } from 'node:crypto' export default class AttachmentService { private readonly disk = drive.use() diff --git a/app/services/link_parser_service.ts b/app/services/link_parser_service.ts index f35112d..ccf470d 100644 --- a/app/services/link_parser_service.ts +++ b/app/services/link_parser_service.ts @@ -1,4 +1,4 @@ -import LinkMetadata from '#models/link-metadata' +import LinkMetadata from '#models/link_metadata' import { LinkResponse } from 'app/interfaces/post' import { differenceInHours } from 'date-fns' import env from '#start/env' @@ -26,7 +26,7 @@ export default class LinkParserService { body: JSON.stringify({ q: link }), }) .then((res) => { - if (res.status != 200) { + if (res.status !== 200) { console.log(res.status) throw new Error('something went wrong') } diff --git a/app/services/post_reaction_service.ts b/app/services/post_reaction_service.ts index 066813f..6f192d8 100644 --- a/app/services/post_reaction_service.ts +++ b/app/services/post_reaction_service.ts @@ -1,6 +1,6 @@ import { PostReactionType } from '#enums/post' import PostReaction from '#models/post_reaction' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' export default class PostReactionService { constructor() {} diff --git a/app/services/post_report_service.ts b/app/services/post_report_service.ts index ddb6428..d73f089 100644 --- a/app/services/post_report_service.ts +++ b/app/services/post_report_service.ts @@ -1,7 +1,7 @@ import Post from '#models/post' import PostReport from '#models/post_report' import { postReportValidator } from '#validators/post_report' -import { UUID } from 'crypto' +import { UUID } from 'node:crypto' export default class PostReportService { constructor() {} diff --git a/app/services/posts_service.ts b/app/services/posts_service.ts index 9bf34b3..324e938 100644 --- a/app/services/posts_service.ts +++ b/app/services/posts_service.ts @@ -9,7 +9,7 @@ import { PostReactionType } from '#enums/post' import PostReaction from '#models/post_reaction' import { ModelObject } from '@adonisjs/lucid/types/model' import type { HttpContext } from '@adonisjs/core/http' -import type { UUID } from 'crypto' +import type { UUID } from 'node:crypto' import { UserService } from '#services/user_service' export default class PostsService { @@ -59,7 +59,7 @@ export default class PostsService { .where('id', id) .preload('user') .preload('reactions') - return !!result ? result[0] : null + return result ? result[0] : null } /** diff --git a/app/services/user_service.ts b/app/services/user_service.ts index e342189..5776543 100644 --- a/app/services/user_service.ts +++ b/app/services/user_service.ts @@ -4,7 +4,7 @@ import { AttachmentModel, AttachmentType } from '#models/attachment' import User from '#models/user' import AttachmentService from '#services/attachment_service' import { HttpContext } from '@adonisjs/core/http' -import { UUID } from 'crypto' +import { UUID } from 'node:crypto' export class UserService { private readonly attachmentService: AttachmentService diff --git a/database/factories/post_report_factory.ts b/database/factories/post_report_factory.ts index 419507d..49bf4a7 100644 --- a/database/factories/post_report_factory.ts +++ b/database/factories/post_report_factory.ts @@ -3,7 +3,7 @@ import PostReport from '#models/post_report' import { PostReportReason } from '#enums/post' import { UserFactory } from '#database/factories/user_factory' import { PostFactory } from '#database/factories/post_factory' -import { randomUUID } from 'crypto' +import { randomUUID } from 'node:crypto' export const PostReportFactory = factory .define(PostReport, async ({ faker }) => { diff --git a/inertia/components/generic/file-upload-preview.tsx b/inertia/components/generic/file_upload_preview.tsx similarity index 100% rename from inertia/components/generic/file-upload-preview.tsx rename to inertia/components/generic/file_upload_preview.tsx diff --git a/inertia/components/posts/delete.tsx b/inertia/components/posts/delete.tsx index 9a56f13..519071e 100644 --- a/inertia/components/posts/delete.tsx +++ b/inertia/components/posts/delete.tsx @@ -10,7 +10,7 @@ import { DialogTitle, DialogTrigger, } from '@/components/ui/dialog' -import { useToast } from '@/components/ui/use-toast' +import { useToast } from '@/components/ui/use_toast' import { ModelObject } from '@adonisjs/lucid/types/model' import { router } from '@inertiajs/react' diff --git a/inertia/components/posts/feed-list.tsx b/inertia/components/posts/feed_list.tsx similarity index 92% rename from inertia/components/posts/feed-list.tsx rename to inertia/components/posts/feed_list.tsx index 6e4e582..434a422 100644 --- a/inertia/components/posts/feed-list.tsx +++ b/inertia/components/posts/feed_list.tsx @@ -1,8 +1,8 @@ import { useEffect, useMemo, useState } from 'react' import { router } from '@inertiajs/react' -import { useToast } from '@/components/ui/use-toast' -import PostCard from '@/components/posts/post-card' -import { useIntersectionObserver } from '@/hooks/use-intersection-observer' +import { useToast } from '@/components/ui/use_toast' +import PostCard from '@/components/posts/post_card' +import { useIntersectionObserver } from '@/hooks/use_intersection_observer' import { PostResponse } from '#interfaces/post' import { UserResponse } from '#interfaces/user' import { Loader2 } from 'lucide-react' diff --git a/inertia/components/posts/form.tsx b/inertia/components/posts/form.tsx index b77b023..bebbe84 100644 --- a/inertia/components/posts/form.tsx +++ b/inertia/components/posts/form.tsx @@ -1,10 +1,10 @@ import React, { useEffect, useMemo, useRef } from 'react' import { MAX_POST_CONTENT_SIZE, MIN_POST_CONTENT_SIZE } from '#validators/post' -import FileUploadPreview from '@/components/generic/file-upload-preview' +import FileUploadPreview from '@/components/generic/file_upload_preview' import { Button } from '@/components/ui/button' import { Label } from '@/components/ui/label' import { Textarea } from '@/components/ui/textarea' -import { useToast } from '@/components/ui/use-toast' +import { useToast } from '@/components/ui/use_toast' import { cn } from '@/lib/utils' import { useForm, usePage } from '@inertiajs/react' import { Paperclip } from 'lucide-react' @@ -45,7 +45,7 @@ export default function Form({ const uploadImages = useRef(null) - const method = !!post ? 'patch' : 'post' + const method = post ? 'patch' : 'post' function addFiles(e: React.ChangeEvent) { if (!e.target.files) return diff --git a/inertia/components/posts/post-card.tsx b/inertia/components/posts/post_card.tsx similarity index 95% rename from inertia/components/posts/post-card.tsx rename to inertia/components/posts/post_card.tsx index 9a1f4e8..17384d2 100644 --- a/inertia/components/posts/post-card.tsx +++ b/inertia/components/posts/post_card.tsx @@ -17,7 +17,7 @@ import { DropdownMenuContent, DropdownMenuTrigger, DropdownMenuItem, -} from '@/components/ui/dropdown-menu' +} from '@/components/ui/dropdown_menu' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { UpdatePost } from '@/components/posts/update' import { DeletePost } from '@/components/posts/delete' @@ -25,8 +25,8 @@ import { PostResponse } from 'app/interfaces/post' import { AttachmentResponse } from 'app/interfaces/attachment' import { formatDistanceToNow } from 'date-fns' import { PostReactionType } from '#enums/post' -import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover-card' -import type { UUID } from 'crypto' +import { HoverCard, HoverCardContent, HoverCardTrigger } from '@/components/ui/hover_card' +import type { UUID } from 'node:crypto' import { UserResponse } from '#interfaces/user' import { ReportPost } from '@/components/posts/report' @@ -266,16 +266,16 @@ function PostReaction({ }, [reaction.type]) const reactionCounts = useMemo(() => { - const counts = { ...post.reactions.reactionsCounts } + const accCounts = { ...post.reactions.reactionsCounts } if (reaction.type && post.reactions.reacted) { - counts[reaction.type] = counts[reaction.type] + 1 - counts[post.reactions.reacted] = counts[post.reactions.reacted] - 1 + accCounts[reaction.type] = accCounts[reaction.type] + 1 + accCounts[post.reactions.reacted] = accCounts[post.reactions.reacted] - 1 } else if (reaction.type && !post.reactions.reacted) { - counts[reaction.type] = counts[reaction.type] + 1 + accCounts[reaction.type] = accCounts[reaction.type] + 1 } else if (!reaction.type && post.reactions.reacted) { - counts[post.reactions.reacted] = counts[post.reactions.reacted] - 1 + accCounts[post.reactions.reacted] = accCounts[post.reactions.reacted] - 1 } - return counts + return accCounts }, [reaction.type]) return ( @@ -283,7 +283,7 @@ function PostReaction({