From 81f6f2fdb2b649a437b87bd0d15dc0543fe445c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Sun, 12 Jul 2026 03:44:37 +0800 Subject: [PATCH 1/3] chore: migrate lint configs --- .eslintignore | 8 -- .eslintrc.js | 92 ---------------------- .prettierrc.js | 24 ------ eslint.config.mjs | 44 +++++++++++ js/color-picker/color.ts | 2 +- js/color-picker/format.ts | 2 +- js/color-picker/gradient.ts | 4 +- js/date-picker/format.ts | 12 +-- js/date-picker/utils.ts | 14 ++-- js/image-viewer/transform.ts | 6 +- js/input-number/large-number.ts | 4 +- js/input-number/number.ts | 4 +- js/qrcode/qrcodegen.ts | 6 +- js/qrcode/utils.ts | 2 +- js/table/tree-store.ts | 20 ++--- js/table/utils.ts | 4 +- js/tree-select/utils.ts | 2 +- js/upload/main.ts | 16 ++-- js/utils/calcTextareaHeight.ts | 2 +- js/utils/general.ts | 2 +- js/utils/getPosition.ts | 2 +- js/utils/observe.ts | 4 +- js/watermark/generateBase64Url.ts | 6 +- package.json | 16 ++-- prettier.config.mjs | 1 + test/unit/input-number/number.test.js | 16 ++-- test/unit/locale/locale.test.ts | 2 +- test/unit/upload/utils.test.js | 2 +- test/unit/utils/calcTextareaHeight.test.ts | 2 +- 29 files changed, 118 insertions(+), 203 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.js delete mode 100644 .prettierrc.js create mode 100644 eslint.config.mjs create mode 100644 prettier.config.mjs diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 1eea585532..0000000000 --- a/.eslintignore +++ /dev/null @@ -1,8 +0,0 @@ -## 构建产物 -lib -public -dist -static -site -!.github -**/*/*.test.js \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index baf7f37995..0000000000 --- a/.eslintrc.js +++ /dev/null @@ -1,92 +0,0 @@ -module.exports = { - root: true, - env: { - browser: true, - node: true, - mocha: true, - jest: true, - }, - extends: [ - 'airbnb-base', - 'plugin:prettier/recommended', // 添加 Prettier 集成 - ], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint', 'import'], - // 配置小程序内全局函数,避免报错 - globals: { - require: true, - Page: true, - wx: true, - App: true, - getApp: true, - getCurrentPages: true, - Component: true, - getRegExp: true, - NodeJS: true, - }, - settings: { - 'import/resolver': { - node: {}, - }, - 'import/extensions': ['.js', '.jsx', '.ts', '.tsx'], - }, - overrides: [ - { - files: ['*.config.js', 'test/script/*'], - rules: { - 'no-console': 0, - // node 环境下支持 require - '@typescript-eslint/no-require-imports': 'off', - 'import/no-dynamic-require': 0, - }, - }, - ], - rules: { - 'no-continue': 0, - 'max-len': ['error', { code: 160, tabWidth: 2 }], - 'no-unused-vars': 0, - 'import/extensions': 0, - 'import/no-unresolved': 0, - 'import/no-named-as-default': 0, - 'import/prefer-default-export': 0, - 'import/no-extraneous-dependencies': 0, - 'default-param-last': 'off', - 'no-plusplus': [ - 'error', - { - allowForLoopAfterthoughts: true, - }, - ], - 'no-underscore-dangle': 0, - 'no-constant-condition': [ - 'error', - { - checkLoops: false, - }, - ], - 'comma-dangle': 0, - 'no-shadow': 0, - 'object-curly-newline': 0, - // 避免 `eslint` 对于 `typescript` 函数重载的误报 - 'no-redeclare': 'off', - '@typescript-eslint/no-redeclare': 'error', - 'no-use-before-define': 'off', - 'no-restricted-imports': [ - 'error', - { - paths: [ - { - name: 'lodash', - message: 'Please use lodash-es instead.', - }, - ], - patterns: [ - { - group: ['js/*'], - message: 'Importing from paths starting with "js/" is not allowed. Please use "../" instead.', - }, - ], - }, - ], - }, -}; diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index d404b0dc2d..0000000000 --- a/.prettierrc.js +++ /dev/null @@ -1,24 +0,0 @@ -module.exports = { - // 每行最大字符数 - printWidth: 120, - // 使用 2 个空格缩进 - tabWidth: 2, - // 使用空格而不是制表符 - useTabs: false, - // 语句末尾添加分号 - semi: true, - // 使用单引号 - singleQuote: true, - // 对象属性的引号使用: 仅在需要时添加引号 - quoteProps: 'as-needed', - // JSX 使用单引号 - jsxSingleQuote: true, - // 尾随逗号: es5 (对象、数组等) - trailingComma: 'es5', - // 对象字面量的括号之间打印空格 - bracketSpacing: true, - // 箭头函数单个参数时省略括号 - arrowParens: 'always', - // 换行符使用 lf - endOfLine: 'lf', -}; diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000000..89a603bbb5 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,44 @@ +import { base } from '@rss1102/eslint-config-tdesign'; + +export default [ + ...base, + { + ignores: ['lib/**', 'public/**', 'dist/**', 'static/**', 'site/**', '**/*/*.test.js'], + }, + { + files: ['**/*.{js,mjs,cjs,jsx,ts,tsx}'], + rules: { + 'no-unassigned-vars': 'off', + 'no-useless-assignment': 'off', + 'preserve-caught-error': 'off', + '@typescript-eslint/consistent-type-imports': 'off', + '@typescript-eslint/no-unused-vars': 'off', + 'simple-import-sort/exports': 'off', + 'simple-import-sort/imports': 'off', + 'no-restricted-imports': [ + 'error', + { + paths: [ + { + name: 'lodash', + message: 'Please use lodash-es instead.', + }, + ], + patterns: [ + { + group: ['js/*'], + message: 'Importing from paths starting with "js/" is not allowed. Please use "../" instead.', + }, + ], + }, + ], + }, + }, + { + files: ['*.config.js', 'test/script/*'], + rules: { + 'no-console': 'off', + '@typescript-eslint/no-require-imports': 'off', + }, + }, +]; diff --git a/js/color-picker/color.ts b/js/color-picker/color.ts index 16451127a4..5ef1f67875 100644 --- a/js/color-picker/color.ts +++ b/js/color-picker/color.ts @@ -115,7 +115,7 @@ export class Color { this.isGradient = true; const object = gradientColors as GradientColors; const points = object.points.map((c, index) => - genGradientPoint(c.left, c.color, this.gradientStates.colors[index]?.id) + genGradientPoint(c.left, c.color, this.gradientStates.colors[index]?.id), ); this.gradientStates = { colors: points, diff --git a/js/color-picker/format.ts b/js/color-picker/format.ts index b63c1d0ce0..d0c291297f 100644 --- a/js/color-picker/format.ts +++ b/js/color-picker/format.ts @@ -64,7 +64,7 @@ export const getColorFormatInputs = (format: ColorFormat = 'RGB', enableAlpha: b if (enableAlpha) { finalFormat = Object.keys(ALPHA_FORMAT_MAP).find( - (key) => key in ALPHA_FORMAT_MAP && ALPHA_FORMAT_MAP[key as AlphaConvertibleFormat] === format + (key) => key in ALPHA_FORMAT_MAP && ALPHA_FORMAT_MAP[key as AlphaConvertibleFormat] === format, ) || format; } else { finalFormat = format; diff --git a/js/color-picker/gradient.ts b/js/color-picker/gradient.ts index 8b6a2c8085..3e4cf56354 100644 --- a/js/color-picker/gradient.ts +++ b/js/color-picker/gradient.ts @@ -67,7 +67,7 @@ const generateRegExp = (): RegExpLib => { const // "red", "transparent". rColor = combineRegExp( ['(?:', rColorHex, '|', '(?:rgb|hsl)', rDigits3, '|', '(?:rgba|hsla)', rDigits4, '|', rKeyword, ')'], - '' + '', ); const rColorStop = combineRegExp([rColor, '(?:\\s+', rValue, '(?:\\s+', rValue, ')?)?'], ''); const // Single Color Stop, optional %, optional length. @@ -79,7 +79,7 @@ const generateRegExp = (): RegExpLib => { const // Capture 1:"line", 2:"angle" (optional), 3:"side corner" (optional) and 4:"stop list". rColorStopSearch = combineRegExp( ['\\s*(', rColor, ')', '(?:\\s+', '(', rValue, '))?', '(?:', rComma, '\\s*)?'], - searchFlags + searchFlags, ); // Capture 1:"color" and 2:"position" (optional). return { diff --git a/js/date-picker/format.ts b/js/date-picker/format.ts index 903fcbe2fb..86857410f0 100644 --- a/js/date-picker/format.ts +++ b/js/date-picker/format.ts @@ -26,7 +26,7 @@ export function parseToDayjs( format: string, timeOfDay?: string, dayjsLocale?: string, - defaultTime?: string + defaultTime?: string, ) { if (value === '' || value === null) return dayjs(); @@ -109,7 +109,7 @@ export function parseToDayjs( if (!result.isValid()) { log.error( 'DatePicker', - `Check whether the format、value format is valid.\n value: '${value}', format: '${format}'` + `Check whether the format、value format is valid.\n value: '${value}', format: '${format}'`, ); return dayjs(); } @@ -155,7 +155,7 @@ function formatRange({ if (!newDate || !Array.isArray(newDate)) return []; let dayjsDateList = newDate.map( - (d, i) => d && parseToDayjs(d, format, undefined, undefined, defaultTime?.[i]).locale(dayjsLocale) + (d, i) => d && parseToDayjs(d, format, undefined, undefined, defaultTime?.[i]).locale(dayjsLocale), ); // 保证后面的时间大于前面的时间 @@ -173,7 +173,7 @@ function formatRange({ if (dayjsDateList.some((r) => r && !r.isValid())) { log.error( 'DatePicker', - `Check whether the value、format、valueType format is valid.\nformat: '${format}' value: '${newDate}' valueType: '${targetFormat}'` + `Check whether the value、format、valueType format is valid.\nformat: '${format}' value: '${newDate}' valueType: '${targetFormat}'`, ); return []; } @@ -208,7 +208,7 @@ function formatSingle({ if (!dayJsDate.isValid()) { log.error( 'DatePicker', - `Check whether the format、value format is valid.\nformat: '${format}' value: '${newDate}'` + `Check whether the format、value format is valid.\nformat: '${format}' value: '${newDate}'`, ); return ''; } @@ -249,7 +249,7 @@ export function formatDate( targetFormat?: string; autoSwap?: boolean; defaultTime?: string | string[]; - } + }, ) { let result; diff --git a/js/date-picker/utils.ts b/js/date-picker/utils.ts index 8c380f6a4f..0c4f7289b3 100644 --- a/js/date-picker/utils.ts +++ b/js/date-picker/utils.ts @@ -212,7 +212,7 @@ export function getWeeks( maxDate, dayjsLocale = 'zh-cn', cancelRangeSelectLimit = false, - }: OptionsType + }: OptionsType, ) { const prependDay = getFirstDayOfMonth({ year, month }); const appendDay = getLastDayOfMonth({ year, month }); @@ -298,7 +298,7 @@ export function getQuarters( quarterLocal, dayjsLocale = 'zh-cn', cancelRangeSelectLimit = false, - }: OptionsType + }: OptionsType, ) { const quarterArr = []; const today = getToday(); @@ -323,7 +323,7 @@ export function getQuarters( export function getYears( year: number, - { disableDate = () => false, minDate, maxDate, dayjsLocale = 'zh-cn', cancelRangeSelectLimit = false }: OptionsType + { disableDate = () => false, minDate, maxDate, dayjsLocale = 'zh-cn', cancelRangeSelectLimit = false }: OptionsType, ) { const startYear = parseInt((year / 10).toString(), 10) * 10; const endYear = startYear + 9; @@ -416,14 +416,14 @@ export function flagActive(data: any[], { ...args }: FlagActiveOptions) { if (multiple) { _item.active = (value as DateValue[])?.some?.( - (val) => isSame(dayjs(val).toDate(), _item.value, type) && !_item.additional + (val) => isSame(dayjs(val).toDate(), _item.value, type) && !_item.additional, ); } else { _item.active = start && isSame(item.value, start, type) && !_item.additional; } return _item; - }) + }), ); } @@ -450,7 +450,7 @@ export function flagActive(data: any[], { ...args }: FlagActiveOptions) { _item.hoverEndOfRange = isHoverEnd; } return _item; - }) + }), ); } @@ -610,7 +610,7 @@ export function computePaginationDisabled( range: PickerDateRange, mode: 'date' | 'week' | 'month' | 'quarter' | 'year', year: number, - month: number | undefined + month: number | undefined, ): { prev: boolean; next: boolean } { const monthCountMap: Record = { date: 1, week: 1, month: 12, quarter: 12, year: 120 }; const monthCount = monthCountMap[mode] || 0; diff --git a/js/image-viewer/transform.ts b/js/image-viewer/transform.ts index afee7fe4a6..b604e773f5 100644 --- a/js/image-viewer/transform.ts +++ b/js/image-viewer/transform.ts @@ -84,7 +84,7 @@ export function calcZoomOutScale(oldScale: number, step: number, min: number, ma export function calculateTranslateOffset( oldScale: number, newScale: number, - options?: ZoomOptions + options?: ZoomOptions, ): TranslateOffset | undefined { if (options?.mouseOffsetX == null || options?.mouseOffsetY == null) { return undefined; @@ -109,7 +109,7 @@ export function zoomIn( step: number, min: number, max: number, - options?: ZoomOptions + options?: ZoomOptions, ): { newScale: number; zoomResult: ZoomResult } { const newScale = calcZoomInScale(oldScale, step, min, max); return { @@ -127,7 +127,7 @@ export function zoomOut( step: number, min: number, max: number, - options?: ZoomOptions + options?: ZoomOptions, ): { newScale: number; zoomResult: ZoomResult } { const newScale = calcZoomOutScale(oldScale, step, min, max); return { diff --git a/js/input-number/large-number.ts b/js/input-number/large-number.ts index 2e51f134c8..322ad3bb94 100644 --- a/js/input-number/large-number.ts +++ b/js/input-number/large-number.ts @@ -208,7 +208,7 @@ export function compareNumber(num1: string | number, num2: string | number, larg export function largeIntegerNumberSubtract( num1: string, num2: string, - p?: { decimal?: boolean; stayZero?: boolean; filledZero?: boolean } + p?: { decimal?: boolean; stayZero?: boolean; filledZero?: boolean }, ): string { if (num1 === num2) return '0'; const { decimal, stayZero, filledZero } = p || {}; @@ -380,7 +380,7 @@ export function decimalPlacesToFixedNum(num: number, decimalPlaces: InputNumberD export function largeNumberToFixed( number: string | number, decimalPlaces: InputNumberDecimalPlaces = 0, - largeNumber: boolean = true + largeNumber: boolean = true, ): string { if (Number.isNaN(Number(number))) return ''; if (!largeNumber) { diff --git a/js/input-number/number.ts b/js/input-number/number.ts index 10d26272ab..86be1e0caf 100644 --- a/js/input-number/number.ts +++ b/js/input-number/number.ts @@ -43,7 +43,7 @@ export function putInRangeNumber( min?: NumberType; lastValue?: NumberType; largeNumber?: boolean; - } + }, ) { if (val === '') return undefined; const { max, min, lastValue, largeNumber } = params; @@ -235,7 +235,7 @@ export function formatUnCompleteNumber( decimalPlaces?: InputNumberDecimalPlaces; largeNumber?: boolean; isToFixed?: boolean; - } = {} + } = {}, ): number | string { if (['', null, undefined].includes(number) || !/\d+/.test(number)) return undefined; const { decimalPlaces, largeNumber, isToFixed } = extra; diff --git a/js/qrcode/qrcodegen.ts b/js/qrcode/qrcodegen.ts index 5bbbf5dd80..af20d371ee 100644 --- a/js/qrcode/qrcodegen.ts +++ b/js/qrcode/qrcodegen.ts @@ -341,7 +341,7 @@ export class QrCode { minVersion: number = 1, maxVersion: number = 40, mask: number = -1, - boostEcl: boolean = true + boostEcl: boolean = true, ): QrCode { if ( !(QrCode.MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= QrCode.MAX_VERSION) || @@ -451,7 +451,7 @@ export class QrCode { dataCodewords: Readonly, - oriMsk: number + oriMsk: number, ) { let msk = oriMsk; this.version = version; @@ -967,7 +967,7 @@ export class QrCode { private finderPenaltyTerminateAndCount( currentRunColor: boolean, oriCurrentRunLength: number, - runHistory: number[] + runHistory: number[], ): number { let currentRunLength = oriCurrentRunLength; if (currentRunColor) { diff --git a/js/qrcode/utils.ts b/js/qrcode/utils.ts index aadffaf13b..49db1dcc21 100644 --- a/js/qrcode/utils.ts +++ b/js/qrcode/utils.ts @@ -96,7 +96,7 @@ export const getImageSettings = ( cells: Modules, size: number, margin: number, - imageSettings?: ImageSettings + imageSettings?: ImageSettings, ): null | { x: number; y: number; diff --git a/js/table/tree-store.ts b/js/table/tree-store.ts index 335e151a98..9bdccd0253 100644 --- a/js/table/tree-store.ts +++ b/js/table/tree-store.ts @@ -73,7 +73,7 @@ class TableTreeStore { this.treeDataMap, dataSource, columns.find((col) => col.colKey === 'row-select'), - keys + keys, ); } @@ -442,7 +442,7 @@ class TableTreeStore { const distance = type === 'after' ? 1 : 0; if (state.parent) { const childrenIndex = state.parent.row[keys.childrenKey].findIndex( - (t: TableRowData) => rowValue === get(t, keys.rowKey) + (t: TableRowData) => rowValue === get(t, keys.rowKey), ); state.parent.row[keys.childrenKey].splice(childrenIndex + distance, 0, newData); updateRowExpandLength(this.treeDataMap, state.parent.row, 1, 'insert', keys); @@ -466,7 +466,7 @@ class TableTreeStore { swapData( dataSource: T[], params: SwapParams, - keys: KeysType + keys: KeysType, ): { dataSource: T[]; result: boolean; code?: number; reason?: string } { const startIndex = params.currentIndex; const endIndex = params.targetIndex; @@ -659,7 +659,7 @@ class TableTreeStore { column: PrimaryTableCol, keys: KeysType, level = 0, - parent: TableRowState = null + parent: TableRowState = null, ) { for (let i = 0, len = dataSource.length; i < len; i++) { const item = dataSource[i]; @@ -742,7 +742,7 @@ export function updateRowExpandLength( row: TableRowData, distance: number, type: 'expand' | 'fold' | 'delete' | 'insert', - keys: KeysType + keys: KeysType, ) { let tmp = row; while (tmp) { @@ -779,7 +779,7 @@ export function updateChildrenRowState( treeDataMap: TableTreeDataMap, rowState: TableRowState, expanded: boolean, - keys: KeysType + keys: KeysType, ) { const { row, rowIndex } = rowState; const childrenNodes = get(row, keys.childrenKey); @@ -807,7 +807,7 @@ export function updateChildrenRowState( expanded: false, } as any, expanded, - keys + keys, ); } } @@ -818,7 +818,7 @@ export function updateRowData( data: T[], key: string | number, newData: T, - keys: KeysType + keys: KeysType, ) { for (let i = 0, len = data.length; i < len; i++) { const item = data[i]; @@ -843,7 +843,7 @@ export function updateRowIndex( maxRowIndex?: number; type?: 'add' | 'remove'; count?: number; - } + }, ) { const start = extra.minRowIndex || 0; const end = extra.maxRowIndex || dataSource.length; @@ -859,7 +859,7 @@ export function updateRowIndex( export function diffExpandedTreeNode( newExpandedNode: (number | string)[] = [], - oldExpandedNode: (number | string)[] = [] + oldExpandedNode: (number | string)[] = [], ) { const removedList: (number | string)[] = []; const addedList: (number | string)[] = []; diff --git a/js/table/utils.ts b/js/table/utils.ts index d0057584c5..af4e1792b0 100644 --- a/js/table/utils.ts +++ b/js/table/utils.ts @@ -4,7 +4,7 @@ import { BaseTableCol } from './types'; export function filterDataByIds( data: Array = [], ids: Array = [], - byId = 'id' + byId = 'id', ): Array { return data.filter((d: Record = {}) => ids.includes(d[byId])); } @@ -33,7 +33,7 @@ export const getScrollDirection = (scrollLeft: number, scrollTop: number): SCROL export function isRowSelectedDisabled( selectColumn: { [key: string]: any }, row: Record, - rowIndex: number + rowIndex: number, ): boolean { if (!selectColumn) return false; let disabled = isFunction(selectColumn.disabled) ? selectColumn.disabled({ row, rowIndex }) : selectColumn.disabled; diff --git a/js/tree-select/utils.ts b/js/tree-select/utils.ts index 9bc2af48f0..d4de45fd61 100644 --- a/js/tree-select/utils.ts +++ b/js/tree-select/utils.ts @@ -13,7 +13,7 @@ export function findParentValues( options: TreeOptionData[], targetValue: TargetValue, realValue: string, - realChildren: string + realChildren: string, ): TargetValue[] { let currentTargetValue = targetValue; if (currentTargetValue != null && typeof currentTargetValue === 'object') { diff --git a/js/upload/main.ts b/js/upload/main.ts index 6c998426e8..e3e22d9542 100644 --- a/js/upload/main.ts +++ b/js/upload/main.ts @@ -115,14 +115,14 @@ export function handleRequestMethodResponse(res: RequestMethodResponse) { if (!['success', 'fail'].includes(res.status)) { log.error( 'Upload', - "`requestMethodResponse.status` must be `success` or `fail`, examples `{ status: 'success', response: { url: '' } }`" + "`requestMethodResponse.status` must be `success` or `fail`, examples `{ status: 'success', response: { url: '' } }`", ); return false; } if (res.status === 'success' && (!res.response || (!res.response.url && !res.response.files))) { log.warn( 'Upload', - '`requestMethodResponse.response.url` or `requestMethodResponse.response.files` is required if `status` is `success`' + '`requestMethodResponse.response.url` or `requestMethodResponse.response.files` is required if `status` is `success`', ); } return true; @@ -166,7 +166,7 @@ export function uploadOneRequest(params: HandleUploadParams): Promise { const fileInfo = toUploadFiles.find( - (toFile) => (file.name && toFile.name === file.name) || (file.raw && toFile.raw === file.raw) + (toFile) => (file.name && toFile.name === file.name) || (file.raw && toFile.raw === file.raw), ); return { ...fileInfo, @@ -256,7 +256,7 @@ function updateUploadedFiles(uploadFiles: UploadFile[], resultFiles: UploadFile[ for (let i = 0, len = resultFiles.length; i < len; i++) { const file = resultFiles[i]; const index = uploadFiles.findIndex( - (item) => (item.raw && item.raw === file.raw) || (item.name && item.name === file.name) + (item) => (item.raw && item.raw === file.raw) || (item.name && item.name === file.name), ); const tmpFile = index >= 0 ? { ...uploadFiles[index], ...file } : file; newFiles.push(tmpFile); @@ -316,7 +316,7 @@ export function formatToUploadFile( files: File[], format: FileChangeParams['format'], status: UploadFile['status'] = undefined, - percent = 0 + percent = 0, ) { return files.map((fileRaw: File) => { let file: UploadFile = fileRaw; @@ -395,9 +395,9 @@ export function validateFile(params: FileChangeParams): Promise { const [allFilesResult, ...others] = results; @@ -423,7 +423,7 @@ export function validateFile(params: FileChangeParams): Promise string + getError: (p: { [key: string]: any }) => string, ) { const sizeLimitErrors: FileChangeReturn[] = []; const beforeUploadErrorFiles: UploadFile[] = []; diff --git a/js/utils/calcTextareaHeight.ts b/js/utils/calcTextareaHeight.ts index 284c3fce94..2eb37f6515 100644 --- a/js/utils/calcTextareaHeight.ts +++ b/js/utils/calcTextareaHeight.ts @@ -23,7 +23,7 @@ const TEXTAREA_STYLE = ` function calcTextareaHeight( targetElement: HTMLTextAreaElement, minRows: LimitType = 1, - maxRows: LimitType = null + maxRows: LimitType = null, ): CalculateStyleType { const hiddenTextarea = document.createElement('textarea'); document.body.appendChild(hiddenTextarea); diff --git a/js/utils/general.ts b/js/utils/general.ts index 2f8aeb87fb..3b79e845dd 100644 --- a/js/utils/general.ts +++ b/js/utils/general.ts @@ -6,7 +6,7 @@ export const hasOwn = (val: T, key: string | symbol | number): hasOwnProperty.call(val, key); export const getPropertyValFromObj = ( val: T, - key: string | symbol | number + key: string | symbol | number, ): T[keyof T] | undefined => (hasOwn(val, key) ? val[key] : undefined); const objectToString: typeof Object.prototype.toString = Object.prototype.toString; diff --git a/js/utils/getPosition.ts b/js/utils/getPosition.ts index 8ed8293c14..fa1963811d 100644 --- a/js/utils/getPosition.ts +++ b/js/utils/getPosition.ts @@ -5,7 +5,7 @@ const getPosition = ( contentEle: HTMLElement, placement: Partial, clientX?: Number, - clientY?: Number + clientY?: Number, ): { left: number; top: number } => { const targetRect = targetEle.getBoundingClientRect() as DOMRect; const contentRect = contentEle.getBoundingClientRect() as DOMRect; diff --git a/js/utils/observe.ts b/js/utils/observe.ts index cb261612f8..918432b484 100644 --- a/js/utils/observe.ts +++ b/js/utils/observe.ts @@ -2,7 +2,7 @@ export default function observe( element: HTMLElement, root: HTMLElement, callback: Function, - marginBottom: number + marginBottom: number, ): IntersectionObserver { if (typeof window === 'undefined') return null; if (!window || !window.IntersectionObserver) { @@ -22,7 +22,7 @@ export default function observe( { rootMargin: `0px 0px ${marginBottom}px 0px`, root, - } + }, ); io.observe(element); } catch (e) { diff --git a/js/watermark/generateBase64Url.ts b/js/watermark/generateBase64Url.ts index 0d2cd6836d..417da80948 100644 --- a/js/watermark/generateBase64Url.ts +++ b/js/watermark/generateBase64Url.ts @@ -28,7 +28,7 @@ export default function generateBase64Url( fontColor?: string; layout?: WatermarkLayout; }, - onFinish: (url: string, backgroundSize?: { width: number }) => void + onFinish: (url: string, backgroundSize?: { width: number }) => void, ): string { const isHexagonal = layout === 'hexagonal'; @@ -99,7 +99,7 @@ export default function generateBase64Url( fontWeight: string, fontSize: number, fontFamily: string, - fillStyle: string + fillStyle: string, ) => { ctx.font = `normal normal ${fontWeight} ${fontSize * ratio}px/${markHeight}px ${fontFamily}`; ctx.fillStyle = fillStyle; @@ -135,7 +135,7 @@ export default function generateBase64Url( offsetX: number = 0, offsetY: number = 0, rotateX: number = 0, - rotateY: number = 0 + rotateY: number = 0, ) => { if (item.url) { const { url, isGrayscale = false } = item; diff --git a/package.json b/package.json index fca926c6c3..c0a555d3a4 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,10 @@ "lint": "npm run lint:css && npm run lint:js && npm run lint:eslint && npm run typecheck", "lint:css": "stylelint **/*.{css,wxss,less} --allow-empty-input --cache", "lint:js": "prettier --check \"**/*.{vue,js,ts,jsx,tsx,json,md}\" --ignore-path .prettierignore", - "lint:eslint": "eslint . --ext .vue,.js,.ts,.jsx,.tsx --max-warnings 0 --cache", + "lint:eslint": "eslint . --max-warnings 0 --cache", "lint:css:fix": "stylelint **/*.{css,wxss,less} --fix --allow-empty-input --cache", "lint:js:fix": "prettier --write \"**/*.{vue,js,ts,jsx,tsx,json,md}\" --ignore-path .prettierignore", - "lint:eslint:fix": "eslint . --ext .vue,.js,.ts,.jsx,.tsx --fix --max-warnings 0 --cache", + "lint:eslint:fix": "eslint . --fix --max-warnings 0 --cache", "lint:fix": "npm run lint:css:fix && npm run lint:js:fix && npm run lint:eslint:fix", "test": "npm run test:unit", "test:unit": "vitest run --coverage", @@ -43,21 +43,15 @@ "@types/lodash-es": "^4.17.12", "@types/node": "^22.10.2", "@types/tinycolor2": "^1.4.6", - "@typescript-eslint/eslint-plugin": "^6.21.0", - "@typescript-eslint/experimental-utils": "^2.24.0", - "@typescript-eslint/parser": "^6.21.0", - "@typescript-eslint/typescript-estree": "^8.8.0", + "@rss1102/eslint-config-tdesign": "^0.0.1", + "@rss1102/prettier-config-tdesign": "^0.0.1", "@vitest/coverage-v8": "^3.1.4", "commitizen": "^4.2.2", "commitlint": "^17.0.3", "conventional-changelog-cli": "^2.1.1", "cz-conventional-changelog": "^3.3.0", "dayjs": "^1.11.4", - "eslint": "^8.57.0", - "eslint-config-airbnb-base": "^15.0.0", - "eslint-config-prettier": "^9.1.0", - "eslint-plugin-import": "^2.24.2", - "eslint-plugin-prettier": "^5.2.1", + "eslint": "^10.5.0", "husky": "^8.0.1", "jsdom": "^29.1.1", "lint-staged": "~13.2.0", diff --git a/prettier.config.mjs b/prettier.config.mjs new file mode 100644 index 0000000000..974977ec3d --- /dev/null +++ b/prettier.config.mjs @@ -0,0 +1 @@ +export { default } from '@rss1102/prettier-config-tdesign'; diff --git a/test/unit/input-number/number.test.js b/test/unit/input-number/number.test.js index 3d93230fc4..8c0544c53e 100644 --- a/test/unit/input-number/number.test.js +++ b/test/unit/input-number/number.test.js @@ -345,7 +345,7 @@ describe('putInRangeNumber', () => { it('大数字超过 max 应该返回 max', () => { expect(putInRangeNumber('99999999999999999999', { max: '9999999999999999999', min: '0', largeNumber: true })).toBe( - '9999999999999999999' + '9999999999999999999', ); }); @@ -355,7 +355,7 @@ describe('putInRangeNumber', () => { max: '99999999999999999999', min: '10000000000000000000', largeNumber: true, - }) + }), ).toBe('10000000000000000000'); }); @@ -369,7 +369,7 @@ describe('putInRangeNumber', () => { it('大数字在范围内应该返回原值', () => { expect(putInRangeNumber('5000000000000000000', { max: '9999999999999999999', min: '0', largeNumber: true })).toBe( - '5000000000000000000' + '5000000000000000000', ); }); }); @@ -401,7 +401,7 @@ describe('getStepValue', () => { min: '0', lastValue: '9999999999999999999', largeNumber: true, - }) + }), ).toBe('10000000000000000000'); }); @@ -414,7 +414,7 @@ describe('getStepValue', () => { min: '0', lastValue: '10000000000000000000', largeNumber: true, - }) + }), ).toBe('9999999999999999999'); }); @@ -461,7 +461,7 @@ describe('getMaxOrMinValidateResult', () => { value: '99999999999999999999', max: '9999999999999999999', min: '0', - }) + }), ).toBe('exceed-maximum'); }); @@ -472,7 +472,7 @@ describe('getMaxOrMinValidateResult', () => { value: '9999999999999999999', max: '99999999999999999999', min: '10000000000000000000', - }) + }), ).toBe('below-minimum'); }); @@ -483,7 +483,7 @@ describe('getMaxOrMinValidateResult', () => { value: '5000000000000000000', max: '9999999999999999999', min: '0', - }) + }), ).toBeUndefined(); }); diff --git a/test/unit/locale/locale.test.ts b/test/unit/locale/locale.test.ts index 249a2c247e..c9a8967948 100644 --- a/test/unit/locale/locale.test.ts +++ b/test/unit/locale/locale.test.ts @@ -82,7 +82,7 @@ describe('国际化函数 t', () => { it('应该正确处理包含其他变量的复数文本', () => { expect(t('no {type} | one {type} ({count}) | {count} {type}s', 0, { type: 'file' })).toBe('no file'); expect(t('no {type} | one {type} ({count}) | {count} {type}s', 1, { count: 1, type: 'file' })).toBe( - 'one file (1)' + 'one file (1)', ); expect(t('no {type} | one {type} ({count}) | {count} {type}s', 5, { count: 5, type: 'file' })).toBe('5 files'); }); diff --git a/test/unit/upload/utils.test.js b/test/unit/upload/utils.test.js index 6f511a994d..d98c70a8cc 100644 --- a/test/unit/upload/utils.test.js +++ b/test/unit/upload/utils.test.js @@ -34,7 +34,7 @@ describe('validateFileType', () => { expect(validateFileType('.docx,.doc,.zip', 'application/doc')).toBeTruthy(); expect(validateFileType('.docx,.doc,.zip', 'application/msword')).toBeTruthy(); expect( - validateFileType('.docx,.doc,.zip', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') + validateFileType('.docx,.doc,.zip', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'), ).toBeTruthy(); expect(validateFileType('.docx,.doc,.zip', 'application/docx')).toBeTruthy(); expect(validateFileType('.docx,.doc,.zip', 'application/jpg')).toBeFalsy(); diff --git a/test/unit/utils/calcTextareaHeight.test.ts b/test/unit/utils/calcTextareaHeight.test.ts index ae5beda518..2089416ff7 100644 --- a/test/unit/utils/calcTextareaHeight.test.ts +++ b/test/unit/utils/calcTextareaHeight.test.ts @@ -32,7 +32,7 @@ describe('calcTextareaHeight', () => { let isReentered = false; vi.spyOn(HTMLTextAreaElement.prototype, 'scrollHeight', 'get').mockImplementation(function mockScrollHeight( - this: HTMLTextAreaElement + this: HTMLTextAreaElement, ) { if (!isReentered && !this.isConnected) return 0; if (!isReentered && this !== firstTextarea && this !== secondTextarea) { From fb1d8974bda09d82cb89e71d8f1683517b445ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Mon, 13 Jul 2026 06:09:23 +0800 Subject: [PATCH 2/3] chore: bump eslint config package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c0a555d3a4..f07d7ee7a2 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "@types/lodash-es": "^4.17.12", "@types/node": "^22.10.2", "@types/tinycolor2": "^1.4.6", - "@rss1102/eslint-config-tdesign": "^0.0.1", + "@rss1102/eslint-config-tdesign": "^0.0.2", "@rss1102/prettier-config-tdesign": "^0.0.1", "@vitest/coverage-v8": "^3.1.4", "commitizen": "^4.2.2", From 9aafe1381264066df9409e4371274a91e049afed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Tue, 11 Aug 2026 19:39:04 +0800 Subject: [PATCH 3/3] chore: consume shared TDesign lint configs --- eslint.config.mjs | 22 ++++++++++++++++++---- package.json | 4 ++-- prettier.config.mjs | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 89a603bbb5..2f929800eb 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,18 +1,25 @@ -import { base } from '@rss1102/eslint-config-tdesign'; +import { tdesign } from '@tdesign/eslint-config'; -export default [ - ...base, +export default tdesign( { + preset: 'base', + tests: true, ignores: ['lib/**', 'public/**', 'dist/**', 'static/**', 'site/**', '**/*/*.test.js'], }, { + name: 'tdesign-common/overrides', files: ['**/*.{js,mjs,cjs,jsx,ts,tsx}'], rules: { 'no-unassigned-vars': 'off', 'no-useless-assignment': 'off', 'preserve-caught-error': 'off', + '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/consistent-type-imports': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-unsafe-function-type': 'off', '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/no-wrapper-object-types': 'off', 'simple-import-sort/exports': 'off', 'simple-import-sort/imports': 'off', 'no-restricted-imports': [ @@ -35,10 +42,17 @@ export default [ }, }, { + name: 'tdesign-common/legacy-disable-directives', + linterOptions: { + reportUnusedDisableDirectives: 'off', + }, + }, + { + name: 'tdesign-common/tooling-overrides', files: ['*.config.js', 'test/script/*'], rules: { 'no-console': 'off', '@typescript-eslint/no-require-imports': 'off', }, }, -]; +); diff --git a/package.json b/package.json index f07d7ee7a2..29edd468bf 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,8 @@ "@types/lodash-es": "^4.17.12", "@types/node": "^22.10.2", "@types/tinycolor2": "^1.4.6", - "@rss1102/eslint-config-tdesign": "^0.0.2", - "@rss1102/prettier-config-tdesign": "^0.0.1", + "@tdesign/eslint-config": "https://pkg.pr.new/TDesignOteam/eslint-prettier-config/@tdesign/eslint-config@c21e4ff", + "@tdesign/prettier-config": "https://pkg.pr.new/TDesignOteam/eslint-prettier-config/@tdesign/prettier-config@c21e4ff", "@vitest/coverage-v8": "^3.1.4", "commitizen": "^4.2.2", "commitlint": "^17.0.3", diff --git a/prettier.config.mjs b/prettier.config.mjs index 974977ec3d..87cd7d9fff 100644 --- a/prettier.config.mjs +++ b/prettier.config.mjs @@ -1 +1 @@ -export { default } from '@rss1102/prettier-config-tdesign'; +export { default } from '@tdesign/prettier-config';