Skip to content

feat(transformers): add transformerRemoveComments#1144

Merged
antfu merged 9 commits intoshikijs:mainfrom
Bitshifter-9:main
Dec 3, 2025
Merged

feat(transformers): add transformerRemoveComments#1144
antfu merged 9 commits intoshikijs:mainfrom
Bitshifter-9:main

Conversation

@Bitshifter-9
Copy link
Contributor

Title: feat(transformers): add transformerRemoveComments

Description

This PR introduces a new transformer [transformerRemoveComments]
This transformer allows users to automatically remove comments from their code snippets. This is particularly useful for scenarios like presentation slides or minimal examples where comments might be distracting or consume valuable vertical space.

It uses includeExplanation: true to identify tokens with comment scopes (e.g., comment.line, comment.block) and filters them out. It also includes an option removeEmptyLines (defaulting to true) to clean up lines that become empty after comment removal.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@netlify
Copy link

netlify bot commented Nov 26, 2025

Deploy Preview for shiki-next ready!

Name Link
🔨 Latest commit 53f5a03
🔍 Latest deploy log https://app.netlify.com/projects/shiki-next/deploys/692fccff8302fb000875a286
😎 Deploy Preview https://deploy-preview-1144--shiki-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Nov 26, 2025

Deploy Preview for shiki-matsu ready!

Name Link
🔨 Latest commit 53f5a03
🔍 Latest deploy log https://app.netlify.com/projects/shiki-matsu/deploys/692fccfff1460c0007801772
😎 Deploy Preview https://deploy-preview-1144--shiki-matsu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Bitshifter-9
Copy link
Contributor Author

@antfu Raised PR Please take a look review and merge it ☺️

@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.20%. Comparing base (38c7f79) to head (53f5a03).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1144      +/-   ##
==========================================
+ Coverage   95.14%   95.20%   +0.05%     
==========================================
  Files          91       92       +1     
  Lines        7873     7922      +49     
  Branches     1673     1690      +17     
==========================================
+ Hits         7491     7542      +51     
+ Misses        376      374       -2     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Bitshifter-9
Copy link
Contributor Author

@antfu All chechks have passed
please take a review at the PR ☺️

@Bitshifter-9
Copy link
Contributor Author

@antfu Please Update if any Changes are required on this this PR

@Bitshifter-9 Bitshifter-9 changed the title changes done feat(transformers): add transformerRemoveComments Dec 2, 2025
@Bitshifter-9
Copy link
Contributor Author

@antfu Any Updates regarding this PR

Copilot AI review requested due to automatic review settings December 3, 2025 05:22
Copy link
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 introduces a new transformer transformerRemoveComments that automatically removes comments from code snippets. The transformer works by examining the TextMate grammar scope information to identify comment tokens and filter them out. It's designed for use cases like presentation slides or minimal examples where comments might be distracting.

Key changes:

  • New transformer implementation with support for removing lines that become empty after comment removal
  • Integration with the includeExplanation option to access token scope metadata
  • Basic test coverage and documentation

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/transformers/src/transformers/remove-comments.ts Core transformer implementation that filters tokens with comment scopes
packages/transformers/src/index.ts Exports the new transformer function
packages/types/src/options.ts Adds includeExplanation to the CodeToHastOptions interface to support the transformer
packages/transformers/test/fixtures.test.ts Adds test suite for the new transformer
packages/transformers/test/fixtures/remove-comments/basic.js Test input fixture with various comment types
packages/transformers/test/fixtures/remove-comments/basic.js.output.html Expected output for the test
docs/packages/transformers.md Documentation with usage examples and option descriptions
test/exports/@shikijs/transformers.yaml Export validation test ensuring the transformer is properly exported

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

Comment on lines +272 to +287
suite(
'remove-comments',
import.meta.glob('./fixtures/remove-comments/*.*', { query: '?raw', import: 'default', eager: true }),
[
transformerRemoveComments(),
transformerRemoveLineBreak(),
],
code => `${code}
<style>
body { margin: 0; }
.shiki { padding: 1em; }
.line { display: block; width: 100%; height: 1.2em; }
</style>`,
undefined,
{ includeExplanation: true },
)
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Test coverage for transformerRemoveComments is limited to a single basic JavaScript file. Consider adding test fixtures for:

  1. The removeEmptyLines: false option
  2. Different comment types (JSDoc comments, multi-line comments spanning multiple lines)
  3. Different languages (TypeScript, Python, etc.) to ensure scope detection works across grammars
  4. Edge cases like comments within strings (which should not be removed)

Other transformers in this codebase (e.g., highlight) have multiple test fixtures covering various scenarios.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,6 @@
// This is a comment
const x = 1; // Inline comment
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Unused variable x.

Suggested change
const x = 1; // Inline comment

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +5
const y = 2;

Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Unused variable y.

Suggested change
const y = 2;

Copilot uses AI. Check for mistakes.
antfu and others added 4 commits December 3, 2025 14:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants