mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-18 22:23:07 -03:00
refactoring: remove un-used code, add go doc, fix ci (#199)
Refactoring, consisting of - remove unused method `isAuxiliaryLanguage` and `FileCountList` in order to reduce public API surfaces (go/java) - add GoDoc to public APIs - ci: java profile use latest go src It also now mimics https://docs.travis-ci.com/user/languages/go/#go-import-path for non-go build image, as code relies on internal imports. TEST PLAN: - make test
This commit is contained in:
80
utils.go
80
utils.go
@ -8,53 +8,20 @@ import (
|
||||
"gopkg.in/src-d/enry.v1/data"
|
||||
)
|
||||
|
||||
var (
|
||||
auxiliaryLanguages = map[string]bool{
|
||||
"Other": true, "XML": true, "YAML": true, "TOML": true, "INI": true,
|
||||
"JSON": true, "TeX": true, "Public Key": true, "AsciiDoc": true,
|
||||
"AGS Script": true, "VimL": true, "Diff": true, "CMake": true, "fish": true,
|
||||
"Awk": true, "Graphviz (DOT)": true, "Markdown": true, "desktop": true,
|
||||
"XSLT": true, "SQL": true, "RMarkdown": true, "IRC log": true,
|
||||
"reStructuredText": true, "Twig": true, "CSS": true, "Batchfile": true,
|
||||
"Text": true, "HTML+ERB": true, "HTML": true, "Gettext Catalog": true,
|
||||
"Smarty": true, "Raw token data": true,
|
||||
}
|
||||
const binSniffLen = 8000
|
||||
|
||||
configurationLanguages = map[string]bool{
|
||||
"XML": true, "JSON": true, "TOML": true, "YAML": true, "INI": true, "SQL": true,
|
||||
}
|
||||
)
|
||||
|
||||
// IsAuxiliaryLanguage returns whether or not lang is an auxiliary language.
|
||||
func IsAuxiliaryLanguage(lang string) bool {
|
||||
_, ok := auxiliaryLanguages[lang]
|
||||
return ok
|
||||
var configurationLanguages = map[string]bool{
|
||||
"XML": true, "JSON": true, "TOML": true, "YAML": true, "INI": true, "SQL": true,
|
||||
}
|
||||
|
||||
// IsConfiguration returns whether or not path is using a configuration language.
|
||||
// IsConfiguration tells if filename is in one of the configuration languages.
|
||||
func IsConfiguration(path string) bool {
|
||||
language, _ := GetLanguageByExtension(path)
|
||||
_, is := configurationLanguages[language]
|
||||
return is
|
||||
}
|
||||
|
||||
// IsDotFile returns whether or not path has dot as a prefix.
|
||||
func IsDotFile(path string) bool {
|
||||
path = filepath.Clean(path)
|
||||
base := filepath.Base(path)
|
||||
return strings.HasPrefix(base, ".") && base != "." && base != ".."
|
||||
}
|
||||
|
||||
// IsVendor returns whether or not path is a vendor path.
|
||||
func IsVendor(path string) bool {
|
||||
return data.VendorMatchers.Match(path)
|
||||
}
|
||||
|
||||
// IsDocumentation returns whether or not path is a documentation path.
|
||||
func IsDocumentation(path string) bool {
|
||||
return data.DocumentationMatchers.Match(path)
|
||||
}
|
||||
|
||||
// IsImage tells if a given file is an image (PNG, JPEG or GIF format).
|
||||
func IsImage(path string) bool {
|
||||
extension := filepath.Ext(path)
|
||||
if extension == ".png" || extension == ".jpg" || extension == ".jpeg" || extension == ".gif" {
|
||||
@ -64,7 +31,8 @@ func IsImage(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func GetMimeType(path string, language string) string {
|
||||
// GetMIMEType returns a MIME type of a given file based on its languages.
|
||||
func GetMIMEType(path string, language string) string {
|
||||
if mime, ok := data.LanguagesMime[language]; ok {
|
||||
return mime
|
||||
}
|
||||
@ -76,13 +44,27 @@ func GetMimeType(path string, language string) string {
|
||||
return "text/plain"
|
||||
}
|
||||
|
||||
const sniffLen = 8000
|
||||
// IsDocumentation returns whether or not path is a documentation path.
|
||||
func IsDocumentation(path string) bool {
|
||||
return data.DocumentationMatchers.Match(path)
|
||||
}
|
||||
|
||||
// IsDotFile returns whether or not path has dot as a prefix.
|
||||
func IsDotFile(path string) bool {
|
||||
base := filepath.Base(filepath.Clean(path))
|
||||
return strings.HasPrefix(base, ".") && base != "."
|
||||
}
|
||||
|
||||
// IsVendor returns whether or not path is a vendor path.
|
||||
func IsVendor(path string) bool {
|
||||
return data.VendorMatchers.Match(path)
|
||||
}
|
||||
|
||||
// IsBinary detects if data is a binary value based on:
|
||||
// http://git.kernel.org/cgit/git/git.git/tree/xdiff-interface.c?id=HEAD#n198
|
||||
func IsBinary(data []byte) bool {
|
||||
if len(data) > sniffLen {
|
||||
data = data[:sniffLen]
|
||||
if len(data) > binSniffLen {
|
||||
data = data[:binSniffLen]
|
||||
}
|
||||
|
||||
if bytes.IndexByte(data, byte(0)) == -1 {
|
||||
@ -91,17 +73,3 @@ func IsBinary(data []byte) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// FileCount type stores language name and count of files belonging to the
|
||||
// language.
|
||||
type FileCount struct {
|
||||
Name string
|
||||
Count int
|
||||
}
|
||||
|
||||
// FileCountList type is a list of FileCounts.
|
||||
type FileCountList []FileCount
|
||||
|
||||
func (fcl FileCountList) Len() int { return len(fcl) }
|
||||
func (fcl FileCountList) Less(i, j int) bool { return fcl[i].Count < fcl[j].Count }
|
||||
func (fcl FileCountList) Swap(i, j int) { fcl[i], fcl[j] = fcl[j], fcl[i] }
|
||||
|
Reference in New Issue
Block a user