From 2609939438eb8e17d0bcf7a815237dfc32a51ecd Mon Sep 17 00:00:00 2001 From: Soulou Date: Sun, 21 Jun 2015 18:06:00 +0200 Subject: [PATCH] gofmt all the code --- extractor.go | 41 +++++++++++----------- pe.go | 27 ++++++++------- pe_test.go | 96 +++++++++++++++++++++++++-------------------------- validators.go | 64 +++++++++++++++++----------------- 4 files changed, 115 insertions(+), 113 deletions(-) diff --git a/extractor.go b/extractor.go index 69d4b95..b7be986 100644 --- a/extractor.go +++ b/extractor.go @@ -2,29 +2,28 @@ package main import "regexp" - func pathExtractor(input string) [][][]byte { - surroundRegex := "[^][ \\t:'\"]" - r := regexp.MustCompile("("+surroundRegex+"*[\\./]"+surroundRegex+"*)") - temp := [][][]byte{} - temp = r.FindAllSubmatch([]byte(input),-1) - return temp + surroundRegex := "[^][ \\t:'\"]" + r := regexp.MustCompile("(" + surroundRegex + "*[\\./]" + surroundRegex + "*)") + temp := [][][]byte{} + temp = r.FindAllSubmatch([]byte(input), -1) + return temp } func getAllMatches(input string) []string { - matches := [][][]byte{} - result := []string{} - s := string("") - matches = pathExtractor(input) - for _,match := range matches { - s = string(match[1]) - if isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || containsInvalidString(s) || len(s)<=2 { - continue - } - if isGitPath(s) { - s = replaceGitPath(s) - } - result = append(result,s) - } - return result + matches := [][][]byte{} + result := []string{} + s := string("") + matches = pathExtractor(input) + for _, match := range matches { + s = string(match[1]) + if isDate(s) || isVersion(s) || isGitRange(s) || isGitInstruction(s) || containsInvalidString(s) || len(s) <= 2 { + continue + } + if isGitPath(s) { + s = replaceGitPath(s) + } + result = append(result, s) + } + return result } diff --git a/pe.go b/pe.go index a95a385..5147f27 100644 --- a/pe.go +++ b/pe.go @@ -1,18 +1,19 @@ package main -import "os" -import "bufio" -import "fmt" +import ( + "bufio" + "fmt" + "os" +) func main() { - stdin := os.Stdin - if scanner := bufio.NewScanner(stdin); scanner != nil { - for scanner.Scan() { - matches := getAllMatches(scanner.Text()) - for _,match := range matches { - fmt.Println(match) - } - } - } + stdin := os.Stdin + if scanner := bufio.NewScanner(stdin); scanner != nil { + for scanner.Scan() { + matches := getAllMatches(scanner.Text()) + for _, match := range matches { + fmt.Println(match) + } + } + } } - diff --git a/pe_test.go b/pe_test.go index 378e79a..2ef95b2 100644 --- a/pe_test.go +++ b/pe_test.go @@ -3,63 +3,63 @@ package main import "testing" func TestGitIgnore(t *testing.T) { - output:=getAllMatches("?? alt/generateStore.php") - if output[0] != "alt/generateStore.php" { - t.Errorf("Doesnt match files", output[0]) - } + output := getAllMatches("?? alt/generateStore.php") + if output[0] != "alt/generateStore.php" { + t.Errorf("Doesnt match files", output[0]) + } - output=getAllMatches("hello .gitignore") - if output[0] != ".gitignore" { - t.Errorf("Doesnt match hidden files", output[0]) - } + output = getAllMatches("hello .gitignore") + if output[0] != ".gitignore" { + t.Errorf("Doesnt match hidden files", output[0]) + } - output=getAllMatches(" mail@mail.com ") - if len(output) != 0 { - t.Errorf("Matches email adresses", output[0]) - } + output = getAllMatches(" mail@mail.com ") + if len(output) != 0 { + t.Errorf("Matches email adresses", output[0]) + } - output=getAllMatches("v1.2") - if len(output) != 0 { - t.Errorf("Matches version number", output[0]) - } + output = getAllMatches("v1.2") + if len(output) != 0 { + t.Errorf("Matches version number", output[0]) + } - output=getAllMatches("obj.slice()") - if len(output) != 0 { - t.Errorf("Matches function call", output[0]) - } + output = getAllMatches("obj.slice()") + if len(output) != 0 { + t.Errorf("Matches function call", output[0]) + } - output=getAllMatches("~/www") - if len(output) == 0 || output[0] != "~/www" { - t.Errorf("Doesnt match home", output[0]) - } + output = getAllMatches("~/www") + if len(output) == 0 || output[0] != "~/www" { + t.Errorf("Doesnt match home", output[0]) + } - output=getAllMatches("origin/master") - if len(output) != 0 { - t.Errorf("Matches remote name", output[0]) - } + output = getAllMatches("origin/master") + if len(output) != 0 { + t.Errorf("Matches remote name", output[0]) + } - output=getAllMatches("john doe (dead on 28/04/2014)") - if len(output) != 0 { - t.Errorf("Matches date", output[0]) - } + output = getAllMatches("john doe (dead on 28/04/2014)") + if len(output) != 0 { + t.Errorf("Matches date", output[0]) + } - output=getAllMatches("john doe ,dead on 28/04/2014") - if len(output) != 0 { - t.Errorf("Matches date", output[0]) - } + output = getAllMatches("john doe ,dead on 28/04/2014") + if len(output) != 0 { + t.Errorf("Matches date", output[0]) + } - output=getAllMatches(".gitignore , ~/www") - if len(output) != 2 { - t.Errorf("Doesnt match multi", output[0]) - } + output = getAllMatches(".gitignore , ~/www") + if len(output) != 2 { + t.Errorf("Doesnt match multi", output[0]) + } - output=getAllMatches("var/") - if len(output) != 1 { - t.Errorf("Doesnt match dir", output[0]) - } + output = getAllMatches("var/") + if len(output) != 1 { + t.Errorf("Doesnt match dir", output[0]) + } - output=getAllMatches("//") - if len(output) != 0 { - t.Errorf("Comment matches", output[0]) - } + output = getAllMatches("//") + if len(output) != 0 { + t.Errorf("Comment matches", output[0]) + } } diff --git a/validators.go b/validators.go index 60811fc..74b7746 100644 --- a/validators.go +++ b/validators.go @@ -1,46 +1,48 @@ package main -import "strings" -import "regexp" - -func isGitRange (input string) bool { - r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}") - return r.Match([]byte(input)) +import ( + "regexp" + "strings" +) + +func isGitRange(input string) bool { + r := regexp.MustCompile("[0-9a-f]{3,}\\.\\.[0-9a-f]{3,}") + return r.Match([]byte(input)) } -func isGitPath (input string) bool { - r := regexp.MustCompile("^[ab]/") - return r.Match([]byte(input)) +func isGitPath(input string) bool { + r := regexp.MustCompile("^[ab]/") + return r.Match([]byte(input)) } -func isDate (input string) bool { - r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+") - return r.Match([]byte(input)) +func isDate(input string) bool { + r := regexp.MustCompile("^[0-9]+/[0-9]+/[0-9]+") + return r.Match([]byte(input)) } -func isGitInstruction (input string) bool { - r := regexp.MustCompile("\\.{3,}") - return r.Match([]byte(input)) +func isGitInstruction(input string) bool { + r := regexp.MustCompile("\\.{3,}") + return r.Match([]byte(input)) } -func replaceGitPath (input string) string { - r := regexp.MustCompile("^[ab]/(.*)") - temp := [][]byte{} - temp = r.FindSubmatch([]byte(input)) - return string(temp[1]) +func replaceGitPath(input string) string { + r := regexp.MustCompile("^[ab]/(.*)") + temp := [][]byte{} + temp = r.FindSubmatch([]byte(input)) + return string(temp[1]) } -func isVersion (input string) bool { - r := regexp.MustCompile("[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?") - return r.Match([]byte(input)) +func isVersion(input string) bool { + r := regexp.MustCompile("[0-9x]\\.[0-9x]{1,2}(\\.[0-9x]{1,3})?") + return r.Match([]byte(input)) } -func containsInvalidString (input string) bool { - invalidStrings := []string{"(",")","@","origin/","{","}","<",">","$","*"} - for _,s := range invalidStrings { - if strings.Contains(input,s) { - return true - } - } - return false +func containsInvalidString(input string) bool { + invalidStrings := []string{"(", ")", "@", "origin/", "{", "}", "<", ">", "$", "*"} + for _, s := range invalidStrings { + if strings.Contains(input, s) { + return true + } + } + return false } -- 2.44.0