refactor(backend): lint @typescript-eslint/strict (#8408)

* lint @typescript-eslint/recommended

* lint @typescript-eslint/recommended-requiring-type-checking

fix type not detected locally due to wierd uuid typings

missing save

error not reported locally

* lint @typescript-eslint/strict

---------

Co-authored-by: Wolfgang Huß <wolle.huss@pjannto.com>
This commit is contained in:
Ulf Gebhardt 2025-04-21 13:09:47 +02:00 committed by GitHub
parent b464a380ca
commit 5131752710
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 29 additions and 28 deletions

View File

@ -181,7 +181,7 @@ module.exports = {
extends: [ extends: [
'plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking', 'plugin:@typescript-eslint/recommended-requiring-type-checking',
// 'plugin:@typescript-eslint/strict', 'plugin:@typescript-eslint/strict',
'prettier', 'prettier',
], ],
rules: { rules: {

View File

@ -19,7 +19,7 @@ import { pubsub, NOTIFICATION_ADDED, ROOM_COUNT_UPDATED, CHAT_MESSAGE_ADDED } fr
import extractMentionedUsers from './mentions/extractMentionedUsers' import extractMentionedUsers from './mentions/extractMentionedUsers'
const queryNotificationEmails = async (context, notificationUserIds) => { const queryNotificationEmails = async (context, notificationUserIds) => {
if (!(notificationUserIds && notificationUserIds.length)) return [] if (!notificationUserIds?.length) return []
const userEmailCypher = ` const userEmailCypher = `
MATCH (user: User) MATCH (user: User)
// blocked users are filtered out from notifications already // blocked users are filtered out from notifications already
@ -360,7 +360,7 @@ const notifyMemberOfGroup = async (groupId, userId, reason, context) => {
} }
const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => { const notifyUsersOfMention = async (label, id, idsOfUsers, reason, context) => {
if (!(idsOfUsers && idsOfUsers.length)) return [] if (!idsOfUsers?.length) return []
await validateNotifyUsers(label, reason) await validateNotifyUsers(label, reason)
let mentionedCypher let mentionedCypher
switch (reason) { switch (reason) {

View File

@ -18,7 +18,7 @@ const neode = getNeode()
const isAuthenticated = rule({ const isAuthenticated = rule({
cache: 'contextual', cache: 'contextual',
})(async (_parent, _args, ctx, _info) => { })(async (_parent, _args, ctx, _info) => {
return !!(ctx && ctx.user && ctx.user.id) return !!ctx?.user?.id
}) })
const isModerator = rule()(async (_parent, _args, { user }, _info) => { const isModerator = rule()(async (_parent, _args, { user }, _info) => {
@ -62,7 +62,7 @@ const isMySocialMedia = rule({
const isAllowedToChangeGroupSettings = rule({ const isAllowedToChangeGroupSettings = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const ownerId = user.id const ownerId = user.id
const { id: groupId } = args const { id: groupId } = args
const session = driver.session() const session = driver.session()
@ -92,7 +92,7 @@ const isAllowedToChangeGroupSettings = rule({
const isAllowedSeeingGroupMembers = rule({ const isAllowedSeeingGroupMembers = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const { id: groupId } = args const { id: groupId } = args
const session = driver.session() const session = driver.session()
const readTxPromise = session.readTransaction(async (transaction) => { const readTxPromise = session.readTransaction(async (transaction) => {
@ -128,7 +128,7 @@ const isAllowedSeeingGroupMembers = rule({
const isAllowedToChangeGroupMemberRole = rule({ const isAllowedToChangeGroupMemberRole = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const currentUserId = user.id const currentUserId = user.id
const { groupId, userId, roleInGroup } = args const { groupId, userId, roleInGroup } = args
if (currentUserId === userId) return false if (currentUserId === userId) return false
@ -175,7 +175,7 @@ const isAllowedToChangeGroupMemberRole = rule({
const isAllowedToJoinGroup = rule({ const isAllowedToJoinGroup = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const { groupId, userId } = args const { groupId, userId } = args
const session = driver.session() const session = driver.session()
const readTxPromise = session.readTransaction(async (transaction) => { const readTxPromise = session.readTransaction(async (transaction) => {
@ -205,7 +205,7 @@ const isAllowedToJoinGroup = rule({
const isAllowedToLeaveGroup = rule({ const isAllowedToLeaveGroup = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const { groupId, userId } = args const { groupId, userId } = args
if (user.id !== userId) return false if (user.id !== userId) return false
const session = driver.session() const session = driver.session()
@ -235,7 +235,7 @@ const isAllowedToLeaveGroup = rule({
const isMemberOfGroup = rule({ const isMemberOfGroup = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const { groupId } = args const { groupId } = args
if (!groupId) return true if (!groupId) return true
const userId = user.id const userId = user.id
@ -263,7 +263,7 @@ const isMemberOfGroup = rule({
const canRemoveUserFromGroup = rule({ const canRemoveUserFromGroup = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const { groupId, userId } = args const { groupId, userId } = args
const currentUserId = user.id const currentUserId = user.id
if (currentUserId === userId) return false if (currentUserId === userId) return false
@ -299,7 +299,7 @@ const canRemoveUserFromGroup = rule({
const canCommentPost = rule({ const canCommentPost = rule({
cache: 'no_cache', cache: 'no_cache',
})(async (_parent, args, { user, driver }) => { })(async (_parent, args, { user, driver }) => {
if (!(user && user.id)) return false if (!user?.id) return false
const { postId } = args const { postId } = args
const userId = user.id const userId = user.id
const session = driver.session() const session = driver.session()

View File

@ -21,7 +21,7 @@ if (CONFIG.SENTRY_DSN_BACKEND) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
withScope: (scope, error, context: any) => { withScope: (scope, error, context: any) => {
scope.setUser({ scope.setUser({
id: context.user && context.user.id, id: context.user?.id,
}) })
scope.setExtra('body', context.req.body) scope.setExtra('body', context.req.body)
scope.setExtra('origin', context.req.headers.origin) scope.setExtra('origin', context.req.headers.origin)

View File

@ -87,7 +87,7 @@ const validateReview = async (resolve, root, args, context, info) => {
try { try {
const txResult = await reportReadTxPromise const txResult = await reportReadTxPromise
existingReportedResource = txResult existingReportedResource = txResult
if (!existingReportedResource || !existingReportedResource.length) if (!existingReportedResource?.length)
throw new Error(`Resource not found or is not a Post|Comment|User!`) throw new Error(`Resource not found or is not a Post|Comment|User!`)
existingReportedResource = existingReportedResource[0] existingReportedResource = existingReportedResource[0]
if (!existingReportedResource.filed) if (!existingReportedResource.filed)

View File

@ -48,7 +48,7 @@ export default {
// check email does not belong to anybody // check email does not belong to anybody
const existingEmail = await existingEmailAddress({ args, context }) const existingEmail = await existingEmailAddress({ args, context })
if (existingEmail && existingEmail.alreadyExistingEmail && existingEmail.user) if (existingEmail?.alreadyExistingEmail && existingEmail.user)
return existingEmail.alreadyExistingEmail return existingEmail.alreadyExistingEmail
const nonce = generateNonce() const nonce = generateNonce()

View File

@ -2429,7 +2429,7 @@ describe('in mode', () => {
id: groupId, id: groupId,
}, },
}) })
return result.data && result.data.GroupMembers return result.data?.GroupMembers
? !!result.data.GroupMembers.find((member) => member.id === userId) ? !!result.data.GroupMembers.find((member) => member.id === userId)
: null : null
} }

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-dynamic-delete */
/* eslint-disable @typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/require-await */
/* eslint-disable @typescript-eslint/no-unsafe-argument */ /* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable @typescript-eslint/restrict-template-expressions */

View File

@ -22,7 +22,7 @@ export const validateEventParams = (params) => {
throw new UserInputError('Event venue must be present if event location is given!') throw new UserInputError('Event venue must be present if event location is given!')
} }
params.eventVenue = eventInput.eventVenue params.eventVenue = eventInput.eventVenue
params.eventLocationName = eventInput.eventLocationName && eventInput.eventLocationName.trim() params.eventLocationName = eventInput.eventLocationName?.trim()
if (params.eventLocationName) { if (params.eventLocationName) {
locationName = params.eventLocationName locationName = params.eventLocationName
} else { } else {

View File

@ -9,7 +9,7 @@ const getInvisiblePosts = async (context) => {
const readTxResultPromise = await session.readTransaction(async (transaction) => { const readTxResultPromise = await session.readTransaction(async (transaction) => {
let cypher = '' let cypher = ''
const { user } = context const { user } = context
if (user && user.id) { if (user?.id) {
cypher = ` cypher = `
MATCH (post:Post)<-[:CANNOT_SEE]-(user:User { id: $userId }) MATCH (post:Post)<-[:CANNOT_SEE]-(user:User { id: $userId })
RETURN collect(post.id) AS invisiblePostIds` RETURN collect(post.id) AS invisiblePostIds`

View File

@ -6,7 +6,7 @@ import { mergeWith, isArray } from 'lodash'
const getMyGroupIds = async (context) => { const getMyGroupIds = async (context) => {
const { user } = context const { user } = context
if (!(user && user.id)) return [] if (!user?.id) return []
const session = context.driver.session() const session = context.driver.session()
const readTxResultPromise = await session.readTransaction(async (transaction) => { const readTxResultPromise = await session.readTransaction(async (transaction) => {
@ -26,7 +26,7 @@ const getMyGroupIds = async (context) => {
} }
export const filterPostsOfMyGroups = async (params, context) => { export const filterPostsOfMyGroups = async (params, context) => {
if (!(params.filter && params.filter.postsInMyGroups)) return params if (!params.filter?.postsInMyGroups) return params
delete params.filter.postsInMyGroups delete params.filter.postsInMyGroups
const myGroupIds = await getMyGroupIds(context) const myGroupIds = await getMyGroupIds(context)
params.filter = mergeWith( params.filter = mergeWith(

View File

@ -47,7 +47,7 @@ export default {
) )
}) })
const [reset] = await passwordResetTxPromise const [reset] = await passwordResetTxPromise
return !!(reset && reset.properties.usedAt) return !!reset?.properties.usedAt
} finally { } finally {
session.close() session.close()
} }

View File

@ -49,7 +49,7 @@ export default {
) { ) {
delete currentUser.encryptedPassword delete currentUser.encryptedPassword
return encode(currentUser) return encode(currentUser)
} else if (currentUser && currentUser.disabled) { } else if (currentUser?.disabled) {
throw new AuthenticationError('Your account has been disabled.') throw new AuthenticationError('Your account has been disabled.')
} else { } else {
throw new AuthenticationError('Incorrect email address or password.') throw new AuthenticationError('Incorrect email address or password.')

View File

@ -228,7 +228,7 @@ export default {
const session = context.driver.session() const session = context.driver.session()
const deleteUserTxResultPromise = session.writeTransaction(async (transaction) => { const deleteUserTxResultPromise = session.writeTransaction(async (transaction) => {
if (resource && resource.length) { if (resource?.length) {
await Promise.all( await Promise.all(
resource.map(async (node) => { resource.map(async (node) => {
const txResult = await transaction.run( const txResult = await transaction.run(

View File

@ -47,8 +47,8 @@ const createLocation = async (session, mapboxData) => {
nameRU: mapboxData.text_ru, nameRU: mapboxData.text_ru,
type: mapboxData.id.split('.')[0].toLowerCase(), type: mapboxData.id.split('.')[0].toLowerCase(),
address: mapboxData.address, address: mapboxData.address,
lng: mapboxData.center && mapboxData.center.length ? mapboxData.center[0] : null, lng: mapboxData.center?.length ? mapboxData.center[0] : null,
lat: mapboxData.center && mapboxData.center.length ? mapboxData.center[1] : null, lat: mapboxData.center?.length ? mapboxData.center[1] : null,
} }
let mutation = let mutation =
@ -95,7 +95,7 @@ export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, s
debug(res) debug(res)
if (!res || !res.features || !res.features[0]) { if (!res?.features?.[0]) {
throw new UserInputError('locationName is invalid') throw new UserInputError('locationName is invalid')
} }
@ -110,7 +110,7 @@ export const createOrUpdateLocations = async (nodeLabel, nodeId, locationName, s
data = res.features[0] data = res.features[0]
} }
if (!data || !data.place_type || !data.place_type.length) { if (!data?.place_type?.length) {
throw new UserInputError('locationName is invalid') throw new UserInputError('locationName is invalid')
} }
@ -172,7 +172,7 @@ export const queryLocations = async ({ place, lang }) => {
`https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${CONFIG.MAPBOX_TOKEN}&types=region,place,country&language=${lang}`, `https://api.mapbox.com/geocoding/v5/mapbox.places/${place}.json?access_token=${CONFIG.MAPBOX_TOKEN}&types=region,place,country&language=${lang}`,
) )
// Return empty array if no location found or error occurred // Return empty array if no location found or error occurred
if (!res || !res.features) { if (!res?.features) {
return [] return []
} }
return res.features return res.features