Skip to content

Commit 36e9550

Browse files
committed
more linting
1 parent 93ccd56 commit 36e9550

15 files changed

Lines changed: 371 additions & 292 deletions

src/processors/excelProcessor.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ export class ExcelProcessor extends BaseProcessor {
6565
* @param tree - Full AAC tree for navigation context
6666
* @param usedNames - Set of already used worksheet names to avoid duplicates
6767
*/
68-
private async convertPageToWorksheet(
68+
private convertPageToWorksheet(
6969
workbook: ExcelJS.Workbook,
7070
page: AACPage,
7171
tree: AACTree,
7272
usedNames: Set<string> = new Set()
73-
): Promise<void> {
73+
): void {
7474
// Create worksheet with page name (sanitized for Excel and unique)
7575
const worksheetName = this.getUniqueWorksheetName(page.name || page.id, usedNames);
7676
const worksheet = workbook.addWorksheet(worksheetName);
@@ -81,16 +81,16 @@ export class ExcelProcessor extends BaseProcessor {
8181
// Add navigation row if enabled (optional feature)
8282
let startRow = 1;
8383
if (this.shouldAddNavigationRow()) {
84-
await this.addNavigationRow(worksheet, page, tree);
84+
this.addNavigationRow(worksheet, page, tree);
8585
startRow = 2; // Start content after navigation row
8686
}
8787

8888
// Convert grid layout if available
8989
if (page.grid && page.grid.length > 0) {
90-
await this.convertGridLayout(worksheet, page.grid, startRow);
90+
this.convertGridLayout(worksheet, page.grid, startRow);
9191
} else {
9292
// Convert button list to grid layout
93-
await this.convertButtonsToGrid(worksheet, page.buttons, rows, cols, startRow);
93+
this.convertButtonsToGrid(worksheet, page.buttons, rows, cols, startRow);
9494
}
9595

9696
// Apply worksheet formatting
@@ -133,18 +133,18 @@ export class ExcelProcessor extends BaseProcessor {
133133
* @param grid - 2D array of AAC buttons
134134
* @param startRow - Starting row number
135135
*/
136-
private async convertGridLayout(
136+
private convertGridLayout(
137137
worksheet: ExcelJS.Worksheet,
138138
grid: Array<Array<AACButton | null>>,
139139
startRow: number
140-
): Promise<void> {
140+
): void {
141141
for (let row = 0; row < grid.length; row++) {
142142
for (let col = 0; col < grid[row].length; col++) {
143143
const button = grid[row][col];
144144
if (button) {
145145
const excelRow = startRow + row;
146146
const excelCol = col + 1; // Excel columns are 1-based
147-
await this.setButtonCell(worksheet, button, excelRow, excelCol);
147+
this.setButtonCell(worksheet, button, excelRow, excelCol);
148148
}
149149
}
150150
}
@@ -158,13 +158,13 @@ export class ExcelProcessor extends BaseProcessor {
158158
* @param cols - Number of columns in grid
159159
* @param startRow - Starting row number
160160
*/
161-
private async convertButtonsToGrid(
161+
private convertButtonsToGrid(
162162
worksheet: ExcelJS.Worksheet,
163163
buttons: AACButton[],
164164
rows: number,
165165
cols: number,
166166
startRow: number
167-
): Promise<void> {
167+
): void {
168168
for (let i = 0; i < buttons.length; i++) {
169169
const button = buttons[i];
170170
const row = Math.floor(i / cols);
@@ -173,7 +173,7 @@ export class ExcelProcessor extends BaseProcessor {
173173
if (row < rows) {
174174
const excelRow = startRow + row;
175175
const excelCol = col + 1; // Excel columns are 1-based
176-
await this.setButtonCell(worksheet, button, excelRow, excelCol);
176+
this.setButtonCell(worksheet, button, excelRow, excelCol);
177177
}
178178
}
179179
}
@@ -185,12 +185,12 @@ export class ExcelProcessor extends BaseProcessor {
185185
* @param row - Excel row number
186186
* @param col - Excel column number
187187
*/
188-
private async setButtonCell(
188+
private setButtonCell(
189189
worksheet: ExcelJS.Worksheet,
190190
button: AACButton,
191191
row: number,
192192
col: number
193-
): Promise<void> {
193+
): void {
194194
const cell = worksheet.getCell(row, col);
195195

196196
// Set cell value to button label
@@ -220,10 +220,10 @@ export class ExcelProcessor extends BaseProcessor {
220220
* @param cell - Excel cell to style
221221
* @param style - AAC style object
222222
*/
223-
private applyCellStyling(cell: ExcelJS.Cell, style: any): void {
224-
const fill: any = {};
225-
const font: any = {};
226-
const border: any = {};
223+
private applyCellStyling(cell: ExcelJS.Cell, style: AACStyle): void {
224+
const fill: Partial<ExcelJS.Fill> = {};
225+
const font: Partial<ExcelJS.Font> = {};
226+
const border: Partial<ExcelJS.Borders> = {};
227227

228228
// Background color
229229
if (style.backgroundColor) {
@@ -299,7 +299,7 @@ export class ExcelProcessor extends BaseProcessor {
299299
* @param color - Color string (hex, rgb, etc.)
300300
* @returns ARGB color string
301301
*/
302-
private convertColorToArgb(color: string): string {
302+
private convertColorToArgb(color?: string): string {
303303
if (!color) return 'FFFFFFFF'; // Default white
304304

305305
// Remove any whitespace
@@ -380,11 +380,7 @@ export class ExcelProcessor extends BaseProcessor {
380380
* @param page - Current AAC page
381381
* @param tree - Full AAC tree for navigation context
382382
*/
383-
private async addNavigationRow(
384-
worksheet: ExcelJS.Worksheet,
385-
page: AACPage,
386-
tree: AACTree
387-
): Promise<void> {
383+
private addNavigationRow(worksheet: ExcelJS.Worksheet, page: AACPage, tree: AACTree): void {
388384
const navButtons = ExcelProcessor.NAVIGATION_BUTTONS;
389385

390386
for (let i = 0; i < navButtons.length; i++) {
@@ -469,9 +465,9 @@ export class ExcelProcessor extends BaseProcessor {
469465
// - Max 31 characters
470466
// - Cannot contain: \ / ? * [ ] :
471467
// - Cannot be empty
472-
const cleaned = (name || '')
473-
.replace(/[\\\/\?\*\[\]:]/g, '_')
474-
.substring(0, 31);
468+
let cleaned = (name || '').replace(/[\\/?*:]/g, '_');
469+
cleaned = cleaned.replace(/\[/g, '_').replace(/\]/g, '_');
470+
cleaned = cleaned.substring(0, 31);
475471

476472
if (cleaned.length === 0) {
477473
return 'Sheet1';
@@ -488,7 +484,7 @@ export class ExcelProcessor extends BaseProcessor {
488484
*/
489485
private getUniqueWorksheetName(name: string, usedNames: Set<string>): string {
490486
const baseName = this.sanitizeWorksheetName(name);
491-
const normalize = (value: string) => value.toLowerCase();
487+
const normalize = (value: string): string => value.toLowerCase();
492488
let uniqueName = baseName;
493489
let counter = 1;
494490

@@ -537,15 +533,13 @@ export class ExcelProcessor extends BaseProcessor {
537533

538534
try {
539535
await this.saveFromTreeAsync(tree, outputPath);
540-
} catch (error: any) {
541-
console.error('Failed to save Excel file:', error);
536+
} catch (error: unknown) {
537+
const message = error instanceof Error ? error.message : String(error);
538+
console.error('Failed to save Excel file:', message);
542539
try {
543540
const fallbackPath = outputPath.replace(/\.xlsx$/i, '_error.txt');
544541
fs.mkdirSync(path.dirname(fallbackPath), { recursive: true });
545-
fs.writeFileSync(
546-
fallbackPath,
547-
`Error saving Excel file: ${error?.message || String(error)}`
548-
);
542+
fs.writeFileSync(fallbackPath, `Error saving Excel file: ${message}`);
549543
} catch (writeError) {
550544
console.error('Failed to write Excel error file:', writeError);
551545
}
@@ -578,7 +572,7 @@ export class ExcelProcessor extends BaseProcessor {
578572
// Convert each AAC page to an Excel worksheet
579573
for (const pageId in tree.pages) {
580574
const page = tree.pages[pageId];
581-
await this.convertPageToWorksheet(workbook, page, tree, usedNames);
575+
this.convertPageToWorksheet(workbook, page, tree, usedNames);
582576
}
583577

584578
// Save the workbook

src/processors/gridset/styleHelpers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Grid3 Style Helpers
3-
*
3+
*
44
* Utilities for creating and managing Grid3 styles, including default styles,
55
* style XML generation, and style conversion utilities.
66
*/
@@ -221,10 +221,9 @@ function darkenColor(hexColor: string, amount: number): string {
221221
const normalized = ensureAlphaChannel(hexColor);
222222
const hex = normalized.slice(1, 7); // Extract RGB part (skip # and alpha)
223223
const num = parseInt(hex, 16);
224-
const clamp = (value: number) => Math.max(0, Math.min(255, value));
224+
const clamp = (value: number): number => Math.max(0, Math.min(255, value));
225225
const r = clamp(((num >> 16) & 0xff) - amount);
226226
const g = clamp(((num >> 8) & 0xff) - amount);
227227
const b = clamp((num & 0xff) - amount);
228228
return `#${((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1)}`;
229229
}
230-

src/processors/gridset/wordlistHelpers.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* Grid3 Wordlist Helpers
3-
*
3+
*
44
* This module provides utilities for creating and extracting wordlists
55
* from Grid3 gridsets. Wordlists are Grid3-specific data structures
66
* used for dynamic vocabulary content.
7-
*
7+
*
88
* Note: Wordlists are only supported in Grid3 format. Other AAC formats
99
* do not have equivalent wordlist functionality.
1010
*/
@@ -34,14 +34,14 @@ export interface WordList {
3434

3535
/**
3636
* Creates a WordList object from an array of words/phrases or a dictionary
37-
*
37+
*
3838
* @param input - Either an array of strings or an object with text/image/partOfSpeech properties
3939
* @returns A WordList object ready to be used in Grid3
40-
*
40+
*
4141
* @example
4242
* // From simple array
4343
* const wordlist = createWordlist(['hello', 'goodbye', 'thank you']);
44-
*
44+
*
4545
* @example
4646
* // From array of objects
4747
* const wordlist = createWordlist([
@@ -64,7 +64,7 @@ export function createWordlist(
6464
});
6565
} else if (typeof input === 'object') {
6666
// Handle dictionary/object input
67-
items = Object.entries(input).map(([key, value]) => {
67+
items = Object.entries(input).map(([, value]) => {
6868
if (typeof value === 'string') {
6969
return { text: value };
7070
}
@@ -77,7 +77,7 @@ export function createWordlist(
7777

7878
/**
7979
* Converts a WordList object to Grid3 XML format
80-
*
80+
*
8181
* @param wordlist - The wordlist to convert
8282
* @returns XML string representation
8383
* @internal
@@ -263,7 +263,8 @@ export function updateWordlist(
263263
zip.updateFile(entry, Buffer.from(updatedXml, 'utf8'));
264264
found = true;
265265
} catch (error) {
266-
throw new Error(`Failed to update wordlist in grid "${gridName}": ${error}`);
266+
const message = error instanceof Error ? error.message : String(error);
267+
throw new Error(`Failed to update wordlist in grid "${gridName}": ${message}`);
267268
}
268269
}
269270
}
@@ -275,4 +276,3 @@ export function updateWordlist(
275276

276277
return zip.toBuffer();
277278
}
278-

0 commit comments

Comments
 (0)