Skip to content

Commit

Permalink
Update eslint config to v9
Browse files Browse the repository at this point in the history
  • Loading branch information
VerHde committed Jul 25, 2024
1 parent 6a53c27 commit dde8005
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 29 deletions.
19 changes: 0 additions & 19 deletions .eslintrc.yaml

This file was deleted.

54 changes: 54 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import typescriptEslint from '@typescript-eslint/eslint-plugin'
import prettier from 'eslint-plugin-prettier'
import globals from 'globals'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
import { FlatCompat } from '@eslint/eslintrc'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
})

export default [
...compat
.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier'
)
.map((config) => ({
...config,
files: ['src/**/*.ts'],
})),
{
files: ['src/**/*.ts'],

plugins: {
'@typescript-eslint': typescriptEslint,
prettier,
},

languageOptions: {
globals: {
...globals.node,
...globals.mocha,
},

ecmaVersion: 2022,
sourceType: 'module',

parserOptions: {
parser: '@typescript-eslint/parser',
},
},

rules: {
'prettier/prettier': ['warn'],
},
},
]
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"scripts": {
"format": "prettier . --check --ignore-unknown",
"format-fix": "prettier . --write --ignore-unknown",
"lint": "eslint src/ --ext .ts --max-warnings 0",
"lint-fix": "eslint src/ --fix --ext .ts",
"lint": "eslint --max-warnings 0",
"lint-fix": "eslint --fix",
"prefix": "npm run format-fix",
"fix": "npm run lint-fix",
"test": "rm -rf dist/ && jest",
Expand Down
3 changes: 1 addition & 2 deletions src/handlers/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
process.env.AS_TOKEN = 'ApplicationSecretToken'
process.env.EXCLUDED_USERS = 'excludedUser1,excludedUser2'
import { afterEach, expect, jest, test } from '@jest/globals'
import axios from 'axios'
import { IdMapping } from '../entity/IdMapping'
import log from '../helpers/logger'
import * as storage from '../helpers/storage'
Expand All @@ -18,7 +17,7 @@ import * as synapse from '../helpers/synapse'

jest.mock('../helpers/synapse')
const mockedSynapse = synapse as jest.Mocked<typeof synapse>
const mockedAxios = mockedSynapse.axios as jest.Mocked<typeof axios>
const mockedAxios = mockedSynapse.axios as jest.Mocked<typeof synapse.axios>

jest.mock('../helpers/storage')
const mockedStorage = storage as jest.Mocked<typeof storage>
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/messagesHandlingReactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ test('handling reactions: duplicate reaction error', async () => {
switch (username) {
case 'testuser':
case 'duplicator':
case 'breaker':
case 'breaker': {
const idMapping = new IdMapping()
idMapping.rcId = 'rcId-' + username
idMapping.matrixId = username
idMapping.type = 0
idMapping.accessToken = username
return idMapping
}
}
return null
}
Expand Down
14 changes: 9 additions & 5 deletions src/handlers/rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ export function mapRoom(rcRoom: RcRoom): MatrixRoom {
room.name = rcRoom.fname || rcRoom.name
room.room_alias_name = rcRoom.fname || rcRoom.name
}
rcRoom.description && (room.topic = rcRoom.description)
if (rcRoom.description) {
room.topic = rcRoom.description
}

switch (rcRoom.t) {
case RcRoomTypes.direct:
if (rcRoom.usersCount == 1) {
rcRoom.lastMessage && (room.name = rcRoom.lastMessage.u.name)
if (rcRoom.usersCount == 1 && rcRoom.lastMessage) {
room.name = rcRoom.lastMessage.u.name
}
room.is_direct = true
room.preset = MatrixRoomPresets.trusted
Expand All @@ -113,19 +115,21 @@ export function mapRoom(rcRoom: RcRoom): MatrixRoom {
room.visibility = MatrixRoomVisibility.private
break

case RcRoomTypes.live:
case RcRoomTypes.live: {
const messageLivechat = `Room ${
rcRoom.name || 'with ID: ' + rcRoom._id
} is a live chat. Migration not implemented`
log.warn(messageLivechat)
throw new Error(messageLivechat)
}

default:
default: {
const messageUnknownRoom = `Room ${
rcRoom.name || 'with ID: ' + rcRoom._id
} is of type ${rcRoom.t}, which is unknown or unimplemented`
log.error(messageUnknownRoom)
throw new Error(messageUnknownRoom)
}
}
return room
}
Expand Down

0 comments on commit dde8005

Please sign in to comment.