Skip to content

Commit 8681ca2

Browse files
committed
fix linting
1 parent da74cf5 commit 8681ca2

9 files changed

Lines changed: 74 additions & 37 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
obla-improvements/
23
tmp/
34
# Logs
45
logs

src/optional/analytics/metrics/comparison.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,18 @@ export class ComparisonAnalyzer {
114114
});
115115

116116
highEffortWords.sort((a, b) => {
117-
const diffA = targetWords.get(a)!.effort - (compareWords.get(a)?.effort || 0);
118-
const diffB = targetWords.get(b)!.effort - (compareWords.get(b)?.effort || 0);
117+
const targetBtnA = targetWords.get(a);
118+
const targetBtnB = targetWords.get(b);
119+
const diffA = (targetBtnA?.effort || 0) - (compareWords.get(a)?.effort || 0);
120+
const diffB = (targetBtnB?.effort || 0) - (compareWords.get(b)?.effort || 0);
119121
return diffB - diffA;
120122
});
121123

122124
lowEffortWords.sort((a, b) => {
123-
const diffA = (compareWords.get(a)?.effort || 0) - targetWords.get(a)!.effort;
124-
const diffB = (compareWords.get(b)?.effort || 0) - targetWords.get(b)!.effort;
125+
const targetBtnA = targetWords.get(a);
126+
const targetBtnB = targetWords.get(b);
127+
const diffA = (compareWords.get(a)?.effort || 0) - (targetBtnA?.effort || 0);
128+
const diffB = (compareWords.get(b)?.effort || 0) - (targetBtnB?.effort || 0);
125129
return diffB - diffA;
126130
});
127131

src/optional/analytics/metrics/core.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ export class MetricsCalculator {
260260
const levels: { [level: number]: ButtonMetrics[] } = {};
261261

262262
while (toVisit.length > 0) {
263-
const item = toVisit.shift()!;
263+
const item = toVisit.shift();
264+
if (!item) break;
264265
const { board, level, entryX, entryY, priorEffort = 0, temporaryHomeId } = item;
265266

266267
// Skip if already visited at a lower level with equal or better prior effort
@@ -450,11 +451,11 @@ export class MetricsCalculator {
450451
buttonEffort += priorEffort;
451452

452453
// Track scan blocks for block scanning, otherwise track individual buttons
453-
if (
454-
blockScanEnabled &&
455-
(btn.scanBlock || (btn.scanBlocks && btn.scanBlocks.length > 0))
456-
) {
457-
priorScanBlocks.add(btn.scanBlock || btn.scanBlocks![0]);
454+
if (blockScanEnabled) {
455+
const scanBlockId = btn.scanBlock ?? btn.scanBlocks?.[0];
456+
if (scanBlockId !== undefined && scanBlockId !== null) {
457+
priorScanBlocks.add(scanBlockId);
458+
}
458459
}
459460

460461
// Handle navigation buttons

src/optional/symbolTools.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import path from 'path';
22
import fs from 'fs';
3-
import {
4-
getZipEntriesWithPassword,
5-
resolveGridsetPasswordFromEnv,
6-
} from '../processors/gridset/password';
73
import { extractSymbolReferences } from '../processors/gridset/symbols';
84

95
// Dynamic imports for optional dependencies
@@ -68,10 +64,13 @@ export class SnapSymbolResolver extends SymbolResolver {
6864
let AdmZip: AdmZip | null = null;
6965
let XMLParser: XMLParser | null = null;
7066
try {
67+
// Dynamic requires for optional dependencies
7168
// eslint-disable-next-line @typescript-eslint/no-var-requires
72-
AdmZip = require('adm-zip');
69+
const admZipModule = require('adm-zip');
7370
// eslint-disable-next-line @typescript-eslint/no-var-requires
74-
XMLParser = require('fast-xml-parser').XMLParser;
71+
const fxpModule = require('fast-xml-parser');
72+
AdmZip = admZipModule;
73+
XMLParser = fxpModule.XMLParser;
7574
} catch {
7675
AdmZip = null;
7776
XMLParser = null;
@@ -82,6 +81,7 @@ export class Grid3SymbolExtractor extends SymbolExtractor {
8281
if (!AdmZip || !XMLParser) throw new Error('adm-zip or fast-xml-parser not installed');
8382

8483
// Import GridsetProcessor dynamically to avoid circular dependencies
84+
// eslint-disable-next-line @typescript-eslint/no-var-requires
8585
const { GridsetProcessor } = require('../processors/gridsetProcessor');
8686
const proc = new GridsetProcessor();
8787
const tree = proc.loadIntoTree(filePath);

src/processors/gridset/symbolExtractor.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,11 @@ export function extractSymbolLibraryImage(
180180
}
181181

182182
// Successfully extracted!
183-
const format = detectImageFormat(resolved.data!);
183+
const data = resolved.data;
184+
const format = data ? detectImageFormat(data) : 'unknown';
184185
return {
185186
found: true,
186-
data: resolved.data,
187+
data,
187188
format,
188189
source: 'symbol-library',
189190
reference: reference,

src/processors/gridset/symbolSearch.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,16 @@ export function searchSymbols(
145145
for (const [libraryName, index] of indexes.entries()) {
146146
// Exact match first
147147
if (index.searchTerms.has(lowerSearchTerm)) {
148-
const symbolFilename = index.searchTerms.get(lowerSearchTerm)!;
149-
results.push({
150-
searchTerm: lowerSearchTerm,
151-
symbolFilename,
152-
displayName: index.filenames.get(symbolFilename) || lowerSearchTerm,
153-
library: libraryName,
154-
exactMatch: true,
155-
});
148+
const symbolFilename = index.searchTerms.get(lowerSearchTerm);
149+
if (symbolFilename) {
150+
results.push({
151+
searchTerm: lowerSearchTerm,
152+
symbolFilename,
153+
displayName: index.filenames.get(symbolFilename) || lowerSearchTerm,
154+
library: libraryName,
155+
exactMatch: true,
156+
});
157+
}
156158
}
157159

158160
// Fuzzy match if enabled

src/processors/gridsetProcessor.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,22 @@ class GridsetProcessor extends BaseProcessor {
532532

533533
// Map Grid 3 visibility values to AAC standard values
534534
// Grid 3 can have additional values like TouchOnly, PointerOnly that map to PointerAndTouchOnly
535-
let cellVisibility: 'Visible' | 'Hidden' | 'Disabled' | 'PointerAndTouchOnly' | 'Empty' | undefined;
535+
let cellVisibility:
536+
| 'Visible'
537+
| 'Hidden'
538+
| 'Disabled'
539+
| 'PointerAndTouchOnly'
540+
| 'Empty'
541+
| undefined;
536542
if (grid3Visibility) {
537543
const vis = String(grid3Visibility);
538544
// Direct mapping for standard values
539-
if (vis === 'Visible' || vis === 'Hidden' || vis === 'Disabled' || vis === 'PointerAndTouchOnly') {
545+
if (
546+
vis === 'Visible' ||
547+
vis === 'Hidden' ||
548+
vis === 'Disabled' ||
549+
vis === 'PointerAndTouchOnly'
550+
) {
540551
cellVisibility = vis;
541552
}
542553
// Map Grid 3 specific values to AAC standard
@@ -573,7 +584,11 @@ class GridsetProcessor extends BaseProcessor {
573584
// For cells without captions, check if they have images/symbols before skipping
574585
if (content.ContentType === 'AutoContent') {
575586
label = `AutoContent_${idx}`;
576-
} else if (hasImageCandidate || content.ContentType === 'Workspace' || content.ContentType === 'LiveCell') {
587+
} else if (
588+
hasImageCandidate ||
589+
content.ContentType === 'Workspace' ||
590+
content.ContentType === 'LiveCell'
591+
) {
577592
// Keep cells with images/symbols even if no caption
578593
label = `Cell_${idx}`;
579594
} else {

src/processors/touchchatProcessor.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ function intToHex(colorInt: number | null | undefined): string | undefined {
8989
* TouchChat: 0 = Hidden, 1 = Visible
9090
* Maps to: 'Hidden' | 'Visible' | undefined
9191
*/
92-
function mapTouchChatVisibility(visible: number | null | undefined): 'Visible' | 'Hidden' | undefined {
92+
function mapTouchChatVisibility(
93+
visible: number | null | undefined
94+
): 'Visible' | 'Hidden' | undefined {
9395
if (visible === null || visible === undefined) {
9496
return undefined; // Default to visible
9597
}
@@ -268,8 +270,13 @@ class TouchChatProcessor extends BaseProcessor {
268270
label: cell.label || '',
269271
message: cell.message || '',
270272
semanticAction: semanticAction,
271-
semantic_id: (cell as any).symbol_link_id || (cell as any).symbolLinkId || undefined, // Extract semantic_id from symbol_link_id
272-
visibility: mapTouchChatVisibility((cell as any).visible),
273+
semantic_id:
274+
(((cell as any).symbol_link_id || (cell as any).symbolLinkId) as
275+
| string
276+
| undefined) || undefined, // Extract semantic_id from symbol_link_id
277+
visibility: mapTouchChatVisibility(
278+
((cell as any).visible as number | null | undefined) || undefined
279+
),
273280
// Note: TouchChat does not use scan blocks in the file
274281
// Scanning is a runtime feature (linear/row-column patterns)
275282
// scanBlock defaults to 1 (no grouping)
@@ -289,9 +296,9 @@ class TouchChatProcessor extends BaseProcessor {
289296
});
290297
buttonBoxes.get(cell.box_id)?.push({
291298
button,
292-
location: (cell as any).location,
293-
spanX: (cell as any).span_x,
294-
spanY: (cell as any).span_y,
299+
location: ((cell as any).location as number) || 0,
300+
spanX: ((cell as any).span_x as number) || 1,
301+
spanY: ((cell as any).span_y as number) || 1,
295302
});
296303
});
297304

test/obfsetProcessor.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ describe('ObfsetProcessor', () => {
1414
expect(tree.rootId).toBe('root');
1515
expect(Object.keys(tree.pages).length).toBe(2);
1616

17-
const rootPage = tree.getPage('root')!;
17+
const rootPage = tree.getPage('root');
18+
if (!rootPage) {
19+
throw new Error('Expected root page to exist');
20+
}
1821
expect(rootPage.name).toBe('Home');
1922
expect(rootPage.grid[0][0]?.label).toBe('Hello');
2023
expect(rootPage.grid[0][0]?.semantic_id).toBe('greeting-1');
2124
expect(rootPage.buttons.length).toBe(2);
2225

23-
const page2 = tree.getPage('page2')!;
26+
const page2 = tree.getPage('page2');
27+
if (!page2) {
28+
throw new Error('Expected page2 to exist');
29+
}
2430
expect(page2.parentId).toBe('root');
2531
expect(page2.grid[0][0]?.label).toBe('World');
2632
expect(page2.grid[0][0]?.clone_id).toBe('world-1');

0 commit comments

Comments
 (0)