Skip to content

test(linter/plugins): remove @ts-expect-error from tests#16795

Merged
graphite-app[bot] merged 1 commit intomainfrom
12-13-test_linter_plugins_remove_ts-expect-error_from_tests
Dec 13, 2025
Merged

test(linter/plugins): remove @ts-expect-error from tests#16795
graphite-app[bot] merged 1 commit intomainfrom
12-13-test_linter_plugins_remove_ts-expect-error_from_tests

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Dec 13, 2025

Remove // @ts-expect-error and // @ts-ignore comments from test fixtures, and use assertions instead. This makes sure that the input to methods under test is what we intend it to be.

Note: Using assert rather than expect, because assert gives TypeScript information about types, which expect doesn't seem to be capable of.

@github-actions github-actions bot added A-linter Area - Linter A-cli Area - CLI A-linter-plugins Area - Linter JS plugins C-test Category - Testing. Code is missing test cases, or a PR is adding them labels Dec 13, 2025
Copy link
Copy Markdown
Member Author

overlookmotel commented Dec 13, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Copy Markdown

@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

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

The main remaining issue is that several places replace TS suppressions with assertions, but still rely on unchecked indexing (declarations[0]) and non-null assertions (init!), which undermines the goal of making test intent explicit. Adding a couple of targeted assertions (array non-empty, init != null) would make failures clearer and more robust. There’s also some repeated AST-unwrapping logic in the JSX tests that could be factored into a small helper for maintainability.

Summary of changes

What changed

apps/oxlint/test/fixtures/sourceCode/plugin.ts

  • Replaced // @ts-ignore-based property access with runtime assertions to narrow AST node types.
  • Extracted ast.body[0] into stmt, asserted VariableDeclaration, then asserted id is an Identifier and used id.name in the reported message.

apps/oxlint/test/isSpaceBetween.test.ts

  • Added node:assert and switched fixture AST typing from a generic Node[] cast to Program.
  • Replaced // @ts-expect-error accesses with explicit structural assertions (stmt.type, jsx.type, closingElement !== null, non-null first/last nodes/tokens).
  • Expanded coverage by asserting isSpaceBetween* behavior for both argument orders (normal and reversed).
  • Minor test description grammar fix ("either" → "if either").

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves type safety in test files by removing @ts-expect-error and @ts-ignore comments and replacing them with explicit runtime assertions using node:assert. This ensures that test inputs are validated to be what the tests expect them to be, while also providing TypeScript with proper type narrowing information that expect assertions cannot provide.

Key Changes:

  • Replace type suppression comments with explicit assert and assert.strictEqual checks
  • Add proper type assertions for AST nodes (checking types like "VariableDeclaration", "Identifier", "JSXElement")
  • Extract values into named variables before assertions for better readability
  • Add test cases for reversed argument order in isSpaceBetween tests

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/oxlint/test/isSpaceBetween.test.ts Replaced @ts-expect-error comments with explicit assertions for null checks, type checks, and added reversed-order test cases for thoroughness
apps/oxlint/test/fixtures/sourceCode/plugin.ts Replaced @ts-ignore comments with type assertions and extracted AST node properties into variables with proper type validation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@overlookmotel overlookmotel self-assigned this Dec 13, 2025
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Dec 13, 2025
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 13, 2025

Merge activity

Remove `// @ts-expect-error` and `// @ts-ignore` comments from test fixtures, and use assertions instead. This makes sure that the input to methods under test is what we intend it to be.

Note: Using `assert` rather than `expect`, because `assert` gives TypeScript information about types, which `expect` doesn't seem to be capable of.
@graphite-app graphite-app bot force-pushed the 12-13-test_linter_plugins_remove_defunct_test_case branch from be35cb1 to 7277d4c Compare December 13, 2025 14:33
@graphite-app graphite-app bot force-pushed the 12-13-test_linter_plugins_remove_ts-expect-error_from_tests branch from 151fe2b to 26ae895 Compare December 13, 2025 14:34
Base automatically changed from 12-13-test_linter_plugins_remove_defunct_test_case to main December 13, 2025 14:39
@graphite-app graphite-app bot merged commit 26ae895 into main Dec 13, 2025
19 checks passed
@graphite-app graphite-app bot deleted the 12-13-test_linter_plugins_remove_ts-expect-error_from_tests branch December 13, 2025 14:39
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Dec 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-linter Area - Linter A-linter-plugins Area - Linter JS plugins C-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants