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:
@@ -62,18 +62,54 @@ shush src/ --recursive --inline --dry-run --verbose
|
|||||||
|
|
||||||
## Supported Languages
|
## Supported Languages
|
||||||
|
|
||||||
| Language | Line Comments | Block Comments |
|
### Programming Languages
|
||||||
|----------|--------------|----------------|
|
| Language | Extensions | Line Comments | Block Comments |
|
||||||
| Python | `#` | - |
|
|----------|------------|---------------|----------------|
|
||||||
| JavaScript/TypeScript | `//` | `/* */` |
|
| **C/C++** | `.c`, `.cpp`, `.cc`, `.cxx`, `.h`, `.hpp` | `//` | `/* */` |
|
||||||
| Go | `//` | `/* */` |
|
| **C#** | `.cs` | `//` | `/* */` |
|
||||||
| C/C++ | `//` | `/* */` |
|
| **Dart** | `.dart` | `//` | `/* */` |
|
||||||
| Java | `//` | `/* */` |
|
| **Go** | `.go` | `//` | `/* */` |
|
||||||
| Lua | `--` | - |
|
| **Java** | `.java` | `//` | `/* */` |
|
||||||
| Shell/Bash | `#` | - |
|
| **JavaScript** | `.js`, `.jsx` | `//` | `/* */` |
|
||||||
| Ruby | `#` | - |
|
| **Kotlin** | `.kt`, `.kts` | `//` | `/* */` |
|
||||||
| Perl | `#` | - |
|
| **Lua** | `.lua` | `--` | - |
|
||||||
| YAML | `#` | - |
|
| **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
|
## Options
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/carlosarraes/shush/internal/types"
|
"github.com/carlosarraes/shush/internal/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "0.2.0"
|
var version = "0.2.1"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var cliArgs types.CLI
|
var cliArgs types.CLI
|
||||||
|
|||||||
@@ -204,21 +204,30 @@ func (p *Processor) removeCommentsFromLine(line string, language types.Language,
|
|||||||
result := line
|
result := line
|
||||||
hasChanges := false
|
hasChanges := false
|
||||||
|
|
||||||
if !p.cli.Block && language.LineComment != "" {
|
if !p.cli.Block {
|
||||||
|
if language.LineComment != "" {
|
||||||
if idx := p.findCommentIndex(result, language.LineComment); idx != -1 {
|
if idx := p.findCommentIndex(result, language.LineComment); idx != -1 {
|
||||||
|
|
||||||
comment := strings.TrimSpace(result[idx:])
|
comment := strings.TrimSpace(result[idx:])
|
||||||
|
|
||||||
if cfg.ShouldPreserveComment(comment) {
|
if cfg.ShouldPreserveComment(comment) {
|
||||||
return originalLine
|
return originalLine
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result[:idx]
|
result = result[:idx]
|
||||||
hasChanges = true
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !p.cli.Inline && language.BlockComment != nil {
|
if !p.cli.Inline && language.BlockComment != nil {
|
||||||
|
|
||||||
startComment := language.BlockComment.Start
|
startComment := language.BlockComment.Start
|
||||||
@@ -402,11 +411,14 @@ func (p *Processor) findCommentIndex(line, commentMarker string) int {
|
|||||||
|
|
||||||
// lineHasComment checks if a line contains comments
|
// lineHasComment checks if a line contains comments
|
||||||
func (p *Processor) lineHasComment(line string, language types.Language) bool {
|
func (p *Processor) lineHasComment(line string, language types.Language) bool {
|
||||||
|
|
||||||
if language.LineComment != "" && p.findCommentIndex(line, language.LineComment) != -1 {
|
if language.LineComment != "" && p.findCommentIndex(line, language.LineComment) != -1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if language.AlternateLineComment != "" && p.findCommentIndex(line, language.AlternateLineComment) != -1 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if language.BlockComment != nil {
|
if language.BlockComment != nil {
|
||||||
if p.findCommentIndex(line, language.BlockComment.Start) != -1 || p.findCommentIndex(line, language.BlockComment.End) != -1 {
|
if p.findCommentIndex(line, language.BlockComment.Start) != -1 || p.findCommentIndex(line, language.BlockComment.End) != -1 {
|
||||||
return true
|
return true
|
||||||
|
|||||||
@@ -12,16 +12,56 @@ var languageMap = map[string]types.Language{
|
|||||||
"lua": {LineComment: "--"},
|
"lua": {LineComment: "--"},
|
||||||
"py": {LineComment: "#"},
|
"py": {LineComment: "#"},
|
||||||
"sh": {LineComment: "#"},
|
"sh": {LineComment: "#"},
|
||||||
|
"bash": {LineComment: "#"},
|
||||||
|
"zsh": {LineComment: "#"},
|
||||||
|
"fish": {LineComment: "#"},
|
||||||
|
"ps1": {LineComment: "#"},
|
||||||
|
"r": {LineComment: "#"},
|
||||||
|
|
||||||
"js": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
|
"js": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
|
||||||
"ts": {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: "*/"}},
|
"go": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
|
||||||
"c": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
|
"c": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
|
||||||
"cpp": {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: "*/"}},
|
"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: "#"},
|
"rb": {LineComment: "#"},
|
||||||
"pl": {LineComment: "#"},
|
"pl": {LineComment: "#"},
|
||||||
"yml": {LineComment: "#"},
|
"yml": {LineComment: "#"},
|
||||||
"yaml": {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) {
|
func DetectLanguage(filename string) (types.Language, error) {
|
||||||
@@ -47,16 +87,56 @@ func GetLanguageName(filename string) string {
|
|||||||
"lua": "Lua",
|
"lua": "Lua",
|
||||||
"py": "Python",
|
"py": "Python",
|
||||||
"sh": "Shell",
|
"sh": "Shell",
|
||||||
|
"bash": "Bash",
|
||||||
|
"zsh": "Zsh",
|
||||||
|
"fish": "Fish",
|
||||||
|
"ps1": "PowerShell",
|
||||||
|
"r": "R",
|
||||||
|
|
||||||
"js": "JavaScript",
|
"js": "JavaScript",
|
||||||
"ts": "TypeScript",
|
"ts": "TypeScript",
|
||||||
|
"jsx": "JSX",
|
||||||
|
"tsx": "TSX",
|
||||||
"go": "Go",
|
"go": "Go",
|
||||||
"c": "C",
|
"c": "C",
|
||||||
"cpp": "C++",
|
"cpp": "C++",
|
||||||
|
"cc": "C++",
|
||||||
|
"cxx": "C++",
|
||||||
|
"h": "C Header",
|
||||||
|
"hpp": "C++ Header",
|
||||||
"java": "Java",
|
"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",
|
"rb": "Ruby",
|
||||||
"pl": "Perl",
|
"pl": "Perl",
|
||||||
"yml": "YAML",
|
"yml": "YAML",
|
||||||
"yaml": "YAML",
|
"yaml": "YAML",
|
||||||
|
"toml": "TOML",
|
||||||
|
"ini": "INI",
|
||||||
|
"conf": "Config",
|
||||||
|
"cfg": "Config",
|
||||||
|
|
||||||
|
"sql": "SQL",
|
||||||
|
|
||||||
|
"dockerfile": "Dockerfile",
|
||||||
|
"makefile": "Makefile",
|
||||||
}
|
}
|
||||||
|
|
||||||
if name, ok := names[ext]; ok {
|
if name, ok := names[ext]; ok {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ type CLI struct {
|
|||||||
|
|
||||||
type Language struct {
|
type Language struct {
|
||||||
LineComment string
|
LineComment string
|
||||||
|
AlternateLineComment string
|
||||||
BlockComment *BlockComment
|
BlockComment *BlockComment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user