Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
chore: update eslint rule for explicit function return type (#3116)
白熱3612ba8b1756
diff --git a/common/shared/eslint/index.js b/common/shared/eslint/index.jsindex dc127fdeaa..cb93509cca 100644--- a/common/shared/eslint/index.js+++ b/common/shared/eslint/index.js@@ -43,6 +43,7 @@ exports.baseRules = {'command/command': 'off',// TODO: debatable rules+ 'ts/explicit-function-return-type': 'warn','test/prefer-lowercase-title': 'off','antfu/top-level-function': 'off','style/operator-linebreak': 'off',@@ -100,7 +101,7 @@ exports.baseRules = {'react/no-create-ref': 'warn',};-exports.typescriptPreset = function typescriptPreset() {+exports.typescriptPreset = () => {return {files: ['**/*.ts', '**/*.tsx'],rules: {@@ -129,3 +130,24 @@ exports.typescriptPreset = function typescriptPreset() {},};};++exports.facadePreset = () => {+ return {+ files: ['**/facade/src/**/*.ts'],+ rules: {+ 'ts/explicit-function-return-type': 'error',+ },+ };+};++exports.specPreset = () => {+ return {+ files: [+ '**/*.spec.ts',+ '**/__tests__/**/*.ts',+ ],+ rules: {+ 'ts/explicit-function-return-type': 'off',+ },+ };+};diff --git a/eslint.config.js b/eslint.config.jsindex 454797acab..e7866e144a 100644--- a/eslint.config.js+++ b/eslint.config.js@@ -2,7 +2,7 @@ import antfu from '@antfu/eslint-config';import header from 'eslint-plugin-header';import barrel from 'eslint-plugin-no-barrel-import';import penetrating from 'eslint-plugin-no-penetrating-import';-import { baseRules, typescriptPreset } from '@univerjs/shared/eslint';+import { baseRules, facadePreset, specPreset, typescriptPreset } from '@univerjs/shared/eslint';header.rules.header.meta.schema = false;@@ -89,4 +89,7 @@ export default antfu({'penetrating/no-penetrating-import': 2,},},-typescriptPreset());+typescriptPreset(),+facadePreset(),+specPreset()+);diff --git a/packages/facade/src/apis/facade.ts b/packages/facade/src/apis/facade.tsindex 544c57c2a7..8443ee424c 100644--- a/packages/facade/src/apis/facade.ts+++ b/packages/facade/src/apis/facade.ts@@ -437,7 +437,7 @@ export class FUniver {* customizeColumnHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, columnsCfg: ['MokaII', undefined, null, { text: 'Size', textAlign: 'left' }] });* ```*/- customizeColumnHeader(cfg: IColumnsHeaderCfgParam) {+ customizeColumnHeader(cfg: IColumnsHeaderCfgParam): void {const wb = this.getActiveWorkbook();if (!wb) {console.error('WorkBook not exist');@@ -458,7 +458,7 @@ export class FUniver {* customizeRowHeader({ headerStyle: { backgroundColor: 'pink', fontSize: 9 }, rowsCfg: ['MokaII', undefined, null, { text: 'Size', textAlign: 'left' }] });* ```*/- customizeRowHeader(cfg: IRowsHeaderCfgParam) {+ customizeRowHeader(cfg: IRowsHeaderCfgParam): void {const wb = this.getActiveWorkbook();if (!wb) {console.error('WorkBook not exist');diff --git a/packages/facade/src/apis/sheets/f-data-validation-builder.ts b/packages/facade/src/apis/sheets/f-data-validation-builder.tsindex 35ae82b4cb..71d58c639a 100644--- a/packages/facade/src/apis/sheets/f-data-validation-builder.ts+++ b/packages/facade/src/apis/sheets/f-data-validation-builder.ts@@ -438,7 +438,7 @@ export class FDataValidationBuilder {* operator is a DataValidationOperator enum value, formula1 is the first formula, and formula2 is the second formula.* @return The current instance of the FDataValidationBuilder class, allowing for method chaining.*/- withCriteriaValues(type: DataValidationType, values: [DataValidationOperator, string, string]) {+ withCriteriaValues(type: DataValidationType, values: [DataValidationOperator, string, string]): this {this._rule.type = type;this._rule.operator = values[0];this._rule.formula1 = values[1];diff --git a/packages/facade/src/apis/sheets/f-data-validation.ts b/packages/facade/src/apis/sheets/f-data-validation.tsindex 8500b6c598..47ecf1613d 100644--- a/packages/facade/src/apis/sheets/f-data-validation.ts+++ b/packages/facade/src/apis/sheets/f-data-validation.ts@@ -14,7 +14,9 @@* limitations under the License.*/-import { DataValidationErrorStyle, type IDataValidationRule } from '@univerjs/core';+import type { DataValidationType, IDataValidationRule } from '@univerjs/core';+import { DataValidationErrorStyle } from '@univerjs/core';+import { FDataValidationBuilder } from './f-data-validation-builder';export class FDataValidation {@@ -28,34 +30,34 @@ export class FDataValidation {** @return true if invalid data is allowed, false otherwise.*/- getAllowInvalid() {+ getAllowInvalid(): boolean {return this.rule.errorStyle !== DataValidationErrorStyle.STOP;};/*** Gets the data validation type of the rule*- * @returns {DataValidationType} The data validation type+ * @returns The data validation type*/- getCriteriaType() {+ getCriteriaType(): DataValidationType {return this.rule.type;};/*** Gets the values used for criteria evaluation*- * @returns {any[]} An array containing the operator, formula1, and formula2 values+ * @returns An array containing the operator, formula1, and formula2 values*/- getCriteriaValues() {+ getCriteriaValues(): (string | undefined)[] {return [this.rule.operator, this.rule.formula1, this.rule.formula2];}/*** Gets the help text information, which is used to provide users with guidance and support*- * @returns {string | undefined} Returns the help text information. If there is no error message, it returns an undefined value.+ * @returns Returns the help text information. If there is no error message, it returns an undefined value.*/- getHelpText() {+ getHelpText(): string | undefined {return this.rule.error;};@@ -65,7 +67,7 @@ export class FDataValidation {** @return A new FDataValidationBuilder instance with the same rule configuration.*/- copy() {+ copy(): FDataValidationBuilder {return new FDataValidationBuilder(this.rule);}}diff --git a/packages/facade/src/apis/sheets/f-range.ts b/packages/facade/src/apis/sheets/f-range.tsindex e49339f739..d5c79067fd 100644--- a/packages/facade/src/apis/sheets/f-range.ts+++ b/packages/facade/src/apis/sheets/f-range.ts@@ -16,6 +16,7 @@import type {CellValue,+ DataValidationStatus,ICellData,IColorStyle,IObjectMatrixPrimitiveType,@@ -89,7 +90,7 @@ export class FRange {** @return The unit ID of the workbook*/- getUnitId() {+ getUnitId(): string {return this._workbook.getUnitId();}@@ -98,7 +99,7 @@ export class FRange {** @return The name of the worksheet*/- getSheetName() {+ getSheetName(): string {return this._worksheet.getName();}@@ -107,7 +108,7 @@ export class FRange {** @return The area where the statement is applied*/- getRange() {+ getRange(): IRange {return this._range;}@@ -171,7 +172,7 @@ export class FRange {* Return range whether this range is merged* @returns if true is merged*/- isMerged() {+ isMerged(): boolean {return isCellMerged(this.getCell().mergeInfo, this._range);}@@ -464,7 +465,7 @@ export class FRange {/*** Sets the font underline style of the given ITextDecoration*/- private _setFontUnderline(value: ITextDecoration | null) {+ private _setFontUnderline(value: ITextDecoration | null): void {const style: IStyleTypeValue<ITextDecoration | null> = {type: 'ul',value,@@ -482,7 +483,7 @@ export class FRange {/*** Sets the font strikethrough style of the given ITextDecoration*/- private _setFontStrikethrough(value: ITextDecoration | null) {+ private _setFontStrikethrough(value: ITextDecoration | null): void {const style: IStyleTypeValue<ITextDecoration | null> = {type: 'st',value,@@ -598,7 +599,7 @@ export class FRange {* @param rule data validation rule, build by `FUniver.newDataValidation`* @returns current range*/- async setDataValidation(rule: Nullable<FDataValidation>) {+ async setDataValidation(rule: Nullable<FDataValidation>): Promise<this> {if (!rule) {this._commandService.executeCommand(ClearRangeDataValidationCommand.id, {unitId: this._workbook.getUnitId(),@@ -642,9 +643,9 @@ export class FRange {/*** get all data validation rules in current range- * @returns {FDataValidation[]} all data validation rules+ * @returns all data validation rules*/- getDataValidations() {+ getDataValidations(): FDataValidation[] {const validatorService = this._injector.get(SheetsDataValidationValidatorService);return validatorService.getDataValidations(this._workbook.getUnitId(),@@ -657,7 +658,7 @@ export class FRange {* get data validation validator status for current range* @returns matrix of validator status*/- async getValidatorStatus() {+ async getValidatorStatus(): Promise<Promise<DataValidationStatus>[][]> {const validatorService = this._injector.get(SheetsDataValidationValidatorService);return validatorService.validatorRanges(this._workbook.getUnitId(),diff --git a/packages/facade/src/apis/sheets/f-workbook.ts b/packages/facade/src/apis/sheets/f-workbook.tsindex 99e9adf825..819cdab308 100644--- a/packages/facade/src/apis/sheets/f-workbook.ts+++ b/packages/facade/src/apis/sheets/f-workbook.ts@@ -14,7 +14,7 @@* limitations under the License.*/-import type { CommandListener, ICommandInfo, IDisposable, IRange, IWorkbookData, Workbook } from '@univerjs/core';+import type { CommandListener, ICommandInfo, IDisposable, IRange, IWorkbookData, Nullable, ObjectMatrix, Workbook } from '@univerjs/core';import {ICommandService,Inject,@@ -33,6 +33,7 @@ import type {} from '@univerjs/sheets';import { InsertSheetCommand, RemoveSheetCommand, SetWorksheetActiveOperation, SheetsSelectionsService, WorkbookEditablePermission } from '@univerjs/sheets';+import type { IDataValidationResCache } from '@univerjs/sheets-data-validation';import { SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';import { FWorksheet } from './f-worksheet';@@ -81,7 +82,7 @@ export class FWorkbook {* Gets all the worksheets in this workbook* @returns An array of all the worksheets in the workbook*/- getSheets() {+ getSheets(): FWorksheet[] {return this._workbook.getSheets().map((sheet) => {return this._injector.createInstance(FWorksheet, this._workbook, sheet);});@@ -151,7 +152,7 @@ export class FWorkbook {* @param sheet The worksheet to set as the active worksheet.* @returns The active worksheet*/- setActiveSheet(sheet: FWorksheet) {+ setActiveSheet(sheet: FWorksheet): FWorksheet {this._commandService.syncExecuteCommand(SetWorksheetActiveOperation.id, {unitId: this.id,subUnitId: sheet.getSheetId(),@@ -165,7 +166,7 @@ export class FWorkbook {* Using a default sheet name. The new sheet becomes the active sheet* @returns The new sheet*/- insertSheet() {+ insertSheet(): FWorksheet {this._commandService.syncExecuteCommand(InsertSheetCommand.id);const unitId = this.id;@@ -187,7 +188,7 @@ export class FWorkbook {* Deletes the specified worksheet.* @param sheet The worksheet to delete.*/- deleteSheet(sheet: FWorksheet) {+ deleteSheet(sheet: FWorksheet): void {const unitId = this.id;const subUnitId = sheet.getSheetId();this._commandService.executeCommand(RemoveSheetCommand.id, {@@ -278,7 +279,7 @@ export class FWorkbook {* get data validation validator status for current workbook* @returns matrix of validator status*/- getValidatorStatus() {+ getValidatorStatus(): Promise<Record<string, ObjectMatrix<Nullable<IDataValidationResCache>>>> {const validatorService = this._injector.get(SheetsDataValidationValidatorService);return validatorService.validatorWorkbook(this._workbook.getUnitId()diff --git a/packages/facade/src/apis/sheets/f-worksheet.ts b/packages/facade/src/apis/sheets/f-worksheet.tsindex 7d785c0fe1..e6db90dbf6 100644--- a/packages/facade/src/apis/sheets/f-worksheet.ts+++ b/packages/facade/src/apis/sheets/f-worksheet.ts@@ -14,11 +14,12 @@* limitations under the License.*/-import { ICommandService, type IRange, type Nullable, type Workbook, type Worksheet } from '@univerjs/core';+import type { IRange, Nullable, ObjectMatrix, Workbook, Worksheet } from '@univerjs/core';import type { ISetWorksheetColWidthMutationParams, ISetWorksheetRowHeightMutationParams } from '@univerjs/sheets';import { SetWorksheetColWidthMutation, SetWorksheetRowHeightMutation, SheetsSelectionsService } from '@univerjs/sheets';-import { Inject, Injector } from '@univerjs/core';+import { ICommandService, Inject, Injector } from '@univerjs/core';+import type { IDataValidationResCache } from '@univerjs/sheets-data-validation';import { DataValidationModel, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';import type { FilterModel } from '@univerjs/sheets-filter';import { SheetsFilterService } from '@univerjs/sheets-filter';@@ -74,7 +75,7 @@ export class FWorksheet {return this._injector.createInstance(FRange, this._workbook, this._worksheet, range);}- setRowHeights(startRow: number, numRows: number, height: number) {+ setRowHeights(startRow: number, numRows: number, height: number): void {this._commandService.syncExecuteCommand(SetWorksheetRowHeightMutation.id, {unitId: this._workbook.getUnitId(),subUnitId: this._worksheet.getSheetId(),@@ -90,7 +91,7 @@ export class FWorksheet {} as ISetWorksheetRowHeightMutationParams);}- setColumnWidths(startColumn: number, numColumns: number, width: number) {+ setColumnWidths(startColumn: number, numColumns: number, width: number): void {this._commandService.syncExecuteCommand(SetWorksheetColWidthMutation.id, {unitId: this._workbook.getUnitId(),subUnitId: this._worksheet.getSheetId(),@@ -110,7 +111,7 @@ export class FWorksheet {* Returns the current number of columns in the sheet, regardless of content.* @return The maximum columns count of the sheet*/- getMaxColumns() {+ getMaxColumns(): number {return this._worksheet.getMaxColumns();}@@ -118,15 +119,15 @@ export class FWorksheet {* Returns the current number of rows in the sheet, regardless of content.* @return The maximum rows count of the sheet*/- getMaxRows() {+ getMaxRows(): number {return this._worksheet.getMaxRows();}/*** get all data validation rules in current sheet- * @returns {FDataValidation[]} all data validation rules+ * @returns all data validation rules*/- getDataValidations() {+ getDataValidations(): FDataValidation[] {const dataValidationModel = this._injector.get(DataValidationModel);return dataValidationModel.getRules(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((rule) => new FDataValidation(rule));}@@ -135,7 +136,7 @@ export class FWorksheet {* get data validation validator status for current sheet* @returns matrix of validator status*/- getValidatorStatus() {+ getValidatorStatus(): Promise<ObjectMatrix<Nullable<IDataValidationResCache>>> {const validatorService = this._injector.get(SheetsDataValidationValidatorService);return validatorService.validatorWorksheet(this._workbook.getUnitId(),diff --git a/packages/facade/src/apis/sheets/utils.ts b/packages/facade/src/apis/sheets/utils.tsindex 7f83c1aabb..42cb22aace 100644--- a/packages/facade/src/apis/sheets/utils.ts+++ b/packages/facade/src/apis/sheets/utils.ts@@ -137,14 +137,14 @@ export function covertCellValues(return cellValue.getMatrix();}-export function isCellMerged(mergeInfo: IRangeWithCoord, range: IRange) {+export function isCellMerged(mergeInfo: IRangeWithCoord, range: IRange): boolean {if (!isSingleCell(mergeInfo, range)) {return false;}return range.startColumn !== range.endColumn || range.startRow !== range.endRow;}-export function isSingleCell(mergeInfo: IRangeWithCoord, range: IRange) {+export function isSingleCell(mergeInfo: IRangeWithCoord, range: IRange): boolean {return mergeInfo.startColumn === range.startColumn&& mergeInfo.endColumn === range.endColumn&& mergeInfo.startRow === range.startRowdiff --git a/packages/sheets-data-validation/src/index.ts b/packages/sheets-data-validation/src/index.tsindex adf8c81544..12f44d08e7 100644--- a/packages/sheets-data-validation/src/index.ts+++ b/packages/sheets-data-validation/src/index.ts@@ -17,6 +17,7 @@export { UniverSheetsDataValidationPlugin } from './plugin';export { UniverSheetsDataValidationMobilePlugin } from './mobile-plugin';export { DataValidationCacheService } from './services/dv-cache.service';+export type { IDataValidationResCache } from './services/dv-cache.service';export { DataValidationFormulaService } from './services/dv-formula.service';export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';export { DATA_VALIDATION_PLUGIN_NAME } from './common/const';