Skip to content

Commit 41b41de

Browse files
committed
fix: resolve all ESLint errors and warnings
- Remove unused imports (onUnmounted, SuperscriptConfig, shouldIncludeElement) - Replace any types with proper SuperscriptConfig type - Fix unused parameter in patterns.ts with underscore prefix - Remove unused parts variable in processor.ts - Replace console.log with comment in playground - Convert capturing groups to non-capturing groups in test regexes - Remove unused variables in integration tests - All 91 tests passing Authored by: Aaron Lippold<lippold@gmail.com>
1 parent 09318c9 commit 41b41de

File tree

9 files changed

+107
-105
lines changed

9 files changed

+107
-105
lines changed

playground/pages/index.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
<h2>Debug Info</h2>
77
<p>Plugin status: {{ $smartscript ? 'Loaded' : 'Not loaded' }}</p>
88
<p>Debug mode: {{ debugMode ? 'ON' : 'OFF' }}</p>
9-
<button @click="toggleDebug">Toggle Debug Mode</button>
10-
<button @click="manualProcess">Manual Process</button>
11-
<button @click="getStats">Get Stats</button>
9+
<button @click="toggleDebug">
10+
Toggle Debug Mode
11+
</button>
12+
<button @click="manualProcess">
13+
Manual Process
14+
</button>
15+
<button @click="getStats">
16+
Get Stats
17+
</button>
1218
<div v-if="stats">
1319
<p>Processed elements: {{ stats.processedElements }}</p>
1420
<p>Superscripts: {{ stats.superscripts }}, Subscripts: {{ stats.subscripts }}</p>
@@ -71,16 +77,16 @@
7177
<h3>Code Blocks (Not Transformed)</h3>
7278
<pre>Code blocks should not transform: H2O, 1st, Product™, x^2</pre>
7379
<code>Inline code: H2O, CO2, 1st, E=mc^2</code>
74-
80+
7581
<h3>Explicit Exclusion</h3>
7682
<div data-no-superscript>
7783
<p>This section excluded: H2O, CO2, 1st, Product™, x^2</p>
7884
</div>
79-
85+
8086
<h3>Programming Identifiers (Correctly Not Transformed)</h3>
8187
<p>Variables: file_name, some_var, MAX_SIZE stay unchanged</p>
8288
<p>But math after equals works: var=x^2 transforms x^2</p>
83-
89+
8490
<h3>Edge Cases That Work</h3>
8591
<p>After lowercase: abc^2 transforms c^2 (like E=mc^2)</p>
8692
<p>After uppercase: ABC^2 doesn't transform (intentional)</p>
@@ -106,7 +112,7 @@ const toggleDebug = () => {
106112
debugMode.value = !debugMode.value
107113
const config = $smartscript.getConfig()
108114
$smartscript.updateConfig({ ...config, debug: debugMode.value })
109-
console.log('Debug mode:', debugMode.value ? 'enabled' : 'disabled')
115+
// Debug mode toggle handled by updateConfig
110116
}
111117
}
112118
@@ -173,4 +179,4 @@ pre {
173179
padding: 1rem;
174180
overflow-x: auto;
175181
}
176-
</style>
182+
</style>

src/runtime/composables/useSmartScript.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
* Vue composable for SmartScript
33
*/
44

5-
import { ref, onMounted, onUnmounted } from 'vue'
5+
import { ref, onMounted } from 'vue'
66
import { useNuxtApp } from '#app'
7+
import type { SuperscriptConfig } from '../smartscript/types'
78

89
export interface SmartScriptApi {
910
process: () => void
1011
startObserving: () => void
1112
stopObserving: () => void
12-
getConfig: () => any
13-
updateConfig: (config: any) => boolean
13+
getConfig: () => SuperscriptConfig
14+
updateConfig: (config: Partial<SuperscriptConfig>) => boolean
1415
reset: () => void
1516
getStats: () => {
1617
processedElements: number

src/runtime/smartscript/dom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* DOM manipulation utilities for SmartScript
33
*/
44

5-
import type { TextPart, SuperscriptConfig } from './types'
5+
import type { TextPart } from './types'
66
import { logger } from './logger'
77

88
/**
@@ -89,7 +89,7 @@ export function createFragmentFromParts(parts: TextPart[]): DocumentFragment {
8989
else if (part.content === '®') {
9090
element = createSuperscriptElement(part.content, 'registered')
9191
}
92-
else if (/^(st|nd|rd|th)$/.test(part.content)) {
92+
else if (/^(?:st|nd|rd|th)$/.test(part.content)) {
9393
element = createSuperscriptElement(part.content, 'ordinal')
9494
}
9595
else {

src/runtime/smartscript/engine.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { logger } from './logger'
88
import {
99
createFragmentFromParts,
1010
shouldExcludeElement,
11-
shouldIncludeElement,
1211
isProcessed,
1312
markAsProcessed,
1413
resetProcessingFlags,
@@ -33,8 +32,8 @@ export function processTextNode(
3332

3433
// Check if we actually modified the content
3534
// Either we have non-text parts (super/sub) OR the text content changed
36-
const hasModifications = parts.some(p => p.type !== 'text') ||
37-
parts.map(p => p.content).join('') !== text
35+
const hasModifications = parts.some(p => p.type !== 'text')
36+
|| parts.map(p => p.content).join('') !== text
3837

3938
if (hasModifications) {
4039
logger.debug('Found modifications, replacing node')
@@ -126,7 +125,7 @@ export function processContent(
126125
combinedPattern: RegExp,
127126
): void {
128127
logger.info('processContent called with selectors:', config.selectors.include)
129-
128+
130129
// Process each include selector
131130
config.selectors.include.forEach((selector) => {
132131
try {

src/runtime/smartscript/patterns.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { PatternSet, SuperscriptConfig } from './types'
77
/**
88
* Create regex patterns based on configuration
99
*/
10-
export function createPatterns(config: SuperscriptConfig): PatternSet {
10+
export function createPatterns(_config: SuperscriptConfig): PatternSet {
1111
return {
1212
// Matches ™, (TM), or standalone TM
1313
trademark: /|\(TM\)|\bTM\b/g,
@@ -26,7 +26,7 @@ export function createPatterns(config: SuperscriptConfig): PatternSet {
2626

2727
// Matches math superscript notation: x^2, x^n, x^{expr}
2828
// Pattern: /(?<=^|[\s=+\-*/().,\d]|[a-z])([a-zA-Z])\^(\d+|[a-zA-Z]|\{[^}]+\})/g
29-
//
29+
//
3030
// Breakdown:
3131
// - (?<=...) - Positive lookbehind to ensure proper context
3232
// - ^|[\s=+\-*/().,\d] - After start of string, whitespace, operators, or digits
@@ -47,7 +47,7 @@ export function createPatterns(config: SuperscriptConfig): PatternSet {
4747
// Examples that DON'T MATCH:
4848
// - "file^name" - 'e' is after 'l' but we still match (limitation)
4949
// - "MAX^2" - 'X' is after uppercase 'A' (blocked by lookbehind)
50-
mathSuper: /(?<=^|[\s=+\-*/().,\d]|[a-z])([a-zA-Z])\^(\d+|[a-zA-Z]|\{[^}]+\})/g,
50+
mathSuper: /(?<=^|[\s=+\-*/().,\da-z])([a-zA-Z])\^(\d+|[a-zA-Z]|\{[^}]+\})/g,
5151

5252
// Matches math subscript notation: x_1, x_n, x_{expr}
5353
// Pattern: /(?<=^|[\s=+\-*/().,])([a-zA-Z])_(\d+|[a-zA-Z]|\{[^}]+\})/g
@@ -70,7 +70,7 @@ export function createPatterns(config: SuperscriptConfig): PatternSet {
7070
// - "file_name" - 'e' is after letter 'l' (blocked by lookbehind)
7171
// - "some_var" - 'e' is after letter 'm' (blocked by lookbehind)
7272
// - "log_2" - 'g' is after letter 'o' (blocked by lookbehind)
73-
mathSub: /(?<=^|[\s=+\-*/().,])([a-zA-Z])_(\d+|[a-zA-Z]|\{[^}]+\})/g,
73+
mathSub: /(?<=^|[\s=+\-*/().,])([a-z])_(\d+|[a-z]|\{[^}]+\})/gi,
7474
}
7575
}
7676

@@ -97,12 +97,12 @@ export function createCombinedPattern(patterns: PatternSet, config: SuperscriptC
9797
export const PatternMatchers = {
9898
isTrademark: (text: string): boolean => /^(?:|\(TM\)|TM)$/.test(text),
9999
isRegistered: (text: string): boolean => /^(?:®|\(R\))$/.test(text),
100-
isCopyright: (text: string): boolean => /(?:©|\(C\))/.test(text),
100+
isCopyright: (text: string): boolean => /©|\(C\)/.test(text),
101101
isOrdinal: (text: string): boolean => /^\d+(?:st|nd|rd|th)$/.test(text),
102102
isChemicalElement: (text: string): boolean => /^[A-Z][a-z]?\d+$/.test(text),
103103
isChemicalParentheses: (text: string): boolean => /^\)\d+$/.test(text),
104-
isMathSuperscript: (text: string): boolean => /^[a-zA-Z]\^/.test(text),
105-
isMathSubscript: (text: string): boolean => /^[a-zA-Z]_/.test(text),
104+
isMathSuperscript: (text: string): boolean => /^[a-z]\^/i.test(text),
105+
isMathSubscript: (text: string): boolean => /^[a-z]_/i.test(text),
106106
}
107107

108108
/**
@@ -128,24 +128,24 @@ export const PatternExtractors = {
128128
return text.substring(1).replace(/[{}]/g, '')
129129
},
130130

131-
extractMathWithVariable: (text: string): { variable: string; script: string } | null => {
131+
extractMathWithVariable: (text: string): { variable: string, script: string } | null => {
132132
// Handle x^2, x_n, x^{10}, x_{n+1} etc.
133-
const superMatch = text.match(/^([a-zA-Z])\^(.+)$/)
133+
const superMatch = text.match(/^([a-z])\^(.+)$/i)
134134
if (superMatch) {
135135
return {
136136
variable: superMatch[1],
137137
script: superMatch[2].replace(/[{}]/g, ''),
138138
}
139139
}
140-
141-
const subMatch = text.match(/^([a-zA-Z])_(.+)$/)
140+
141+
const subMatch = text.match(/^([a-z])_(.+)$/i)
142142
if (subMatch) {
143143
return {
144144
variable: subMatch[1],
145145
script: subMatch[2].replace(/[{}]/g, ''),
146146
}
147147
}
148-
148+
149149
return null
150150
},
151151
}

src/runtime/smartscript/processor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { logger } from './logger'
1111
*/
1212
export function processMatch(matched: string): ProcessingResult {
1313
logger.debug('processMatch called with:', matched)
14-
const parts: TextPart[] = []
1514

1615
// Trademark symbols - Unicode character already positioned
1716
if (PatternMatchers.isTrademark(matched)) {

0 commit comments

Comments
 (0)