feat: add support for 30+ languages and update README

- Add support for Rust, C#, PHP, Swift, Kotlin, SQL
- Add support for HTML, XML, CSS, SCSS markup languages
- Add support for JSX/TSX, Dart, Scala
- Add support for shell variants, config files, and more
- Add AlternateLineComment support for INI files
- Update README with comprehensive language tables
- Bump version to 0.2.1
This commit is contained in:
carraes
2025-07-06 22:02:41 -03:00
parent 0b9067daf5
commit 8152e62cf5
5 changed files with 167 additions and 38 deletions
+48 -12
View File
@@ -62,18 +62,54 @@ shush src/ --recursive --inline --dry-run --verbose
## Supported Languages
| Language | Line Comments | Block Comments |
|----------|--------------|----------------|
| Python | `#` | - |
| JavaScript/TypeScript | `//` | `/* */` |
| Go | `//` | `/* */` |
| C/C++ | `//` | `/* */` |
| Java | `//` | `/* */` |
| Lua | `--` | - |
| Shell/Bash | `#` | - |
| Ruby | `#` | - |
| Perl | `#` | - |
| YAML | `#` | - |
### Programming Languages
| Language | Extensions | Line Comments | Block Comments |
|----------|------------|---------------|----------------|
| **C/C++** | `.c`, `.cpp`, `.cc`, `.cxx`, `.h`, `.hpp` | `//` | `/* */` |
| **C#** | `.cs` | `//` | `/* */` |
| **Dart** | `.dart` | `//` | `/* */` |
| **Go** | `.go` | `//` | `/* */` |
| **Java** | `.java` | `//` | `/* */` |
| **JavaScript** | `.js`, `.jsx` | `//` | `/* */` |
| **Kotlin** | `.kt`, `.kts` | `//` | `/* */` |
| **Lua** | `.lua` | `--` | - |
| **Perl** | `.pl` | `#` | - |
| **PHP** | `.php` | `//` | `/* */` |
| **Python** | `.py` | `#` | - |
| **R** | `.r` | `#` | - |
| **Ruby** | `.rb` | `#` | - |
| **Rust** | `.rs` | `//` | `/* */` |
| **Scala** | `.scala` | `//` | `/* */` |
| **Swift** | `.swift` | `//` | `/* */` |
| **TypeScript** | `.ts`, `.tsx` | `//` | `/* */` |
### Web & Markup Languages
| Language | Extensions | Line Comments | Block Comments |
|----------|------------|---------------|----------------|
| **CSS** | `.css` | - | `/* */` |
| **HTML** | `.html`, `.htm` | - | `<!-- -->` |
| **Less** | `.less` | `//` | `/* */` |
| **Sass/SCSS** | `.sass`, `.scss` | `//` | `/* */` |
| **SVG** | `.svg` | - | `<!-- -->` |
| **XML** | `.xml` | - | `<!-- -->` |
### Shell & Config Languages
| Language | Extensions | Line Comments | Block Comments |
|----------|------------|---------------|----------------|
| **Bash** | `.bash` | `#` | - |
| **Config** | `.conf`, `.cfg` | `#` | - |
| **Dockerfile** | `dockerfile` | `#` | - |
| **Fish** | `.fish` | `#` | - |
| **INI** | `.ini` | `#`, `;` | - |
| **Makefile** | `makefile` | `#` | - |
| **PowerShell** | `.ps1` | `#` | - |
| **Shell** | `.sh` | `#` | - |
| **SQL** | `.sql` | `--` | `/* */` |
| **TOML** | `.toml` | `#` | - |
| **YAML** | `.yml`, `.yaml` | `#` | - |
| **Zsh** | `.zsh` | `#` | - |
**Total: 40+ file extensions supported** across 30+ languages
## Options
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"github.com/carlosarraes/shush/internal/types"
)
var version = "0.2.0"
var version = "0.2.1"
func main() {
var cliArgs types.CLI
+23 -11
View File
@@ -204,18 +204,27 @@ func (p *Processor) removeCommentsFromLine(line string, language types.Language,
result := line
hasChanges := false
if !p.cli.Block && language.LineComment != "" {
if idx := p.findCommentIndex(result, language.LineComment); idx != -1 {
comment := strings.TrimSpace(result[idx:])
if cfg.ShouldPreserveComment(comment) {
return originalLine
if !p.cli.Block {
if language.LineComment != "" {
if idx := p.findCommentIndex(result, language.LineComment); idx != -1 {
comment := strings.TrimSpace(result[idx:])
if cfg.ShouldPreserveComment(comment) {
return originalLine
}
result = result[:idx]
hasChanges = true
}
}
result = result[:idx]
hasChanges = true
if language.AlternateLineComment != "" && !hasChanges {
if idx := p.findCommentIndex(result, language.AlternateLineComment); idx != -1 {
comment := strings.TrimSpace(result[idx:])
if cfg.ShouldPreserveComment(comment) {
return originalLine
}
result = result[:idx]
hasChanges = true
}
}
}
@@ -402,11 +411,14 @@ func (p *Processor) findCommentIndex(line, commentMarker string) int {
// lineHasComment checks if a line contains comments
func (p *Processor) lineHasComment(line string, language types.Language) bool {
if language.LineComment != "" && p.findCommentIndex(line, language.LineComment) != -1 {
return true
}
if language.AlternateLineComment != "" && p.findCommentIndex(line, language.AlternateLineComment) != -1 {
return true
}
if language.BlockComment != nil {
if p.findCommentIndex(line, language.BlockComment.Start) != -1 || p.findCommentIndex(line, language.BlockComment.End) != -1 {
return true
+92 -12
View File
@@ -12,16 +12,56 @@ var languageMap = map[string]types.Language{
"lua": {LineComment: "--"},
"py": {LineComment: "#"},
"sh": {LineComment: "#"},
"js": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"ts": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"go": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"c": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"cpp": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"java": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"bash": {LineComment: "#"},
"zsh": {LineComment: "#"},
"fish": {LineComment: "#"},
"ps1": {LineComment: "#"},
"r": {LineComment: "#"},
"js": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"ts": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"jsx": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"tsx": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"go": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"c": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"cpp": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"cc": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"cxx": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"h": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"hpp": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"java": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"cs": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"rs": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"swift": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"kt": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"kts": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"dart": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"scala": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"php": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"css": {BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"scss": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"sass": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"less": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"html": {BlockComment: &types.BlockComment{Start: "<!--", End: "-->"}},
"htm": {BlockComment: &types.BlockComment{Start: "<!--", End: "-->"}},
"xml": {BlockComment: &types.BlockComment{Start: "<!--", End: "-->"}},
"svg": {BlockComment: &types.BlockComment{Start: "<!--", End: "-->"}},
"rb": {LineComment: "#"},
"pl": {LineComment: "#"},
"yml": {LineComment: "#"},
"yaml": {LineComment: "#"},
"toml": {LineComment: "#"},
"ini": {LineComment: "#", AlternateLineComment: ";"},
"conf": {LineComment: "#"},
"cfg": {LineComment: "#"},
"sql": {LineComment: "--", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"dockerfile": {LineComment: "#"},
"makefile": {LineComment: "#"},
}
func DetectLanguage(filename string) (types.Language, error) {
@@ -47,16 +87,56 @@ func GetLanguageName(filename string) string {
"lua": "Lua",
"py": "Python",
"sh": "Shell",
"js": "JavaScript",
"ts": "TypeScript",
"go": "Go",
"c": "C",
"cpp": "C++",
"java": "Java",
"bash": "Bash",
"zsh": "Zsh",
"fish": "Fish",
"ps1": "PowerShell",
"r": "R",
"js": "JavaScript",
"ts": "TypeScript",
"jsx": "JSX",
"tsx": "TSX",
"go": "Go",
"c": "C",
"cpp": "C++",
"cc": "C++",
"cxx": "C++",
"h": "C Header",
"hpp": "C++ Header",
"java": "Java",
"cs": "C#",
"rs": "Rust",
"swift": "Swift",
"kt": "Kotlin",
"kts": "Kotlin Script",
"dart": "Dart",
"scala": "Scala",
"php": "PHP",
"css": "CSS",
"scss": "SCSS",
"sass": "Sass",
"less": "Less",
"html": "HTML",
"htm": "HTML",
"xml": "XML",
"svg": "SVG",
"rb": "Ruby",
"pl": "Perl",
"yml": "YAML",
"yaml": "YAML",
"toml": "TOML",
"ini": "INI",
"conf": "Config",
"cfg": "Config",
"sql": "SQL",
"dockerfile": "Dockerfile",
"makefile": "Makefile",
}
if name, ok := names[ext]; ok {
+3 -2
View File
@@ -26,8 +26,9 @@ type CLI struct {
}
type Language struct {
LineComment string
BlockComment *BlockComment
LineComment string
AlternateLineComment string
BlockComment *BlockComment
}
type BlockComment struct {