A VS Code extension that intelligently removes comments and blank lines from your code while preserving strings, tool directives, and docstrings.
Features
Supported Languages
- Python (
.py)
- JavaScript (
.js)
- TypeScript (
.ts)
- JSX/TSX (
.jsx, .tsx)
- HTML (
.html)
- CSS (
.css)
Why This Extension?
Most comment removal extensions have a critical flaw: they delete anything after a # or //, even when it's inside a string. This extension properly parses your code to avoid breaking strings.
Example Problem with Other Extensions:
url = "https://example.com#anchor"
❌ Other extensions would break this by removing #anchor, leaving you with:
url = "https://example.com"
This Extension Handles It Correctly:
✅ Preserves # inside Python strings
✅ Preserves // inside JavaScript strings
✅ Preserves blank lines inside docstrings and template literals
✅ Handles escape sequences properly
✅ Preserves tool directive comments (ESLint, TypeScript, Prettier, etc.)
The extension automatically preserves important directive comments that tools need:
Python Directives
- Type hints:
# type:, # type ignore
- Linters:
# pylint:, # flake8:, # ruff:, # noqa
- Formatters:
# black:, # isort:, # yapep8:
- Type checkers:
# mypy:, # pyright:, # pyre:
- And many more...
JavaScript/TypeScript Directives
- TypeScript:
// @ts-ignore, // @ts-expect-error
- ESLint:
// eslint-disable, /* eslint-disable */
- Prettier:
// prettier-ignore
- Testing:
// @jest, // @vitest
- Build tools:
/* @__PURE__ */, // @vite
- Regions:
// #region, // #endregion
- And many more...
Usage
- Open a supported file (Python, JavaScript, TypeScript, HTML, or CSS)
- Press
Ctrl+Shift+P (or Cmd+Shift+P on Mac)
- Choose either:
Remove All Comments (Smart)
Remove All Blank Lines (Smart)
Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions (
Ctrl+Shift+X)
- Search for "Smart Remover"
- Click Install
From VSIX File
- Download the
.vsix file
- Open VS Code
- Press
Ctrl+Shift+P
- Type "Install from VSIX"
- Select the downloaded file
- Reload VS Code
From Source
npm install -g @vscode/vsce
git clone https://github.com/evanroby/smart-remover
cd smart-comment-remover
npm install
vsce package
code --install-extension smart-comment-remover-0.0.4.vsix
Examples
Before:
def calculate_total(items):
# Calculate the sum of all items
total = 0 # Initialize counter
for item in items:
total += item # Add each item
return total
After:
def calculate_total(items):
total = 0
for item in items:
total += item
return total
Preserves strings with #:
url = "https://example.com#section" # This comment is removed
api_key = "abc123#def456" # But the # in strings stays!
After:
url = "https://example.com#section"
api_key = "abc123#def456"
Preserves directive comments:
def process_data(data: list) -> int: # type: ignore
result = sum(data) # noqa: E501
return result
After:
def process_data(data: list) -> int: # type: ignore
result = sum(data) # noqa: E501
return result
Before:
function fetchData() {
// Fetch data from API
const url = "https://api.example.com/data"; // API endpoint
/*
* This is a multiline comment
* explaining the fetch logic
*/
return fetch(url);
}
After:
function fetchData() {
const url = "https://api.example.com/data";
return fetch(url);
}
Preserves directive comments:
// @ts-ignore
const result = riskyOperation();
/* eslint-disable no-console */
console.log("Debug info");
// prettier-ignore
const matrix = [
1, 2, 3,
4, 5, 6
];
After:
// @ts-ignore
const result = riskyOperation();
/* eslint-disable no-console */
console.log("Debug info");
// prettier-ignore
const matrix = [
1, 2, 3,
4, 5, 6
];
Remove Blank Lines
Python - Before:
def greet(name):
"""
Greet a person by name.
This function has blank lines in the docstring.
"""
message = f"Hello, {name}!"
print(message)
Python - After:
def greet(name):
"""
Greet a person by name.
This function has blank lines in the docstring.
"""
message = f"Hello, {name}!"
print(message)
Note: Blank lines inside the docstring are preserved!
JavaScript - Before:
function display() {
const template = `
<div>
<h1>Title</h1>
</div>
`;
render(template);
}
JavaScript - After:
function display() {
const template = `
<div>
<h1>Title</h1>
</div>
`;
render(template);
}
Note: Blank lines inside the template literal are preserved!
Requirements
Known Issues
None currently. Please report issues on GitHub.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Release Notes
0.0.4
- Fixed the README.md
- Fixed the package.json vscode engines part (feat hardstucksilver_123)
0.0.3
- Added support for preserving tool directive comments
- Improved Python multiline string handling
0.0.2
- Added JSX/TSX support
- Improved blank line removal logic
0.0.1
- Initial release
- Support for Python, JavaScript/TypeScript, HTML/CSS
- Smart comment removal
- Smart blank line removal
License
MIT
Author
evanroby
Created to solve the problem of extensions that blindly remove everything after comment characters, even inside strings.
Enjoying this extension? Give it a ⭐ on GitHub!