From da72629387eb8c977ba1bcbbbcd07eab9241e7a1 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 20 May 2020 14:48:37 -0700 Subject: [PATCH] move qmlfmt to serpeate standalone openprivacy repo --- cmd/qmlfmt/main.go | 91 ---------------------------------------------- quality.sh | 2 +- 2 files changed, 1 insertion(+), 92 deletions(-) delete mode 100644 cmd/qmlfmt/main.go diff --git a/cmd/qmlfmt/main.go b/cmd/qmlfmt/main.go deleted file mode 100644 index ac109ad1..00000000 --- a/cmd/qmlfmt/main.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "bufio" - "log" - "os" - "strings" -) - -const ( - indent = " " -) - -func main() { - if len(os.Args) < 2 { - log.Fatal("Required argument(s): filename(s)") - } - - for _, filename := range os.Args[1:] { - processFile(filename) - } - -} - -func processFile(filename string) { - file, err := os.Open(filename) - if err != nil { - log.Fatalf("Could not read file %v: %v\n", filename, err) - } - - scanner := bufio.NewScanner(file) - var lines []string - - for scanner.Scan() { - lines = append(lines, scanner.Text()) - } - - file.Close() - - file, err = os.Create(filename) - defer file.Close() - if err != nil { - log.Fatalf("Could not write to file %v: %v\n", filename, err) - } - - indentCount := 0 - inMultiLineComment := false - - for ln, line := range lines { - - singleCommentPos := strings.Index(line, "//") - multiLineCommentStartPos := strings.Index(line, "/*") - multiLineCommentEndPos := strings.Index(line, "*/") - - openPos := strings.Index(line, "{") - closePos := strings.Index(line, "}") - - if !inMultiLineComment && closePos > -1 && (openPos == -1 || openPos > closePos) && (singleCommentPos == -1 || closePos < singleCommentPos) && - (multiLineCommentStartPos == -1 || closePos < multiLineCommentStartPos) && - (multiLineCommentEndPos == -1 || closePos > multiLineCommentEndPos) { - indentCount-- - } - - trimedLine := strings.Trim(line, " \t") - if trimedLine == "" { - file.Write([]byte("\n")) - } else { - if indentCount < 0 { - log.Fatalf("indent Count negative in %v at line %v\n", filename, ln) - } - - file.Write([]byte(strings.Repeat(indent, indentCount) + trimedLine + "\n")) - } - - if !inMultiLineComment && openPos > -1 && (closePos == -1 || openPos > closePos) && (singleCommentPos == -1 || openPos < singleCommentPos) && - (multiLineCommentStartPos == -1 || openPos < multiLineCommentStartPos) && - (multiLineCommentEndPos == -1 || openPos > multiLineCommentEndPos) { - indentCount++ - } - - if multiLineCommentStartPos > -1 { - inMultiLineComment = true - } - - if multiLineCommentEndPos > -1 { - inMultiLineComment = false - } - - } - -} diff --git a/quality.sh b/quality.sh index f6fad191..fc6234c9 100755 --- a/quality.sh +++ b/quality.sh @@ -1,6 +1,6 @@ #!/bin/sh -# go get cwtch.im/ui/cmd/qmlfmt +# go get git.openprivacy.ca/openprivacy/qmlfmt cd qml find -iname "*.qml" | xargs qmlfmt