Skip to content

Commit b2e41ed

Browse files
committed
lint & fromat & typecheck
1 parent f0aaac8 commit b2e41ed

File tree

5 files changed

+67
-27
lines changed

5 files changed

+67
-27
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@ jobs:
2222
run: npm install
2323

2424
- name: Check
25-
run: npm run check
26-
27-
- name: Build
28-
run: npm run build
25+
run: npm run ci

src/package-lock.json

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55
"source": "./spreadsheet_component.html",
66
"scripts": {
77
"build": "parcel build",
8-
"check": "biome check",
9-
"format": "biome format --write"
8+
"lint": "biome check",
9+
"typecheck": "tsc --noEmit",
10+
"lintfix": "biome check --fix --unsafe",
11+
"format": "biome format --write",
12+
"ci": "npm run lint && npm run typecheck && npm run build"
1013
},
1114
"author": "",
1215
"license": "AGPL-3.0-or-later",
1316
"devDependencies": {
1417
"@biomejs/biome": "1.9.2",
1518
"buffer": "^6.0.3",
1619
"parcel": "^2.12.0",
17-
"process": "^0.11.10"
20+
"process": "^0.11.10",
21+
"typescript": "^5.6.2"
1822
},
1923
"dependencies": {
2024
"@univerjs/core": "^0.2.15",

src/spreadsheet.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ import {
88
type CellValue,
99
CellValueType,
1010
type ICellData,
11-
ICommandInfo,
1211
type IObjectMatrixPrimitiveType,
1312
type IStyleData,
1413
type IWorkbookData,
1514
type IWorksheetData,
1615
LocaleType,
17-
Nullable,
18-
Tools,
1916
Univer,
2017
UniverInstanceType,
2118
type Workbook,
@@ -64,9 +61,14 @@ function setupUniver(component_index: number) {
6461
}
6562

6663
function setupErrorModal(component_index: number) {
67-
const resp_modal = document.getElementById(`errorModal_${component_index}`)!;
68-
const resp_modal_body = resp_modal.querySelector(".modal-body")!;
69-
const Modal = window["bootstrap"].Modal;
64+
const resp_modal = document.getElementById(`errorModal_${component_index}`);
65+
if (!resp_modal) throw new Error(`errorModal_${component_index} not found`);
66+
const resp_modal_body = resp_modal.querySelector(".modal-body");
67+
if (!resp_modal_body)
68+
throw new Error(`errorModal_${component_index} not found`);
69+
// @ts-ignore : bootstrap is included separately by sqlpage, and available globally
70+
const Modal = window?.bootstrap?.Modal;
71+
if (!Modal) throw new Error("bootstrap.Modal not found");
7072
return { resp_modal, resp_modal_body, Modal };
7173
}
7274

@@ -75,7 +77,7 @@ async function handleUpdate(
7577
x: number,
7678
y: number,
7779
value: CellValue | null,
78-
custom: any,
80+
custom: Record<string, unknown>,
7981
errorModal: ReturnType<typeof setupErrorModal>,
8082
) {
8183
if (!update_link) return;
@@ -87,7 +89,7 @@ async function handleUpdate(
8789
formData.append("y", y.toString());
8890
if (value != null)
8991
formData.append("value", value == null ? "" : value.toString());
90-
if (custom && custom.id !== null) formData.append("id", custom.id);
92+
if (typeof custom.id === "string") formData.append("id", custom.id);
9193
const r = await fetch(url, { method: "POST", body: formData });
9294
let resp_html = await r.text();
9395
if (r.status !== 200 && !resp_html) resp_html = r.statusText;
@@ -97,7 +99,9 @@ async function handleUpdate(
9799
}
98100
}
99101

100-
function cellFromProps(props: any[]): Partial<IStyleData & { id: string }> {
102+
function cellFromProps(
103+
props: (string | number)[],
104+
): Partial<IStyleData & { id: string }> {
101105
const s: Partial<IStyleData & { id: string }> = {};
102106
for (let i = 0; i < props.length; i++) {
103107
const n = props[i];
@@ -107,30 +111,35 @@ function cellFromProps(props: any[]): Partial<IStyleData & { id: string }> {
107111
const color = props[++i];
108112
s.bg = {
109113
rgb: getComputedStyle(document.documentElement).getPropertyValue(
110-
"--tblr-" + color,
114+
`--tblr-${color}`,
111115
),
112116
};
113117
} else if (n === 4) s.ht = 2;
114118
else if (n === 5) s.ht = 3;
115119
else if (n === 6) {
116-
const pattern = props[++i];
120+
const pattern = props[++i].toString();
117121
s.n = { pattern };
118-
} else if (n === 7) s.id = props[++i];
122+
} else if (n === 7) s.id = props[++i].toString();
119123
}
120124
return s;
121125
}
122126

123127
/**
124128
* [colIdx, rowIdx, value, ...props]
125129
*/
126-
type DataArray = [number, number, string | number | null, ...any[]];
130+
type DataArray = [
131+
number,
132+
number,
133+
string | number | null,
134+
...(string | number)[],
135+
];
127136

128137
function generateWorkSheet(dataArray: DataArray[]): Partial<IWorksheetData> {
129138
const cellData: IObjectMatrixPrimitiveType<ICellData> = {};
130139
let rowCount = 1000;
131140
let columnCount = 26;
132141

133-
dataArray.forEach(([colIdx, rowIdx, value, ...props]) => {
142+
for (const [colIdx, rowIdx, value, ...props] of dataArray) {
134143
const cell: Partial<ICellData> = { v: value };
135144
const style = props.length ? cellFromProps(props) : null;
136145
cell.s = style;
@@ -141,7 +150,7 @@ function generateWorkSheet(dataArray: DataArray[]): Partial<IWorksheetData> {
141150
else cellData[rowIdx] = { [colIdx]: cell };
142151
rowCount = Math.max(rowCount, rowIdx);
143152
columnCount = Math.max(columnCount, colIdx);
144-
});
153+
}
145154

146155
return {
147156
id: "sqlpage",
@@ -152,7 +161,7 @@ function generateWorkSheet(dataArray: DataArray[]): Partial<IWorksheetData> {
152161
};
153162
}
154163

155-
function createWorkbook(univer: Univer, data: any[]): Workbook {
164+
function createWorkbook(univer: Univer, data: DataArray[]): Workbook {
156165
return univer.createUnit<IWorkbookData, Workbook>(
157166
UniverInstanceType.UNIVER_SHEET,
158167
{
@@ -191,6 +200,12 @@ async function renderSpreadsheet({
191200
freeze_y,
192201
component_index,
193202
data,
203+
}: {
204+
update_link: string;
205+
freeze_x: number;
206+
freeze_y: number;
207+
component_index: number;
208+
data: DataArray[];
194209
}) {
195210
const errorModal = setupErrorModal(component_index);
196211
const univer = setupUniver(component_index);
@@ -216,7 +231,7 @@ async function renderSpreadsheet({
216231
Number.parseInt(col),
217232
Number.parseInt(row),
218233
cell.v as V,
219-
cell.custom,
234+
cell.custom || {},
220235
errorModal,
221236
);
222237
}

src/tsconfig.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
"baseUrl": ".",
44
"paths": {
55
"@univerjs/*": ["node_modules/@univerjs/*/lib/types"]
6-
}
7-
}
6+
},
7+
"skipLibCheck": true,
8+
"noEmit": true,
9+
"strict": true,
10+
"esModuleInterop": true,
11+
"moduleResolution": "node",
12+
"noUnusedLocals": true,
13+
"noUnusedParameters": true
14+
},
15+
"include": ["**/*.ts"],
16+
"exclude": ["node_modules"]
817
}

0 commit comments

Comments
 (0)