Skip to content

Commit 1bf9691

Browse files
committed
lint fix nil assertions
1 parent c67b595 commit 1bf9691

18 files changed

Lines changed: 181 additions & 93 deletions

src/processors/astericsGridProcessor.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,18 +1197,18 @@ class AstericsGridProcessor extends BaseProcessor {
11971197
imageData = Buffer.from(base64Data, 'base64');
11981198

11991199
// Use detected format for filename
1200-
imageName = element.image.id || `image.${imageFormat}`;
1201-
} catch (e) {
1202-
// Invalid base64 data, skip image
1200+
imageName = element.image.id || `image.${imageFormat}`;
1201+
} catch (e) {
1202+
// Invalid base64 data, skip image
1203+
}
12031204
}
1204-
}
12051205

1206-
return new AACButton({
1207-
id: element.id,
1208-
label: label,
1209-
message: label,
1206+
return new AACButton({
1207+
id: element.id,
1208+
label: label,
1209+
message: label,
12101210

1211-
targetPageId: targetPageId || undefined,
1211+
targetPageId: targetPageId || undefined,
12121212

12131213
semanticAction: semanticAction,
12141214
audioRecording: audioRecording,

test/errorHandling.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ describe('Error Handling', () => {
152152
const processor = new SnapProcessor();
153153
const invalidData = Buffer.from('invalid sqlite data');
154154

155+
// eslint-disable-next-line @typescript-eslint/no-var-requires
155156
const tempFilesBefore = fs.readdirSync(require('os').tmpdir()).length;
156157

157158
expect(() => {
@@ -160,6 +161,7 @@ describe('Error Handling', () => {
160161

161162
// Give some time for cleanup
162163
setTimeout(() => {
164+
// eslint-disable-next-line @typescript-eslint/no-var-requires
163165
const tempFilesAfter = fs.readdirSync(require('os').tmpdir()).length;
164166
expect(tempFilesAfter).toBeLessThanOrEqual(tempFilesBefore + 1); // Allow for some variance
165167
}, 100);

test/gridsetProcessor.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ describe('GridsetProcessor', () => {
2525

2626
describe('Error Handling', () => {
2727
it('should throw error for non-existent file', () => {
28-
const processor = new GridsetProcessor();
28+
const _processor = new GridsetProcessor();
2929
expect(() => {
30-
const nonExistentBuffer = fs.readFileSync('/non/existent/file.gridset');
30+
const _nonExistentBuffer = fs.readFileSync('/non/existent/file.gridset');
3131
}).toThrow();
3232
});
3333

test/gridsetWordlistHelpers.test.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ describe('Grid3 Wordlist Helpers', () => {
159159
expect(wordlists.size).toBe(1);
160160
expect(wordlists.has('Greetings')).toBe(true);
161161

162-
const wordlist = wordlists.get('Greetings')!;
162+
const wordlist = wordlists.get('Greetings');
163+
expect(wordlist).toBeDefined();
164+
if (!wordlist) {
165+
return;
166+
}
163167
expect(wordlist.items).toHaveLength(2);
164168
expect(wordlist.items[0].text).toBe('hello');
165169
expect(wordlist.items[0].image).toBe('[WIDGIT]hello.emf');
@@ -205,8 +209,14 @@ describe('Grid3 Wordlist Helpers', () => {
205209
</Grid>`;
206210
};
207211

208-
zip.addFile('Grids/Greetings/grid.xml', Buffer.from(createGrid('Greetings', ['hello', 'hi']), 'utf8'));
209-
zip.addFile('Grids/Farewells/grid.xml', Buffer.from(createGrid('Farewells', ['goodbye', 'bye']), 'utf8'));
212+
zip.addFile(
213+
'Grids/Greetings/grid.xml',
214+
Buffer.from(createGrid('Greetings', ['hello', 'hi']), 'utf8')
215+
);
216+
zip.addFile(
217+
'Grids/Farewells/grid.xml',
218+
Buffer.from(createGrid('Farewells', ['goodbye', 'bye']), 'utf8')
219+
);
210220

211221
const wordlists = extractWordlists(zip.toBuffer());
212222

@@ -243,7 +253,9 @@ describe('Grid3 Wordlist Helpers', () => {
243253
function createTestGridset(gridName: string, initialWordlistXml?: string): Buffer {
244254
const zip = new AdmZip();
245255

246-
const wordlistSection = initialWordlistXml || `<WordList>
256+
const wordlistSection =
257+
initialWordlistXml ||
258+
`<WordList>
247259
<Items>
248260
<WordListItem>
249261
<Text><s><r>old</r></s></Text>
@@ -285,7 +297,11 @@ describe('Grid3 Wordlist Helpers', () => {
285297
const wordlists = extractWordlists(updated);
286298

287299
expect(wordlists.has('Greetings')).toBe(true);
288-
const wordlist = wordlists.get('Greetings')!;
300+
const wordlist = wordlists.get('Greetings');
301+
expect(wordlist).toBeDefined();
302+
if (!wordlist) {
303+
return;
304+
}
289305
expect(wordlist.items).toHaveLength(3);
290306
expect(wordlist.items.map((i) => i.text)).toEqual(['hello', 'hi', 'hey']);
291307
});
@@ -300,7 +316,11 @@ describe('Grid3 Wordlist Helpers', () => {
300316
const updated = updateWordlist(gridset, 'Greetings', newWordlist);
301317
const wordlists = extractWordlists(updated);
302318

303-
const wordlist = wordlists.get('Greetings')!;
319+
const wordlist = wordlists.get('Greetings');
320+
expect(wordlist).toBeDefined();
321+
if (!wordlist) {
322+
return;
323+
}
304324
expect(wordlist.items[0].image).toBe('[WIDGIT]hello.emf');
305325
expect(wordlist.items[0].partOfSpeech).toBe('Interjection');
306326
});
@@ -363,4 +383,3 @@ describe('Grid3 Wordlist Helpers', () => {
363383
});
364384
});
365385
});
366-

test/integration.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('Integration Tests', () => {
6969
const outputFile = path.join(tempDir, 'cli_output.json');
7070

7171
try {
72-
const result = execSync(`node ${cliPath} extract-texts ${dotFile} ${outputFile}`, {
72+
const _result = execSync(`node ${cliPath} extract-texts ${dotFile} ${outputFile}`, {
7373
encoding: 'utf8',
7474
stdio: 'pipe',
7575
});
@@ -285,7 +285,7 @@ describe('Integration Tests', () => {
285285
if (translations.size > 0) {
286286
// Apply translations in DOT format
287287
const translatedDotPath = path.join(tempDir, 'translated.dot');
288-
const translatedDotResult = dotProcessor.processTexts(
288+
const _translatedDotResult = dotProcessor.processTexts(
289289
Buffer.from(dotContent),
290290
translations,
291291
translatedDotPath
@@ -352,7 +352,7 @@ describe('Integration Tests', () => {
352352

353353
// Step 4: Apply translations
354354
const translatedPath = path.join(tempDir, 'workflow_translated.dot');
355-
const translatedResult = processor.processTexts(
355+
const _translatedResult = processor.processTexts(
356356
Buffer.from(originalContent),
357357
translations,
358358
translatedPath

test/memoryLeaks.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ import path from 'path';
44
import { performance } from 'perf_hooks';
55
import { DotProcessor } from '../src/processors/dotProcessor';
66
import { SnapProcessor } from '../src/processors/snapProcessor';
7-
import { TouchChatProcessor } from '../src/processors/touchchatProcessor';
8-
import { ObfProcessor } from '../src/processors/obfProcessor';
9-
import { GridsetProcessor } from '../src/processors/gridsetProcessor';
107
import { AACTree, AACPage, AACButton } from '../src/core/treeStructure';
118

129
describe('Memory Leak Detection Tests', () => {
@@ -403,6 +400,7 @@ describe('Memory Leak Detection Tests', () => {
403400
const processor = new SnapProcessor();
404401

405402
const memBefore = getMemoryUsage();
403+
// eslint-disable-next-line @typescript-eslint/no-var-requires
406404
const tempFilesBefore = fs.readdirSync(require('os').tmpdir()).length;
407405

408406
// Perform operations that create temporary files
@@ -430,6 +428,7 @@ describe('Memory Leak Detection Tests', () => {
430428
// Give some time for cleanup
431429
setTimeout(() => {
432430
const memAfter = getMemoryUsage();
431+
// eslint-disable-next-line @typescript-eslint/no-var-requires
433432
const tempFilesAfter = fs.readdirSync(require('os').tmpdir()).length;
434433

435434
const memoryIncrease = memAfter.heapUsed - memBefore.heapUsed;

test/obfProcessor.roundtrip.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from 'fs';
33
import path from 'path';
44
import { ObfProcessor } from '../src/processors/obfProcessor';
5-
import { AACTree } from '../src/core/treeStructure';
5+
import { AACTree, AACPage, AACButton } from '../src/core/treeStructure';
66

77
describe('OBFProcessor round-trip', () => {
88
const obfPath: string = path.join(__dirname, '../examples/example.obf');
@@ -73,13 +73,13 @@ describe('OBFProcessor round-trip', () => {
7373

7474
// Create a simple tree programmatically
7575
const tree1 = new AACTree();
76-
const page = new (require('../src/core/treeStructure').AACPage)({
76+
const page = new AACPage({
7777
id: 'test-page',
7878
name: 'Test Page',
7979
buttons: [],
8080
});
8181

82-
const button = new (require('../src/core/treeStructure').AACButton)({
82+
const button = new AACButton({
8383
id: 'test-button',
8484
label: 'Test Button',
8585
message: 'Hello World',
@@ -106,7 +106,7 @@ describe('OBFProcessor round-trip', () => {
106106
const processor = new ObfProcessor();
107107
const tree = new AACTree();
108108

109-
const page = new (require('../src/core/treeStructure').AACPage)({
109+
const page = new AACPage({
110110
id: 'meta-page',
111111
name: 'Meta Page',
112112
grid: [
@@ -116,7 +116,7 @@ describe('OBFProcessor round-trip', () => {
116116
locale: 'en',
117117
});
118118

119-
const AACButtonCtor = require('../src/core/treeStructure').AACButton;
119+
const AACButtonCtor = AACButton;
120120
const buttonA = new AACButtonCtor({
121121
id: 'btn-a',
122122
label: 'A',

test/obfProcessor.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Test for OBFProcessor (Open Board Format/Zip)
2-
import fs from 'fs';
2+
// Test for OBFProcessor (Open Board Format/Zip)
33
import path from 'path';
44
import { ObfProcessor } from '../src/processors/obfProcessor';
5-
import { AACButton, AACPage, AACTree } from '../src/core/treeStructure';
5+
import { AACTree } from '../src/core/treeStructure';
66

77
describe('OBFProcessor', () => {
88
const obzPath: string = path.join(__dirname, '../examples/example.obz');
@@ -22,7 +22,8 @@ describe('OBFProcessor', () => {
2222
});
2323
expect(navFound).toBe(true);
2424
// Check image on button if present
25-
const rootPage = tree.getPage(tree.rootId!);
25+
const rootId = tree.rootId;
26+
const rootPage = rootId ? tree.getPage(rootId) : undefined;
2627
if (rootPage) {
2728
const imgBtn = rootPage.buttons.find((b: any) => b.image);
2829
if (imgBtn) {

test/opmlProcessor.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ describe('OPMLProcessor', () => {
1313
// Should have at least one page
1414
expect(Object.keys(tree.pages).length).toBeGreaterThan(0);
1515
// Super root should have a navigation button to root
16-
const superRoot = tree.getPage(tree.rootId!);
16+
const rootId = tree.rootId;
17+
const superRoot = rootId ? tree.getPage(rootId) : undefined;
1718
expect(superRoot).toBeDefined();
18-
expect(superRoot!.buttons.length).toBeGreaterThan(0);
19+
expect(superRoot?.buttons.length).toBeGreaterThan(0);
1920
// There should be at least one navigation button in the tree
2021
let navFound = false;
2122
tree.traverse((page) => {

test/performance.memory.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from 'path';
44
import { TouchChatProcessor } from '../src/processors/touchchatProcessor';
55
import { SnapProcessor } from '../src/processors/snapProcessor';
66
import { DotProcessor } from '../src/processors/dotProcessor';
7-
import { TreeFactory, PageFactory, ButtonFactory } from './utils/testFactories';
7+
import { TreeFactory } from './utils/testFactories';
88

99
describe('Memory Performance Tests', () => {
1010
const tempDir = path.join(__dirname, 'temp_performance');
@@ -221,7 +221,7 @@ describe('Memory Performance Tests', () => {
221221
it('should maintain memory usage under 100MB for large files', () => {
222222
const processor = new SnapProcessor();
223223

224-
const { result: tree, memoryUsedMB } = measureMemoryUsage(() => {
224+
const { result: tree, memoryUsedMB: _memoryUsedMB } = measureMemoryUsage(() => {
225225
const tree = TreeFactory.createLarge(100, 20); // 2000 buttons
226226

227227
// Add moderate audio content
@@ -258,7 +258,7 @@ describe('Memory Performance Tests', () => {
258258
it('should handle very large hierarchies efficiently', () => {
259259
const processor = new DotProcessor();
260260

261-
const { result: tree, memoryUsedMB } = measureMemoryUsage(() => {
261+
const { result: tree, memoryUsedMB: _memoryUsedMB } = measureMemoryUsage(() => {
262262
return TreeFactory.createLarge(200, 10); // 200 pages, 10 buttons each
263263
});
264264

0 commit comments

Comments
 (0)