Skip to content

Commit

Permalink
Fix warnings after kir-jam (#135)
Browse files Browse the repository at this point in the history
* Upgrade caniuse-db

* run CI on staging

* Add force-dynamic to all pages

Because nav-bar is different for every user (displays username)

* Refactor clock component

* Fix tailwind warnings

* backend: Ignore dist folder

* configure code style check and fix important issues

* Make everything dynamic

* prettier

---------

Co-authored-by: Sámuel Fekete <[email protected]>
  • Loading branch information
tomitheninja and Tschonti authored Apr 7, 2024
1 parent f5c7f8d commit 0012395
Show file tree
Hide file tree
Showing 39 changed files with 223 additions and 269 deletions.
10 changes: 5 additions & 5 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*.png
*.jpg
*.jpeg
/out/*
/dist/*
/build/*
/rules
packages/client/tailwind.config.js/
**/out/*
**/dist/*
**/build/*
**/rules
**/.eslintrc.js
74 changes: 7 additions & 67 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: Code Style Check

on:
push:
branches: ['master']
branches: ['master', 'staging']
pull_request:
branches: ['master']
branches: ['master', 'staging']

jobs:
backend-eslint:
check-code-style:
name: ESLint Check
runs-on: ubuntu-latest
permissions:
Expand All @@ -18,71 +18,11 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Dev Dependencies
run: |
npm install --only=dev
working-directory: './packages/backend'
- name: Install Dependencies
run: yarn install

- name: Run ESLint
run: npm run lint
working-directory: './packages/backend'

backend-prettier:
name: Prettier Check
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Install Dev Dependencies
run: |
npm install --only=dev
working-directory: './packages/backend'
run: npx eslint .

- name: Run Prettier
run: npm run prettier
working-directory: './packages/backend'
#
# frontend-eslint:
# name: ESLint Check
# runs-on: ubuntu-latest
# permissions:
# contents: read
# security-events: write
# actions: read
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
#
# - name: Install Dev Dependencies
# run: |
# npm install --only=dev
# working-directory: "./packages/frontend"
#
# - name: Run ESLint
# run: npm run lint
# working-directory: "./packages/frontend"
#
# frontend-prettier:
# name: Prettier Check
# runs-on: ubuntu-latest
# permissions:
# contents: read
# security-events: write
# actions: read
# steps:
# - name: Checkout code
# uses: actions/checkout@v3
#
# - name: Install Dev Dependencies
# run: |
# npm install --only=dev
# working-directory: "./packages/frontend"
#
# - name: Run Prettier
# run: npm run prettier
# working-directory: "./packages/frontend"
run: npx prettier --check .
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"printWidth": 150,
"jsxSingleQuote": true,
"bracketSameLine": false,
"endOfLine": "crlf",
"endOfLine": "lf",
"tabWidth": 2,
"arrowParens": "avoid"
}
1 change: 1 addition & 0 deletions packages/admin/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports = {
'react-refresh/only-export-components': 'warn',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'prettier/prettier': 'error',
},
}
3 changes: 1 addition & 2 deletions packages/backend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ module.exports = {
sourceType: 'module',
},
plugins: ['prettier'],
extends: ['prettier'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'prettier/prettier': 'error',
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/auth/decorators/CurrentUser.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const CurrentUser = createParamDecorator<keyof User | undefined>(
throw new InternalServerErrorException('CurrentUser decorator invoked without authGuard')
}

if (key && !user.hasOwnProperty(key)) {
if (key && !Object.prototype.hasOwnProperty.call(user, key)) {
throw new InternalServerErrorException(`Unknown key ${key} in CurrentUser decorator`)
}

Expand All @@ -32,7 +32,7 @@ export const CurrentUserOptional = createParamDecorator<keyof User | undefined>(
*/
(key, context: ExecutionContext) => {
const user: User = context.switchToHttp().getRequest().user
if (key && !user?.hasOwnProperty(key)) {
if (key && !Object.prototype.hasOwnProperty.call(user, key)) {
throw new InternalServerErrorException(`Unknown key ${key} in CurrentUser decorator`)
}

Expand Down
5 changes: 1 addition & 4 deletions packages/backend/src/collection/dto/CollectionEntity.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { ArrayMinSize, ArrayNotEmpty, IsArray, IsNotEmpty, IsObject, IsString, IsUUID, Matches, ValidateNested } from 'class-validator'
import { Link } from 'src/links/entities/link.entity'
import { ApiProperty } from '@nestjs/swagger'
import { Type } from 'class-transformer'
import { IsNotEmpty, IsString, IsUUID, Matches } from 'class-validator'

export class CollectionEntity {
@IsUUID('all')
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/links/links.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Module } from '@nestjs/common'
import { PrismaModule } from 'nestjs-prisma'
import { LinksController } from './links.controller'
import { LinksService } from './links.service'
import { Link } from './entities/link.entity'

@Module({
controllers: [LinksController],
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/links/links.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class LinksService {
const oldLink = await this.prisma.link.findUnique({ where: { id } })
const newLink = await this.prisma.link.update({ where: { id }, data: { ...updateLinkDto, iconUrl: fileName } })
if (oldLink.iconUrl) {
unlink(join(process.cwd(), '/static', oldLink.iconUrl), () => {})
unlink(join(process.cwd(), '/static', oldLink.iconUrl), () => undefined)
}
return newLink
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class UserService {
return { collections: user.collections, submissions: user.submissions, firstName: user.firstName, email: user.email, role: user.role }
}
async saveFavorite(id: string, user: User): Promise<void> {
const res = await this.prisma.user.update({ where: { id: user.id }, data: { favorites: { connect: { id } } } })
await this.prisma.user.update({ where: { id: user.id }, data: { favorites: { connect: { id } } } })
return
}
async removeFavorite(id: string, user: User): Promise<void> {
const res = await this.prisma.user.update({ where: { id: user.id }, data: { favorites: { disconnect: { id } } } })
await this.prisma.user.update({ where: { id: user.id }, data: { favorites: { disconnect: { id } } } })
}
async getFavorites(user: User): Promise<Link[]> {
const res = await this.prisma.user.findUnique({ where: { id: user.id }, include: { favorites: true } })
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/util/DeleteFileExceptionFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class DeleteFileExceptionFilter extends BaseExceptionFilter {
const ctx = host.switchToHttp()
const request = ctx.getRequest<Request>()
if (request.file) {
unlink(join(process.cwd(), '/static', request.file.filename), () => {})
unlink(join(process.cwd(), '/static', request.file.filename), () => undefined)
}
super.catch(exception, host)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
"exclude": ["node_modules", "test", "dist", "**/*spec.ts", ".eslintrc.js"]
}
3 changes: 2 additions & 1 deletion packages/backend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"strictBindCallApply": false,
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false
}
},
"exclude": ["node_modules", "dist", ".eslintrc.js"]
}
2 changes: 2 additions & 0 deletions packages/client/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ module.exports = {
rules: {
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'prettier/prettier': 'error',
'@next/next/no-html-link-for-pages': 'off',
},
}
3 changes: 1 addition & 2 deletions packages/client/src/app/admin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import SubmissionCard from '@/components/submission/AdminSubmissionCard'
import { getAllSubmissions } from '@/network/getAllSubmissions'

Expand All @@ -14,7 +13,7 @@ export default async function Page() {
<h1>
<span className='italic'>zs</span>admin
</h1>
<div className='flex flex-wrap px-4 justify-center gap-4'>
<div className='flex flex-wrap justify-center gap-4 px-4'>
{submissions.map(submission => (
<SubmissionCard key={submission.id} submission={submission} />
))}
Expand Down
12 changes: 6 additions & 6 deletions packages/client/src/app/api/favorites/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NextResponse } from "next/server";
import { NextResponse } from 'next/server'

import { deleteFavorite } from "@/network/deleteFavorite";
import { deleteFavorite } from '@/network/deleteFavorite'

export async function DELETE(req: Request, { params } : { params: { id: string }} ) {
await deleteFavorite(params.id)
return NextResponse.json("Unfavorited")
}
export async function DELETE(req: Request, { params }: { params: { id: string } }) {
await deleteFavorite(params.id)
return NextResponse.json('Unfavorited')
}
3 changes: 3 additions & 0 deletions packages/client/src/app/api/profile/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { NextResponse } from 'next/server'

export const dynamic = 'force-dynamic'

import { getProfile } from '@/network/getProfile'

export async function GET() {
const profile = await getProfile()

return NextResponse.json(profile)
}
1 change: 0 additions & 1 deletion packages/client/src/app/authorized/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ export async function GET(request: NextRequest) {

return NextResponse.redirect(new URL('/', request.url))
}

2 changes: 2 additions & 0 deletions packages/client/src/app/collections/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import CollectionLinksContainer from '@/components/links/CollectionLinksContainer'
import api from '@/network/apiSetup'

export const dynamic = 'force-dynamic'

export default async function CollectionPage({ params }: { params: { id: string } }) {
const fetchData = async () => {
const response = await api('/collection/' + params.id)
Expand Down
2 changes: 2 additions & 0 deletions packages/client/src/app/collections/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import CollectionsContainer from '@/components/collection/CollectionsContainer'
import { getCollections } from '@/network/getCollections'

export const dynamic = 'force-dynamic'

export default async function Collections() {
const collectionsData = await getCollections()

Expand Down
Loading

0 comments on commit 0012395

Please sign in to comment.