Skip to content

Commit 5320453

Browse files
committed
fix: resolve all TypeScript strict null check errors
- Add proper eslint-disable comment for unavoidable 'any' at module boundary - Fix nitro plugin to handle undefined config properly - Add non-null assertions in test files after existence checks - All 251 tests pass with zero TypeScript errors This completes the module-builder migration with full type safety. Authored by: Aaron Lippold<lippold@gmail.com>
1 parent 86a2211 commit 5320453

File tree

10 files changed

+43
-42
lines changed

10 files changed

+43
-42
lines changed

src/module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { RuntimeConfig } from './runtime/types'
21
import { fileURLToPath } from 'node:url'
32
import { addPlugin, addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit'
43

@@ -220,6 +219,8 @@ export default defineNuxtModule<ModuleOptions>({
220219
nuxt.options.css.push(resolver.resolve('./runtime/superscript.css'))
221220

222221
// Pass module options to runtime
223-
nuxt.options.runtimeConfig.public.smartscript = options as unknown as RuntimeConfig
222+
// The options are merged with defaults by Nuxt, so all required fields are present
223+
// eslint-disable-next-line ts/no-explicit-any
224+
nuxt.options.runtimeConfig.public.smartscript = options as any
224225
},
225226
})

src/runtime/nitro/plugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export default <NitroAppPlugin> function (nitro) {
1616
// @ts-expect-error - render:html hook exists but not typed in nitropack
1717
nitro.hooks.hook('render:html', (html: Record<string, string[]>, { event }: { event: { context: { $config?: { public?: { smartscript?: SuperscriptConfig } } } } }) => {
1818
// Get configuration from runtime config
19-
const config = event.context.$config?.public?.smartscript || {}
19+
const config = event.context.$config?.public?.smartscript
2020

21-
// Skip if SSR processing is disabled
22-
if (config.ssr === false) {
21+
// Skip if no config or SSR processing is disabled
22+
if (!config || config.ssr === false) {
2323
logger.debug('[Nitro] SSR processing disabled via config')
2424
return
2525
}

test/integration/element-positioning.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('element Positioning Integration', () => {
4040
expect(regElements.length).toBe(1)
4141

4242
// Verify they are SPAN elements
43-
expect(tmElements[0].tagName).toBe('SPAN')
44-
expect(regElements[0].tagName).toBe('SPAN')
43+
expect(tmElements[0]!.tagName).toBe('SPAN')
44+
expect(regElements[0]!.tagName).toBe('SPAN')
4545
})
4646

4747
it('should apply CSS variables to positioned elements', () => {

test/unit/dom.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ describe('dOM Output: Actual Element Creation', () => {
114114
div.appendChild(fragment)
115115

116116
expect(div.childNodes).toHaveLength(2)
117-
expect(div.childNodes[0].textContent).toBe('MITRE')
117+
expect(div.childNodes[0]!.textContent).toBe('MITRE')
118118

119119
const sup = div.childNodes[1] as HTMLElement
120120
expect(sup.tagName).toBe('SPAN') // TM uses SPAN for positioning
@@ -133,7 +133,7 @@ describe('dOM Output: Actual Element Creation', () => {
133133
div.appendChild(fragment)
134134

135135
expect(div.childNodes).toHaveLength(2)
136-
expect(div.childNodes[0].textContent).toBe('1')
136+
expect(div.childNodes[0]!.textContent).toBe('1')
137137

138138
const sup = div.childNodes[1] as HTMLElement
139139
expect(sup.tagName).toBe('SUP')
@@ -153,14 +153,14 @@ describe('dOM Output: Actual Element Creation', () => {
153153
div.appendChild(fragment)
154154

155155
expect(div.childNodes).toHaveLength(3)
156-
expect(div.childNodes[0].textContent).toBe('H')
156+
expect(div.childNodes[0]!.textContent).toBe('H')
157157

158158
const sub = div.childNodes[1] as HTMLElement
159159
expect(sub.tagName).toBe('SUB')
160160
expect(sub.className).toBe('ss-sub')
161161
expect(sub.textContent).toBe('2')
162162

163-
expect(div.childNodes[2].textContent).toBe('O')
163+
expect(div.childNodes[2]!.textContent).toBe('O')
164164
})
165165

166166
it('should create fragment with mixed super and subscripts', () => {
@@ -201,8 +201,8 @@ describe('dOM Output: Actual Element Creation', () => {
201201
// Should have text "MITRE" and trademark "™" as SPAN (hybrid approach)
202202
const tmElements = div.querySelectorAll('span.ss-tm')
203203
expect(tmElements).toHaveLength(1)
204-
expect(tmElements[0].className).toBe('ss-sup ss-tm')
205-
expect(tmElements[0].textContent).toBe('™')
204+
expect(tmElements[0]!.className).toBe('ss-sup ss-tm')
205+
expect(tmElements[0]!.textContent).toBe('™')
206206
})
207207

208208
it('should process ordinal numbers correctly', () => {
@@ -214,8 +214,8 @@ describe('dOM Output: Actual Element Creation', () => {
214214
// Should have "1" as text and "st" as superscript
215215
const supElements = div.querySelectorAll('sup.ss-sup')
216216
expect(supElements).toHaveLength(1)
217-
expect(supElements[0].className).toBe('ss-sup ss-ordinal')
218-
expect(supElements[0].textContent).toBe('st')
217+
expect(supElements[0]!.className).toBe('ss-sup ss-ordinal')
218+
expect(supElements[0]!.textContent).toBe('st')
219219
})
220220

221221
it('should process chemical formulas correctly', () => {
@@ -227,7 +227,7 @@ describe('dOM Output: Actual Element Creation', () => {
227227
// Should have H, subscript 2, and O
228228
const subElements = div.querySelectorAll('sub.ss-sub')
229229
expect(subElements).toHaveLength(1)
230-
expect(subElements[0].textContent).toBe('2')
230+
expect(subElements[0]!.textContent).toBe('2')
231231
})
232232

233233
it('should process math notation correctly', () => {
@@ -239,7 +239,7 @@ describe('dOM Output: Actual Element Creation', () => {
239239
// Should have superscript 2
240240
const supElements = div.querySelectorAll('sup.ss-sup')
241241
expect(supElements).toHaveLength(1)
242-
expect(supElements[0].textContent).toBe('2')
242+
expect(supElements[0]!.textContent).toBe('2')
243243
})
244244

245245
it('should process copyright symbol correctly', () => {

test/unit/math-notation.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,34 +161,34 @@ describe('mathematical Notation Support', () => {
161161
const result = processMatch('x_n')
162162
expect(result.modified).toBe(true)
163163
expect(result.parts).toHaveLength(2)
164-
expect(result.parts[0].type).toBe('text')
165-
expect(result.parts[0].content).toBe('x')
166-
expect(result.parts[1].type).toBe('sub')
167-
expect(result.parts[1].content).toBe('n')
164+
expect(result.parts[0]!.type).toBe('text')
165+
expect(result.parts[0]!.content).toBe('x')
166+
expect(result.parts[1]!.type).toBe('sub')
167+
expect(result.parts[1]!.content).toBe('n')
168168
})
169169

170170
it('should correctly process single-letter superscripts', () => {
171171
const result = processMatch('x^n')
172172
expect(result.modified).toBe(true)
173173
expect(result.parts).toHaveLength(2)
174-
expect(result.parts[0].type).toBe('text')
175-
expect(result.parts[0].content).toBe('x')
176-
expect(result.parts[1].type).toBe('super')
177-
expect(result.parts[1].content).toBe('n')
174+
expect(result.parts[0]!.type).toBe('text')
175+
expect(result.parts[0]!.content).toBe('x')
176+
expect(result.parts[1]!.type).toBe('super')
177+
expect(result.parts[1]!.content).toBe('n')
178178
})
179179

180180
it('should correctly extract content from braced expressions', () => {
181181
const result1 = processMatch('x_{n+1}')
182182
expect(result1.modified).toBe(true)
183183
expect(result1.parts).toHaveLength(2)
184-
expect(result1.parts[0].content).toBe('x')
185-
expect(result1.parts[1].content).toBe('n+1') // Braces removed
184+
expect(result1.parts[0]!.content).toBe('x')
185+
expect(result1.parts[1]!.content).toBe('n+1') // Braces removed
186186

187187
const result2 = processMatch('x^{2n}')
188188
expect(result2.modified).toBe(true)
189189
expect(result2.parts).toHaveLength(2)
190-
expect(result2.parts[0].content).toBe('x')
191-
expect(result2.parts[1].content).toBe('2n') // Braces removed
190+
expect(result2.parts[0]!.content).toBe('x')
191+
expect(result2.parts[1]!.content).toBe('2n') // Braces removed
192192
})
193193

194194
it('should handle nested braces in math', () => {

test/unit/processor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe('text Processing', () => {
205205
// Unicode input
206206
const unicodeResult = processMatch('™')
207207
expect(unicodeResult.modified).toBe(true)
208-
expect(unicodeResult.parts[0].content).toBe('™')
208+
expect(unicodeResult.parts[0]!.content).toBe('™')
209209

210210
// Mixed case that shouldn't match
211211
const noMatch = processMatch('random text')

test/unit/regression/headers-bug.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ describe('hTML Headers Bug Fix', () => {
5151
const result = processText(text, combinedPattern)
5252
// Should return as plain text, no transformations
5353
expect(result).toHaveLength(1)
54-
expect(result[0].type).toBe('text')
55-
expect(result[0].content).toBe(text)
54+
expect(result[0]!.type).toBe('text')
55+
expect(result[0]!.content).toBe(text)
5656
})
5757
})
5858

test/unit/regression/water.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe('water and Headers Test', () => {
4444
const result = processText(text, combinedPattern)
4545
// Should be plain text, no transformations
4646
expect(result).toHaveLength(1)
47-
expect(result[0].type).toBe('text')
48-
expect(result[0].content).toBe(text)
47+
expect(result[0]!.type).toBe('text')
48+
expect(result[0]!.content).toBe(text)
4949
})
5050
})
5151

@@ -69,8 +69,8 @@ describe('water and Headers Test', () => {
6969
// Should have subscripts for both 2 and 4
7070
const subscripts = result.filter((p) => p.type === 'sub')
7171
expect(subscripts.length).toBe(2)
72-
expect(subscripts[0].content).toBe('2')
73-
expect(subscripts[1].content).toBe('4')
72+
expect(subscripts[0]!.content).toBe('2')
73+
expect(subscripts[1]!.content).toBe('4')
7474
})
7575

7676
it('should NOT transform H7 or higher', () => {

test/unit/ssr.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ describe('sSR with jsdom', () => {
185185
const divs = document.querySelectorAll('div')
186186

187187
// First div with data-no-superscript should remain unchanged
188-
expect(divs[0].innerHTML).toBe('Product(TM) H2O')
188+
expect(divs[0]!.innerHTML).toBe('Product(TM) H2O')
189189

190190
// Second div should be transformed
191-
expect(divs[1].innerHTML).toContain('<span class="ss-sup ss-tm" aria-label="trademark">™</span>')
192-
expect(divs[1].innerHTML).toContain('H<sub class="ss-sub"')
193-
expect(divs[1].innerHTML).toContain('>2</sub>O')
191+
expect(divs[1]!.innerHTML).toContain('<span class="ss-sup ss-tm" aria-label="trademark">™</span>')
192+
expect(divs[1]!.innerHTML).toContain('H<sub class="ss-sub"')
193+
expect(divs[1]!.innerHTML).toContain('>2</sub>O')
194194
})
195195

196196
it('should not transform nested exclusions', () => {

test/unit/transformations.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ describe('transformation Configuration', () => {
238238

239239
// Everything should remain as plain text
240240
expect(parts).toHaveLength(1)
241-
expect(parts[0].type).toBe('text')
242-
expect(parts[0].content).toBe(text)
241+
expect(parts[0]!.type).toBe('text')
242+
expect(parts[0]!.content).toBe(text)
243243
})
244244
})
245245

0 commit comments

Comments
 (0)