diff --git a/.eslintrc.ci.js b/.eslintrc.ci.js new file mode 100644 index 00000000..6696dbe4 --- /dev/null +++ b/.eslintrc.ci.js @@ -0,0 +1,28 @@ +const baseConfig = require('./.eslintrc.js') + +module.exports = { + ...baseConfig, + overrides: [ + { + ...baseConfig.overrides[0], + extends: [ + 'plugin:@typescript-eslint/strict-type-checked', + 'plugin:import/typescript', + ], + parser: '@typescript-eslint/parser', + parserOptions: { + project: true, + tsconfigRootDir: __dirname, + }, + rules: { + ...baseConfig.overrides[0].rules, + '@typescript-eslint/restrict-template-expressions': [ + 'error', + { allowNever: true }, + ], + }, + reportUnusedDisableDirectives: false, + }, + ...baseConfig.overrides.slice(1), + ], +} diff --git a/.eslintrc.js b/.eslintrc.js index 0ffe501d..55f86b8d 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -177,15 +177,11 @@ module.exports = { files: ['**/*.ts', '**/*.tsx'], env: { browser: true, es6: true, node: true }, extends: [ - 'plugin:@typescript-eslint/strict-type-checked', + 'plugin:@typescript-eslint/strict', 'plugin:import/typescript', ], globals: { Atomics: 'readonly', SharedArrayBuffer: 'readonly' }, parser: '@typescript-eslint/parser', - parserOptions: { - project: true, - tsconfigRootDir: __dirname, - }, plugins: ['@typescript-eslint'], rules: { // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules @@ -217,16 +213,14 @@ module.exports = { '@typescript-eslint/no-confusing-void-expression': 'off', '@typescript-eslint/no-unnecessary-condition': 'off', '@typescript-eslint/no-var-requires': 'off', - '@typescript-eslint/restrict-template-expressions': [ - 'error', - { allowNever: true }, - ], + '@typescript-eslint/no-unsafe-enum-comparison': 'off', '@typescript-eslint/no-invalid-void-type': 'off', '@typescript-eslint/unbound-method': 'off', '@typescript-eslint/no-dynamic-delete': 'off', '@typescript-eslint/no-unsafe-member-access': 'off', }, + reportUnusedDisableDirectives: false, settings: { 'import/resolver': { node: true, diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1d2c2fe3..24718488 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,7 +11,6 @@ jobs: test: runs-on: ubuntu-latest - # This job uses a matrix strategy to run the job four times, once for each specified Node version. For more information, see "[AUTOTITLE](/actions/using-jobs/using-a-matrix-for-your-jobs)." strategy: matrix: node-version: [16.x, 18.x, 20.x] @@ -33,5 +32,5 @@ jobs: - name: 'ESLint' env: NODE_OPTIONS: "--max_old_space_size=4096" - run: pnpm run lint + run: pnpm run lint:ci - run: pnpm run test:all \ No newline at end of file diff --git a/.lintstagedrc.cjs b/.lintstagedrc.cjs index 941e1459..51521972 100644 --- a/.lintstagedrc.cjs +++ b/.lintstagedrc.cjs @@ -1,6 +1,7 @@ const path = require('path') const packagesDir = path.join(__dirname, 'packages') +const eslintCiConfig = path.join(__dirname, '.eslintrc.ci.js') module.exports = { '*.{js,jsx,ts,tsx}': (filenames) => { @@ -13,7 +14,7 @@ module.exports = { return [ `prettier --write ${filenames.join(' ')}`, - `eslint --fix ${filenames.join(' ')}`, + `eslint -c ${eslintCiConfig} --fix ${filenames.join(' ')}`, ...[...modifiedPackages].map((pkg) => `pnpm -C packages/${pkg} run --if-present build --noEmit`) ] } diff --git a/package.json b/package.json index 26509876..bc777fd1 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "postinstall": "node scripts/validate-deps-versions.mjs", "test:all": "pnpm run -r test", "lint": "eslint .", + "lint:ci": "eslint --config .eslintrc.ci.js .", "lint:tsc": "pnpm run -r build --noEmit", "lint:fix": "eslint --fix .", "format": "prettier --write \"packages/**/*.ts\"", diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index 58f7daaa..495a6f19 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -2124,13 +2124,11 @@ export interface TelegramClient extends BaseTelegramClient { * Approve or deny multiple join requests to a chat. * * @param peer Chat/channel ID - * @param user User ID * @param action Whether to approve or deny the join requests * @param link Invite link to target */ hideAllJoinRequests( peer: InputPeerLike, - user: InputPeerLike, action: 'approve' | 'deny', link?: string ): Promise diff --git a/packages/client/src/methods/.eslintrc.js b/packages/client/src/methods/.eslintrc.js deleted file mode 100644 index 0e5cc81a..00000000 --- a/packages/client/src/methods/.eslintrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - rules: { - // common when using preprocessor directives - '@typescript-eslint/no-unused-vars': 'off', - }, -} diff --git a/packages/client/src/methods/_imports.ts b/packages/client/src/methods/_imports.ts index d885368b..2a26803c 100644 --- a/packages/client/src/methods/_imports.ts +++ b/packages/client/src/methods/_imports.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ // @copy import { Readable } from 'stream' diff --git a/packages/client/src/methods/auth/_initialize.ts b/packages/client/src/methods/auth/_initialize.ts index 4294b5d8..4f8bb19d 100644 --- a/packages/client/src/methods/auth/_initialize.ts +++ b/packages/client/src/methods/auth/_initialize.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { TelegramClient } from '../../client' // @extension diff --git a/packages/client/src/methods/bots/get-bot-menu-button.ts b/packages/client/src/methods/bots/get-bot-menu-button.ts index da7559ac..92f4c7ee 100644 --- a/packages/client/src/methods/bots/get-bot-menu-button.ts +++ b/packages/client/src/methods/bots/get-bot-menu-button.ts @@ -1,7 +1,7 @@ import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /** diff --git a/packages/client/src/methods/bots/normalize-command-scope.ts b/packages/client/src/methods/bots/normalize-command-scope.ts index b009a04f..2e3bc50b 100644 --- a/packages/client/src/methods/bots/normalize-command-scope.ts +++ b/packages/client/src/methods/bots/normalize-command-scope.ts @@ -2,7 +2,7 @@ import { assertNever } from '@mtcute/core' import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { BotCommands, MtInvalidPeerTypeError } from '../../types' +import { BotCommands } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /** @internal */ diff --git a/packages/client/src/methods/bots/set-bot-menu-button.ts b/packages/client/src/methods/bots/set-bot-menu-button.ts index daf0c64c..fbbe005f 100644 --- a/packages/client/src/methods/bots/set-bot-menu-button.ts +++ b/packages/client/src/methods/bots/set-bot-menu-button.ts @@ -1,7 +1,7 @@ import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /** diff --git a/packages/client/src/methods/bots/set-game-score.ts b/packages/client/src/methods/bots/set-game-score.ts index 2ff10503..67eb6f37 100644 --- a/packages/client/src/methods/bots/set-game-score.ts +++ b/packages/client/src/methods/bots/set-game-score.ts @@ -1,7 +1,7 @@ import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike, Message } from '../../types' import { normalizeInlineId } from '../../utils/inline-utils' import { normalizeToInputUser } from '../../utils/peer-utils' diff --git a/packages/client/src/methods/chats/delete-channel.ts b/packages/client/src/methods/chats/delete-channel.ts index 58b88d6f..b850fed5 100644 --- a/packages/client/src/methods/chats/delete-channel.ts +++ b/packages/client/src/methods/chats/delete-channel.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputChannel } from '../../utils/peer-utils' // @alias=deleteSupergroup @@ -15,7 +15,10 @@ export async function deleteChannel( ): Promise { const res = await this.call({ _: 'channels.deleteChannel', - channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId), + channel: normalizeToInputChannel( + await this.resolvePeer(chatId), + chatId, + ), }) this._handleUpdate(res) } diff --git a/packages/client/src/methods/chats/delete-history.ts b/packages/client/src/methods/chats/delete-history.ts index a2828696..1993f22a 100644 --- a/packages/client/src/methods/chats/delete-history.ts +++ b/packages/client/src/methods/chats/delete-history.ts @@ -1,8 +1,6 @@ -import { tl } from '@mtcute/tl' - import { TelegramClient } from '../../client' import { InputPeerLike } from '../../types' -import { isInputPeerChannel, normalizeToInputChannel } from '../../utils/peer-utils' +import { isInputPeerChannel } from '../../utils/peer-utils' import { createDummyUpdate } from '../../utils/updates-utils' /** @@ -38,11 +36,7 @@ export async function deleteHistory( if (isInputPeerChannel(peer)) { this._handleUpdate( - createDummyUpdate( - res.pts, - res.ptsCount, - peer.channelId, - ), + createDummyUpdate(res.pts, res.ptsCount, peer.channelId), ) } else { this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount)) diff --git a/packages/client/src/methods/chats/delete-user-history.ts b/packages/client/src/methods/chats/delete-user-history.ts index 6998f047..f887dc6a 100644 --- a/packages/client/src/methods/chats/delete-user-history.ts +++ b/packages/client/src/methods/chats/delete-user-history.ts @@ -1,7 +1,7 @@ import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputChannel } from '../../utils/peer-utils' import { createDummyUpdate } from '../../utils/updates-utils' @@ -17,7 +17,10 @@ export async function deleteUserHistory( chatId: InputPeerLike, participantId: InputPeerLike, ): Promise { - const channel = normalizeToInputChannel(await this.resolvePeer(chatId), chatId) + const channel = normalizeToInputChannel( + await this.resolvePeer(chatId), + chatId, + ) const peer = await this.resolvePeer(participantId) diff --git a/packages/client/src/methods/chats/edit-admin-rights.ts b/packages/client/src/methods/chats/edit-admin-rights.ts index 3924a3ff..42d80791 100644 --- a/packages/client/src/methods/chats/edit-admin-rights.ts +++ b/packages/client/src/methods/chats/edit-admin-rights.ts @@ -1,7 +1,7 @@ import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputChannel, normalizeToInputUser, diff --git a/packages/client/src/methods/chats/join-chat.ts b/packages/client/src/methods/chats/join-chat.ts index 5a6c6531..3a438521 100644 --- a/packages/client/src/methods/chats/join-chat.ts +++ b/packages/client/src/methods/chats/join-chat.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { Chat, InputPeerLike, MtPeerNotFoundError } from '../../types' +import { Chat, InputPeerLike } from '../../types' import { INVITE_LINK_REGEX, normalizeToInputChannel, diff --git a/packages/client/src/methods/chats/set-chat-username.ts b/packages/client/src/methods/chats/set-chat-username.ts index 0ad76a64..a18d7864 100644 --- a/packages/client/src/methods/chats/set-chat-username.ts +++ b/packages/client/src/methods/chats/set-chat-username.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputChannel } from '../../utils/peer-utils' /** @@ -18,7 +18,10 @@ export async function setChatUsername( ): Promise { await this.call({ _: 'channels.updateUsername', - channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId), + channel: normalizeToInputChannel( + await this.resolvePeer(chatId), + chatId, + ), username: username || '', }) } diff --git a/packages/client/src/methods/chats/set-slow-mode.ts b/packages/client/src/methods/chats/set-slow-mode.ts index ef5fbd12..62cf7d27 100644 --- a/packages/client/src/methods/chats/set-slow-mode.ts +++ b/packages/client/src/methods/chats/set-slow-mode.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputChannel } from '../../utils/peer-utils' /** @@ -19,7 +19,10 @@ export async function setSlowMode( ): Promise { const res = await this.call({ _: 'channels.toggleSlowMode', - channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId), + channel: normalizeToInputChannel( + await this.resolvePeer(chatId), + chatId, + ), seconds, }) this._handleUpdate(res) diff --git a/packages/client/src/methods/contacts/add-contact.ts b/packages/client/src/methods/contacts/add-contact.ts index f1cd1b14..576ad867 100644 --- a/packages/client/src/methods/contacts/add-contact.ts +++ b/packages/client/src/methods/contacts/add-contact.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types' +import { InputPeerLike, User } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' import { assertIsUpdatesGroup } from '../../utils/updates-utils' diff --git a/packages/client/src/methods/dialogs/_init-conversation.ts b/packages/client/src/methods/dialogs/_init-conversation.ts index 60b69c4d..de0a4023 100644 --- a/packages/client/src/methods/dialogs/_init-conversation.ts +++ b/packages/client/src/methods/dialogs/_init-conversation.ts @@ -1,4 +1,4 @@ -/* eslint-disable dot-notation */ +/* eslint-disable @typescript-eslint/no-unused-vars, dot-notation */ import { getMarkedPeerId } from '@mtcute/core' import { TelegramClient } from '../../client' diff --git a/packages/client/src/methods/invite-links/hide-all-join-requests.ts b/packages/client/src/methods/invite-links/hide-all-join-requests.ts index 57450611..9f8f5167 100644 --- a/packages/client/src/methods/invite-links/hide-all-join-requests.ts +++ b/packages/client/src/methods/invite-links/hide-all-join-requests.ts @@ -1,12 +1,10 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' -import { normalizeToInputUser } from '../../utils/peer-utils' +import { InputPeerLike } from '../../types' /** * Approve or deny multiple join requests to a chat. * * @param peer Chat/channel ID - * @param user User ID * @param action Whether to approve or deny the join requests * @param link Invite link to target * @internal @@ -14,12 +12,9 @@ import { normalizeToInputUser } from '../../utils/peer-utils' export async function hideAllJoinRequests( this: TelegramClient, peer: InputPeerLike, - user: InputPeerLike, action: 'approve' | 'deny', link?: string, ): Promise { - const userId = normalizeToInputUser(await this.resolvePeer(user), user) - await this.call({ _: 'messages.hideAllChatJoinRequests', approved: action === 'approve', diff --git a/packages/client/src/methods/invite-links/hide-join-request.ts b/packages/client/src/methods/invite-links/hide-join-request.ts index 78c3ba84..885796c2 100644 --- a/packages/client/src/methods/invite-links/hide-join-request.ts +++ b/packages/client/src/methods/invite-links/hide-join-request.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { InputPeerLike } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /** diff --git a/packages/client/src/methods/messages/send-media-group.ts b/packages/client/src/methods/messages/send-media-group.ts index 1ab47520..a1a8054f 100644 --- a/packages/client/src/methods/messages/send-media-group.ts +++ b/packages/client/src/methods/messages/send-media-group.ts @@ -4,13 +4,11 @@ import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' import { - BotKeyboard, InputMediaLike, InputPeerLike, Message, MtMessageNotFoundError, PeersIndex, - ReplyMarkup, } from '../../types' import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils' import { assertIsUpdatesGroup } from '../../utils/updates-utils' diff --git a/packages/client/src/methods/messages/send-vote.ts b/packages/client/src/methods/messages/send-vote.ts index d644b386..629ce691 100644 --- a/packages/client/src/methods/messages/send-vote.ts +++ b/packages/client/src/methods/messages/send-vote.ts @@ -5,7 +5,6 @@ import { MtTypeAssertionError, } from '@mtcute/core' import { assertTypeIs } from '@mtcute/core/utils' -import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' import { diff --git a/packages/client/src/methods/parse-modes/_initialize.ts b/packages/client/src/methods/parse-modes/_initialize.ts index 2e2f3e83..bbc4ae1d 100644 --- a/packages/client/src/methods/parse-modes/_initialize.ts +++ b/packages/client/src/methods/parse-modes/_initialize.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { TelegramClient } from '../../client' import { IMessageEntityParser } from '../../types' @@ -12,6 +13,3 @@ function _initializeParseModes(this: TelegramClient) { this._parseModes = new Map() this._defaultParseMode = null } - -// since IMessageEntityParser is copied here, we don't need to -// worry about marking it with @copy anywhere else. diff --git a/packages/client/src/methods/updates.ts b/packages/client/src/methods/updates.ts index 76b83392..f606213e 100644 --- a/packages/client/src/methods/updates.ts +++ b/packages/client/src/methods/updates.ts @@ -41,6 +41,7 @@ interface PendingUpdate { peers?: PeersIndex } +/* eslint-disable @typescript-eslint/no-unused-vars */ // @extension interface UpdatesState { _updatesLoopActive: boolean @@ -82,6 +83,7 @@ interface UpdatesState { _updsLog: Logger } +/* eslint-enable @typescript-eslint/no-unused-vars */ // @initialize function _initializeUpdates(this: TelegramClient) { @@ -660,6 +662,7 @@ function _isMessageEmpty(upd: tl.TypeUpdate): boolean { export function _handleUpdate( this: TelegramClient, update: tl.TypeUpdates, + // eslint-disable-next-line @typescript-eslint/no-unused-vars noDispatch = false, // fixme ): void { this._updsLog.debug( @@ -826,8 +829,6 @@ async function _fetchChannelDifference( limit = 1 } - let isFirst = true - for (;;) { const diff = await this.call( { @@ -840,7 +841,6 @@ async function _fetchChannelDifference( }, // { flush: !isFirst } ) - isFirst = false if (diff._ === 'updates.channelDifferenceEmpty') { this._updsLog.debug( diff --git a/packages/client/src/methods/users/get-common-chats.ts b/packages/client/src/methods/users/get-common-chats.ts index 3713f46e..3e91340f 100644 --- a/packages/client/src/methods/users/get-common-chats.ts +++ b/packages/client/src/methods/users/get-common-chats.ts @@ -1,5 +1,5 @@ import { TelegramClient } from '../../client' -import { Chat, InputPeerLike, MtInvalidPeerTypeError } from '../../types' +import { Chat, InputPeerLike } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /** diff --git a/packages/client/src/methods/users/get-profile-photos.ts b/packages/client/src/methods/users/get-profile-photos.ts index e63273c6..3250ff8b 100644 --- a/packages/client/src/methods/users/get-profile-photos.ts +++ b/packages/client/src/methods/users/get-profile-photos.ts @@ -3,7 +3,7 @@ import Long from 'long' import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError, Photo } from '../../types' +import { InputPeerLike, Photo } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /** diff --git a/packages/client/src/methods/users/iter-profile-photos.ts b/packages/client/src/methods/users/iter-profile-photos.ts index eb19699e..42653bcd 100644 --- a/packages/client/src/methods/users/iter-profile-photos.ts +++ b/packages/client/src/methods/users/iter-profile-photos.ts @@ -3,7 +3,7 @@ import Long from 'long' import { tl } from '@mtcute/tl' import { TelegramClient } from '../../client' -import { InputPeerLike, MtInvalidPeerTypeError, Photo } from '../../types' +import { InputPeerLike, Photo } from '../../types' import { normalizeToInputUser } from '../../utils/peer-utils' /**