From 18e6c2c443365c6be9a94d4248f44a0e811e5793 Mon Sep 17 00:00:00 2001 From: Kwame Akuamoah-Boateng Date: Fri, 4 Aug 2023 11:57:40 +0000 Subject: [PATCH] Improve language detection code and add new gitignore files --- cmd/goignore/main.go | 39 ++++++++++++++------- cmd/goignore/templates/c.txt | 52 +++++++++++++++++++++++++++ cmd/goignore/templates/haskell.txt | 23 ++++++++++++ cmd/goignore/templates/ruby.txt | 56 ++++++++++++++++++++++++++++++ cmd/goignore/templates/rust.txt | 14 ++++++++ 5 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 cmd/goignore/templates/c.txt create mode 100644 cmd/goignore/templates/haskell.txt create mode 100644 cmd/goignore/templates/ruby.txt create mode 100644 cmd/goignore/templates/rust.txt diff --git a/cmd/goignore/main.go b/cmd/goignore/main.go index d6fc4a8..7cc0149 100644 --- a/cmd/goignore/main.go +++ b/cmd/goignore/main.go @@ -11,6 +11,17 @@ import ( "github.com/spf13/cobra" ) +var extensions = map[string][]string{ + "golang": {".go"}, + "javascript": {".js", ".ts", ".tsx"}, + "python": {".py"}, + "c++": {".cpp", ".h"}, + "rust": {".rs"}, + "ruby": {".rb"}, + "c": {".c"}, + "haskell": {".hs"}, +} + var language string var autoDetect bool @@ -91,26 +102,28 @@ func detectLanguage() string { } for _, file := range files { - if !file.IsDir() { - ext := filepath.Ext(file.Name()) - if ext == ".go" { - return "golang" - } else if ext == ".js" || ext == ".ts" || ext == ".tsx" { - return "javaScript" - } else if ext == ".py" { - return "python" - } else if ext == ".cpp" || ext == ".h" { - return "c++" + if file.IsDir() { + continue + } + ext := filepath.Ext(file.Name()) + for lang, exts := range extensions{ + for _, e := range exts { + if ext == e { + return lang + } } } } - return "" } func getSupportedLanguages() []string { - // Add any additional supported languages here - return []string{"python", "javascript", "golang", "c++"} + result := []string{} + + for lang := range extensions { + result = append(result, lang) + } + return result } func init() { diff --git a/cmd/goignore/templates/c.txt b/cmd/goignore/templates/c.txt new file mode 100644 index 0000000..c6127b3 --- /dev/null +++ b/cmd/goignore/templates/c.txt @@ -0,0 +1,52 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf diff --git a/cmd/goignore/templates/haskell.txt b/cmd/goignore/templates/haskell.txt new file mode 100644 index 0000000..4c9e245 --- /dev/null +++ b/cmd/goignore/templates/haskell.txt @@ -0,0 +1,23 @@ +dist +dist-* +cabal-dev +*.o +*.hi +*.hie +*.chi +*.chs.h +*.dyn_o +*.dyn_hi +.hpc +.hsenv +.cabal-sandbox/ +cabal.sandbox.config +*.prof +*.aux +*.hp +*.eventlog +.stack-work/ +cabal.project.local +cabal.project.local~ +.HTF/ +.ghc.environment.* diff --git a/cmd/goignore/templates/ruby.txt b/cmd/goignore/templates/ruby.txt new file mode 100644 index 0000000..e3200e0 --- /dev/null +++ b/cmd/goignore/templates/ruby.txt @@ -0,0 +1,56 @@ +*.gem +*.rbc +/.config +/coverage/ +/InstalledFiles +/pkg/ +/spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ +/tmp/ + +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. +.byebug_history + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* diff --git a/cmd/goignore/templates/rust.txt b/cmd/goignore/templates/rust.txt new file mode 100644 index 0000000..6985cf1 --- /dev/null +++ b/cmd/goignore/templates/rust.txt @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb