Commit eba0ffc1 authored by Hugo Moreau's avatar Hugo Moreau

formating: refacto

For a better readibility, better format has been used for formating.

 * main.go,
   tools/formating.go : Here.
parent ed3fa8fa
Pipeline #26329 failed with stage
in 3 minutes and 25 seconds
...@@ -551,9 +551,8 @@ func main() { ...@@ -551,9 +551,8 @@ func main() {
os.Exit(1) os.Exit(1)
} }
src = treatGlobal(src)
if len(toIgnore) != 0 { if len(toIgnore) != 0 {
src = treatGlobal(src)
a, bb := tools.RewriteBlackbox(string(src), toIgnore, *output) a, bb := tools.RewriteBlackbox(string(src), toIgnore, *output)
if err = os.MkdirAll(*output+"/blackbox", 0777); err != nil { if err = os.MkdirAll(*output+"/blackbox", 0777); err != nil {
...@@ -567,13 +566,13 @@ func main() { ...@@ -567,13 +566,13 @@ func main() {
os.Exit(1) os.Exit(1)
} }
src = []byte(a) src = []byte(a)
err = ioutil.WriteFile(path.Join(*output, basePackagePath), []byte(src), 0666)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(2)
} }
err = ioutil.WriteFile(path.Join(*output, basePackagePath), []byte(src), 0666)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
os.Exit(2)
// Check if all constraints are respected // Check if all constraints are respected
info := &types.Info{ info := &types.Info{
......
...@@ -23,7 +23,6 @@ import ( ...@@ -23,7 +23,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv"
"strings" "strings"
) )
...@@ -38,40 +37,39 @@ func FormatArray(src, pattern string) { ...@@ -38,40 +37,39 @@ func FormatArray(src, pattern string) {
scanner := bufio.NewScanner(strings.NewReader(string(input))) scanner := bufio.NewScanner(strings.NewReader(string(input)))
for scanner.Scan() { for scanner.Scan() {
if strings.Contains(scanner.Text(), pattern) { if strings.Contains(scanner.Text(), pattern) {
tmp, active, count, tab := "", false, 0, 0 array, counter := []string{""}, 0
for i := 0; i < len(scanner.Text()); i++ { for i := 0; i < len(scanner.Text()); i++ {
tab++ if string(scanner.Text()[i]) != "}" {
array[counter] += string(scanner.Text()[i])
}
if string(scanner.Text()[i]) == "{" { if string(scanner.Text()[i]) == "{" {
tmp += string(scanner.Text()[i]) counter += 1
output += tmp + "\n" array = append(array, "")
tmp, active, tab = "\t", true, 0
} else if string(scanner.Text()[i]) == "," { } else if string(scanner.Text()[i]) == "," {
tmp += string(scanner.Text()[i]) counter += 1
output += tmp array = append(array, "")
if tab < 33 {
output += "\t"
}
if tab < 27 {
output += "\t"
}
output += "\t//" + strconv.Itoa(count) + "\n"
count++
tmp, tab = "\t", 0
} else if string(scanner.Text()[i]) == "}" { } else if string(scanner.Text()[i]) == "}" {
output += tmp + "," array[counter] += ","
if tab < 33 { counter += 1
output += "\t" array = append(array, "")
} array[counter] += string(scanner.Text()[i])
if tab < 27 { }
output += "\t" }
} max, counter := 0, 0
output += "\t//" + strconv.Itoa(count) + "\n" for _, val := range array {
tmp = string(scanner.Text()[i]) if len(val) > max {
output += tmp + "\n" max = len(val)
} else if scanner.Text()[i] != 32 || !active {
tmp += string(scanner.Text()[i])
} }
} }
max += 1
output += fmt.Sprintf("%s\n", array[0])
output += fmt.Sprintf("\t%*s// %d\n", -max, array[1], counter)
counter += 1
for i := 2; i < len(array)-1; i++ {
output += fmt.Sprintf("\t%*s// %d\n", -max, array[i][1:], counter)
counter += 1
}
output += fmt.Sprintf("%s\n", array[len(array)-1])
} else { } else {
output += scanner.Text() + "\n" output += scanner.Text() + "\n"
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment