Clean up lint warnings, replace unsafe any usages, and tidy tests#1421
Clean up lint warnings, replace unsafe any usages, and tidy tests#1421
any usages, and tidy tests#1421Conversation
|
There was a problem hiding this comment.
Code Review
This pull request focuses on code cleanup, type safety improvements, and resolving linting issues across the codebase. Key changes include replacing any with unknown or specific types, removing unused imports and variables, and adding void expressions to silence unused parameter warnings. Feedback was provided regarding the unsafe use of non-null assertions in the Markdown renderer and the handling of unused parameters in the slide parser.
| const currentToken = tokens[idx]! | ||
| const inlineToken = tokens[idx + 1]! // text | ||
| if (inlineToken.content.startsWith(notesSeparator)) { | ||
| tokens[idx].tag = 'aside' | ||
| const classIndex = tokens[idx].attrIndex('class') | ||
| currentToken.tag = 'aside' | ||
| const classIndex = currentToken.attrIndex('class') | ||
|
|
||
| if (classIndex < 0) { | ||
| tokens[idx].attrPush(['class', notesClass]) // add new attribute | ||
| } else { | ||
| tokens[idx].attrs[classIndex][1] = notesClass // replace value of existing attr | ||
| currentToken.attrPush(['class', notesClass]) // add new attribute | ||
| } else if (currentToken.attrs) { | ||
| currentToken.attrs[classIndex][1] = notesClass // replace value of existing attr | ||
| } | ||
|
|
||
| // remote "note:" from content | ||
| tokens[idx + 1].content = inlineToken.content.replace(notesSeparator, '') | ||
| tokens[idx + 1].children[0].content = tokens[idx + 1].children[0].content.replace(notesSeparator, '') | ||
| inlineToken.content = inlineToken.content.replace(notesSeparator, '') | ||
| if (inlineToken.children && inlineToken.children[0]) { | ||
| inlineToken.children[0].content = inlineToken.children[0].content.replace(notesSeparator, '') | ||
| } | ||
|
|
||
| tokens[idx + 2].tag = 'aside' | ||
| tokens[idx + 2]!.tag = 'aside' |
There was a problem hiding this comment.
The use of non-null assertions (!) on tokens[idx + 1] and tokens[idx + 2] is unsafe. While the markdown-it parser typically produces a predictable sequence of tokens for paragraphs (open, inline, close), it is more robust to explicitly check for the existence of these tokens before accessing their properties. This ensures the renderer doesn't crash if the token stream is modified by other plugins or is otherwise unexpected.
const currentToken = tokens[idx]
const inlineToken = tokens[idx + 1] // text
const closeToken = tokens[idx + 2]
if (currentToken && inlineToken && inlineToken.content.startsWith(notesSeparator)) {
currentToken.tag = 'aside'
const classIndex = currentToken.attrIndex('class')
if (classIndex < 0) {
currentToken.attrPush(['class', notesClass]) // add new attribute
} else if (currentToken.attrs) {
currentToken.attrs[classIndex][1] = notesClass // replace value of existing attr
}
// remove "note:" from content
inlineToken.content = inlineToken.content.replace(notesSeparator, '')
if (inlineToken.children && inlineToken.children[0]) {
inlineToken.children[0].content = inlineToken.children[0].content.replace(notesSeparator, '')
}
if (closeToken) {
closeToken.tag = 'aside'
}
}| } | ||
|
|
||
| public parse(text: string, configuration: Configuration, partial = true) { | ||
| void partial |
There was a problem hiding this comment.
The partial parameter is currently unused in the parse method. Using void partial silences the lint warning but leaves dead code in the codebase. If the parameter is not required by an interface or intended for future use, it should be removed from the method signature. If it must remain, consider prefixing it with an underscore (e.g., _partial) to signal it is intentionally unused.



Motivation
anytypes flagged by static analysis.anyand potential runtime issues.Description
void nextto silence the "defined but never used" warning insrc/RevealServer.ts.anyin the VS Code test mock with safer types (unknownandvoid) and tighten event/command/cancellation token signatures insrc/test/__mocks__/vscode.ts.TextEditorRevealTypeimport fromsrc/RevealContext.tsand drop the unusedFrontMatterResultimport insrc/SlideParser.ts, while explicitly consuming thepartialparameter withvoid partialto avoid unused-argument warnings.any[]token typing in the Markdown-it note renderer withTokenfrommarkdown-it, add null-safety checks, and update manipulation to use non-null assertions where appropriate insrc/Markdown-it.ts.src/test/UnitTests/*andsrc/test/suite/extension.test.ts./* eslint-env node */tojest.config.jsto address environment-related lint messages.Testing
npm run -s test-compile, which completed successfully.npm test -- --runInBand src/test/UnitTests, and all test suites passed (14suites,57tests passed).npm run -s lint ., which failed due to an ESLint configuration/plugin incompatibility (plugin:sonarjs/recommendedcontains an unexpected top-level propertyname).Codex Task