Skip to content

Clean up lint warnings, replace unsafe any usages, and tidy tests#1421

Merged
evilz merged 1 commit intomasterfrom
codex/clean-up-unused-variables-and-types
Apr 12, 2026
Merged

Clean up lint warnings, replace unsafe any usages, and tidy tests#1421
evilz merged 1 commit intomasterfrom
codex/clean-up-unused-variables-and-types

Conversation

@evilz
Copy link
Copy Markdown
Owner

@evilz evilz commented Apr 12, 2026

Motivation

  • Reduce TypeScript/ESLint noise by addressing unused variables/imports and unsafe any types flagged by static analysis.
  • Improve type-safety in the VS Code test mock and Markdown-it renderer to avoid any and potential runtime issues.
  • Remove stale test scaffolding and commented code to make test suites clearer and reduce false positives.

Description

  • Consume the unused Express error-handler parameter by adding void next to silence the "defined but never used" warning in src/RevealServer.ts.
  • Replace any in the VS Code test mock with safer types (unknown and void) and tighten event/command/cancellation token signatures in src/test/__mocks__/vscode.ts.
  • Remove an unused TextEditorRevealType import from src/RevealContext.ts and drop the unused FrontMatterResult import in src/SlideParser.ts, while explicitly consuming the partial parameter with void partial to avoid unused-argument warnings.
  • Replace loose any[] token typing in the Markdown-it note renderer with Token from markdown-it, add null-safety checks, and update manipulation to use non-null assertions where appropriate in src/Markdown-it.ts.
  • Clean test files by removing unused imports, eliminating commented-out test blocks, and simplifying a few test cases in src/test/UnitTests/* and src/test/suite/extension.test.ts.
  • Add /* eslint-env node */ to jest.config.js to address environment-related lint messages.

Testing

  • Ran npm run -s test-compile, which completed successfully.
  • Ran unit tests with npm test -- --runInBand src/test/UnitTests, and all test suites passed (14 suites, 57 tests passed).
  • Attempted npm run -s lint ., which failed due to an ESLint configuration/plugin incompatibility (plugin:sonarjs/recommended contains an unexpected top-level property name).

Codex Task

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +59 to +77
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'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

@evilz evilz merged commit 40f8ab2 into master Apr 12, 2026
12 checks passed
@evilz evilz deleted the codex/clean-up-unused-variables-and-types branch April 12, 2026 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant