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: add facade eslint (#4297)
#FF00006bb96cc9859d
diff --git a/common/shared/eslint/index.js b/common/shared/eslint/index.jsindex 2cbf081285..18d1c12030 100644--- a/common/shared/eslint/index.js+++ b/common/shared/eslint/index.js@@ -1,4 +1,6 @@const eslintPluginReadableTailwind = require('eslint-plugin-readable-tailwind');+const noExternalImportsInFacade = require('./plugins/no-external-imports-in-facade');+const noSelfPackageImports = require('./plugins/no-self-package-imports');exports.baseRules = {curly: ['error', 'multi-line'],@@ -109,6 +111,14 @@ exports.baseRules = {exports.typescriptPreset = () => {return {files: ['**/*.ts', '**/*.tsx'],+ plugins: {+ univer: {+ rules: {+ 'no-external-imports-in-facade': noExternalImportsInFacade,+ 'no-self-package-imports': noSelfPackageImports,+ },+ },+ },rules: {'ts/naming-convention': ['warn',@@ -136,11 +146,35 @@ exports.typescriptPreset = () => {};};+exports.univerSourcePreset = () => {+ return {+ files: ['**/*.ts', '**/*.tsx'],+ ignores: [+ '**/__tests__/**/*',+ '**/*.spec.ts',+ '**/*.test.ts',+ ],+ rules: {+ 'univer/no-self-package-imports': 'error',+ },+ languageOptions: {+ parser: require('@typescript-eslint/parser'),+ },+ };+};+exports.facadePreset = () => {return {- files: ['**/facade/src/**/*.ts'],+ files: ['**/src/facade/**/*.ts'],+ ignores: [+ '**/core/src/**/*.ts',+ '**/__tests__/**/*',+ '**/*.spec.ts',+ '**/*.test.ts',+ ],rules: {'ts/explicit-function-return-type': 'error',+ 'univer/no-external-imports-in-facade': 'error',},};};diff --git a/common/shared/eslint/plugins/no-external-imports-in-facade.js b/common/shared/eslint/plugins/no-external-imports-in-facade.jsnew file mode 100644index 0000000000..dd83778f7f--- /dev/null+++ b/common/shared/eslint/plugins/no-external-imports-in-facade.js@@ -0,0 +1,48 @@+// no-external-imports-in-facade.js+const path = require('node:path');++const rule = {+ meta: {+ type: 'problem',+ docs: {+ description: 'Disallow imports from outside facade directory in facade files',+ },+ messages: {+ noExternalImports: 'Imports from outside facade directory are not allowed in facade files: "{{importPath}}"',+ },+ },++ create(context) {+ const filename = context.getFilename();+ const normalizedPath = filename.split(path.sep).join('/');+ const isFacadeFile = normalizedPath.includes('/facade/');++ if (!isFacadeFile) {+ return {};+ }++ const currentDir = path.dirname(filename);++ return {+ ImportDeclaration(node) {+ const importPath = node.source.value;++ if (importPath[0] !== '.') {+ return;+ }++ const resolvedPath = path.resolve(currentDir, importPath).split(path.sep).join('/');++ if (!resolvedPath.includes('/facade/')) {+ context.report({+ node,+ messageId: 'noExternalImports',+ data: { importPath },+ });+ }+ },+ };+ },+};++module.exports = rule;diff --git a/common/shared/eslint/plugins/no-self-package-imports.js b/common/shared/eslint/plugins/no-self-package-imports.jsnew file mode 100644index 0000000000..ff74d35171--- /dev/null+++ b/common/shared/eslint/plugins/no-self-package-imports.js@@ -0,0 +1,70 @@+const path = require('node:path');++const rule = {+ meta: {+ type: 'problem',+ docs: {+ description: 'Disallow self package imports in packages directory except facade',+ },+ messages: {+ noSelfImport: 'Package cannot import itself: "{{importPath}}" in {{packageName}}',+ },+ },++ create(context) {+ const filename = context.getFilename();+ const normalizedPath = filename.split(path.sep).join('/');++ const isInPackages = normalizedPath.includes('/packages/');+ const isInFacade = normalizedPath.includes('/facade/');++ if (!isInPackages || isInFacade) {+ return {};+ }++ // get parent dir+ const parentDirMatch = normalizedPath.match(/\/([^/]+)\/packages\//);+ if (!parentDirMatch) {+ return {};+ }++ const parentDir = parentDirMatch[1];+ const packagePrefix = parentDir === 'univer'+ ? '@univerjs/' :+ parentDir === 'univer-pro'+ ? '@univerjs-pro/' :+ null;++ if (!packagePrefix) {+ return {};+ }++ // get package name+ const packageMatch = normalizedPath.match(/\/packages\/([^/]+)/);+ if (!packageMatch) {+ return {};+ }++ const packageName = packageMatch[1];+ const possiblePackageName = `${packagePrefix}${packageName}`;++ return {+ ImportDeclaration(node) {+ const importPath = node.source.value;++ if (importPath === possiblePackageName) {+ context.report({+ node,+ messageId: 'noSelfImport',+ data: {+ importPath,+ packageName: importPath,+ },+ });+ }+ },+ };+ },+};++module.exports = rule;diff --git a/eslint.config.js b/eslint.config.jsindex c952c4262d..6c18da9ec8 100644--- a/eslint.config.js+++ b/eslint.config.js@@ -1,5 +1,5 @@import antfu from '@antfu/eslint-config';-import { baseRules, facadePreset, specPreset, tailwindcssPreset, typescriptPreset } from '@univerjs-infra/shared/eslint';+import { baseRules, facadePreset, specPreset, tailwindcssPreset, typescriptPreset, univerSourcePreset } from '@univerjs-infra/shared/eslint';import header from 'eslint-plugin-header';import barrel from 'eslint-plugin-no-barrel-import';import penetrating from 'eslint-plugin-no-penetrating-import';@@ -99,6 +99,7 @@ export default antfu(},},typescriptPreset(),+ univerSourcePreset(),facadePreset(),tailwindcssPreset(),specPreset()diff --git a/packages/sheets-ui/src/facade/f-workbook.ts b/packages/sheets-ui/src/facade/f-workbook.tsindex 09a795c4fc..935bed1add 100644--- a/packages/sheets-ui/src/facade/f-workbook.ts+++ b/packages/sheets-ui/src/facade/f-workbook.ts@@ -14,12 +14,11 @@* limitations under the License.*/-import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';-import type { IHoverRichTextInfo, IHoverRichTextPosition } from '../services/hover-manager.service';+import type { IEditorBridgeServiceVisibleParam, IHoverRichTextInfo, IHoverRichTextPosition } from '@univerjs/sheets-ui';import { awaitTime, ICommandService, type IDisposable, ILogService, toDisposable } from '@univerjs/core';import { DeviceInputEventType } from '@univerjs/engine-render';-import { FWorkbook } from '@univerjs/sheets/facade';import { HoverManagerService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';+import { FWorkbook } from '@univerjs/sheets/facade';import { type IDialogPartMethodOptions, IDialogService, type ISidebarMethodOptions, ISidebarService, KeyCode } from '@univerjs/ui';import { filter } from 'rxjs';diff --git a/packages/sheets-ui/src/facade/f-worksheet.ts b/packages/sheets-ui/src/facade/f-worksheet.tsindex a79c230295..fccbc7e782 100644--- a/packages/sheets-ui/src/facade/f-worksheet.ts+++ b/packages/sheets-ui/src/facade/f-worksheet.ts@@ -16,9 +16,8 @@import { ICommandService } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';+import { ChangeZoomRatioCommand, SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { FWorksheet } from '@univerjs/sheets/facade';-import { ChangeZoomRatioCommand } from '../commands/commands/set-zoom-ratio.command';-import { SheetSkeletonManagerService } from '../services/sheet-skeleton-manager.service';export interface IFWorksheetSkeletonMixin {/**diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.tsindex ee1d692d1b..68f87b4eed 100644--- a/packages/sheets-ui/src/index.ts+++ b/packages/sheets-ui/src/index.ts@@ -84,7 +84,7 @@ export { mergeSetRangeValues } from './services/clipboard/utils';export type { IAutoFillLocation } from './services/auto-fill/type';export type { IDiscreteRange } from './controllers/utils/range-tools';export { discreteRangeToRange, rangeToDiscreteRange, virtualizeDiscreteRanges } from './controllers/utils/range-tools';-export { type IHoverCellPosition } from './services/hover-manager.service';+export type { IHoverCellPosition, IHoverRichTextInfo, IHoverRichTextPosition } from './services/hover-manager.service';export { AFFECT_LAYOUT_STYLES, AutoHeightController } from './controllers/auto-height.controller';export { AutoWidthController } from './controllers/auto-width.controller';export { type IDragCellPosition } from './services/drag-manager.service';diff --git a/packages/sheets/src/facade/f-workbook.ts b/packages/sheets/src/facade/f-workbook.tsindex 30e7dab3b3..cd21d9be9c 100644--- a/packages/sheets/src/facade/f-workbook.ts+++ b/packages/sheets/src/facade/f-workbook.ts@@ -79,7 +79,7 @@ export class FWorkbook extends FBase {* activeSpreadsheet.setName('MyWorkbook');* ```*/- setName(name: string) {+ setName(name: string): void {this._workbook.setName(name);}@@ -496,7 +496,7 @@ export class FWorkbook extends FBase {* activeSpreadsheet.duplicateSheet(activeSheet);* ```*/- duplicateSheet(sheet: FWorksheet) {+ duplicateSheet(sheet: FWorksheet): void {this._commandService.syncExecuteCommand(CopySheetCommand.id, {unitId: sheet.getWorkbook().getUnitId(),subUnitId: sheet.getSheetId(),@@ -612,7 +612,7 @@ export class FWorkbook extends FBase {* activeSpreadsheet.moveActiveSheet(1);* ```*/- async moveActiveSheet(index: number) {+ async moveActiveSheet(index: number): Promise<boolean> {const sheet = this.getActiveSheet();return this.moveSheet(sheet, index);}@@ -622,7 +622,7 @@ export class FWorkbook extends FBase {** @returns {FPermission} - The PermissionInstance.*/- getPermission() {+ getPermission(): FPermission {return this._injector.createInstance(FPermission);}}diff --git a/packages/sheets/src/facade/f-worksheet.ts b/packages/sheets/src/facade/f-worksheet.tsindex 9fcc63dd70..a9e37a6219 100644--- a/packages/sheets/src/facade/f-worksheet.ts+++ b/packages/sheets/src/facade/f-worksheet.ts@@ -1414,7 +1414,7 @@ export class FWorksheet extends FBase {* This is functionally equivalent to creating a Range bounded by A1 and (Sheet.getLastColumns(), Sheet.getLastRows()).* @returns {FRange} The range of the data in the sheet.*/- getDataRange() {+ getDataRange(): FRange {const lastRow = this.getLastRows();const lastColumn = this.getLastColumns();return this.getRange(0, 0, lastRow + 1, lastColumn + 1);