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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -26,8 +26,9 @@ type CLI struct {
|
||||
}
|
||||
|
||||
type Language struct {
|
||||
LineComment string
|
||||
BlockComment *BlockComment
|
||||
LineComment string
|
||||
AlternateLineComment string
|
||||
BlockComment *BlockComment
|
||||
}
|
||||
|
||||
type BlockComment struct {
|
||||
|
||||
Reference in New Issue
Block a user