ci: moved type-aware linting to pre-commit and ci

This commit is contained in:
alina 🌸 2023-09-24 01:08:01 +03:00
parent 976c25141c
commit fbe264aab0
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
31 changed files with 76 additions and 63 deletions

28
.eslintrc.ci.js Normal file
View file

@ -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),
],
}

View file

@ -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,

View file

@ -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

View file

@ -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`)
]
}

View file

@ -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\"",

View file

@ -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<void>

View file

@ -1,6 +0,0 @@
module.exports = {
rules: {
// common when using preprocessor directives
'@typescript-eslint/no-unused-vars': 'off',
},
}

View file

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
// @copy
import { Readable } from 'stream'

View file

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { TelegramClient } from '../../client'
// @extension

View file

@ -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'
/**

View file

@ -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 */

View file

@ -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'
/**

View file

@ -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'

View file

@ -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<void> {
const res = await this.call({
_: 'channels.deleteChannel',
channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId),
channel: normalizeToInputChannel(
await this.resolvePeer(chatId),
chatId,
),
})
this._handleUpdate(res)
}

View file

@ -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))

View file

@ -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<void> {
const channel = normalizeToInputChannel(await this.resolvePeer(chatId), chatId)
const channel = normalizeToInputChannel(
await this.resolvePeer(chatId),
chatId,
)
const peer = await this.resolvePeer(participantId)

View file

@ -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,

View file

@ -1,5 +1,5 @@
import { TelegramClient } from '../../client'
import { Chat, InputPeerLike, MtPeerNotFoundError } from '../../types'
import { Chat, InputPeerLike } from '../../types'
import {
INVITE_LINK_REGEX,
normalizeToInputChannel,

View file

@ -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<void> {
await this.call({
_: 'channels.updateUsername',
channel: normalizeToInputChannel(await this.resolvePeer(chatId), chatId),
channel: normalizeToInputChannel(
await this.resolvePeer(chatId),
chatId,
),
username: username || '',
})
}

View file

@ -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<void> {
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)

View file

@ -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'

View file

@ -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'

View file

@ -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<void> {
const userId = normalizeToInputUser(await this.resolvePeer(user), user)
await this.call({
_: 'messages.hideAllChatJoinRequests',
approved: action === 'approve',

View file

@ -1,5 +1,5 @@
import { TelegramClient } from '../../client'
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
import { InputPeerLike } from '../../types'
import { normalizeToInputUser } from '../../utils/peer-utils'
/**

View file

@ -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'

View file

@ -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 {

View file

@ -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.

View file

@ -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(

View file

@ -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'
/**

View file

@ -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'
/**

View file

@ -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'
/**