Skip to content

Instantly share code, notes, and snippets.

@vkuprin
Last active September 8, 2025 15:56
Show Gist options
  • Select an option

  • Save vkuprin/4f2489965118160b1526466a2af4bd1d to your computer and use it in GitHub Desktop.

Select an option

Save vkuprin/4f2489965118160b1526466a2af4bd1d to your computer and use it in GitHub Desktop.
git ls-files -c "*.js" "*.jsx" "*.ts" "*.tsx" | xargs -I{} perl -i -0pe '
# First, handle specific JSX/TSX comment blocks with curly braces
s|\{\/\*.*?\*\/\}||gs;
# Then handle regular comments
s|(?<!\:)//[^\n]*| |g;
s|/\*.*?\*/| |gs;
# Clean up extra whitespace
s|[ \t]+\n|\n|g;
' {}
@vkuprin
Copy link
Author

vkuprin commented Sep 8, 2025

#!/bin/bash

# Get list of modified files in current branch compared to main
# Filter for JS/JSX/TS/TSX files only
git diff --name-only main...HEAD | grep -E '\.(js|jsx|ts|tsx)$' | xargs -I{} perl -i -0pe '
# First, handle specific JSX/TSX comment blocks with curly braces
s|\{\/\*.*?\*\/\}||gs;
# Then handle regular comments
s|(?<!\:)//[^\n]*|  |g;
s|/\*.*?\*/|  |gs;
# Clean up extra whitespace
s|[ \t]+\n|\n|g;
' {}

@vkuprin
Copy link
Author

vkuprin commented Sep 8, 2025

# Preview which files will be processed
echo "Files that will have comments removed:"
git diff --name-only main...HEAD | grep -E '\.(js|jsx|ts|tsx)$'

# Then run the actual command
git diff --name-only main...HEAD | grep -E '\.(js|jsx|ts|tsx)$' | xargs -I{} perl -i -0pe '
# First, handle specific JSX/TSX comment blocks with curly braces
s|\{\/\*.*?\*\/\}||gs;
# Then handle regular comments
s|(?<!\:)//[^\n]*|  |g;
s|/\*.*?\*/|  |gs;
# Clean up extra whitespace
s|[ \t]+\n|\n|g;
' {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment