diff --git a/files/.travis.sh b/files/.travis.sh index 584efbe..2fb78fb 100644 --- a/files/.travis.sh +++ b/files/.travis.sh @@ -10,15 +10,17 @@ git diff HEAD^ --name-status | grep "^D" -v | awk '{print $2}' > changed_files while read FILE; do echo -n "Проверка файла $FILE на опечатки... "; - OUTPUT_RU=$(cat "$FILE" | hunspell -d ru_RU | $DIR/spell-checker); + OUTPUT_RU=$(cat "$FILE" | hunspell -d russian-aot,en_US,de_DE,$DIR/dictionary | $DIR/spell-checker); RU_EXIT_CODE=$? - OUTPUT_EN=$(cat "$FILE" | hunspell -d en_US | $DIR/spell-checker); + OUTPUT_EN=$(cat "$FILE" | hunspell -d en_US,russian-aot,de_DE,$DIR/dictionary | $DIR/spell-checker); EN_EXIT_CODE=$? + OUTPUT_DE=$(cat "$FILE" | hunspell -d de_DE,en_US,russian-aot,$DIR/dictionary | $DIR/spell-checker); + DE_EXIT_CODE=$? - if [ $RU_EXIT_CODE -ne 0 ] || [ $EN_EXIT_CODE -ne 0 ]; then + if [ $RU_EXIT_CODE -ne 0 ] || [ $EN_EXIT_CODE -ne 0 ] || [ $DE_EXIT_CODE -ne 0 ]; then EXIT_CODE=1; echo "ошибка"; - echo "$OUTPUT_RU\n$OUTPUT_EN" | sort -n -k2; + echo "$OUTPUT_RU\n$OUTPUT_EN\n$OUTPUT_DE" | sort -n -k2 | uniq; else echo "пройдена"; fi diff --git a/files/dictionary.dic b/files/dictionary.dic new file mode 100644 index 0000000..e69bde9 --- /dev/null +++ b/files/dictionary.dic @@ -0,0 +1,2 @@ +1 +StVzo \ No newline at end of file diff --git a/files/spell-checker.go b/files/spell-checker.go index 8a2642f..7be4f5c 100644 --- a/files/spell-checker.go +++ b/files/spell-checker.go @@ -4,6 +4,8 @@ import ( "fmt" "os" "bufio" + "regexp" + "strings" ) @@ -23,11 +25,18 @@ func main() { _, ok := types["&"] if ok { + var dropCol = regexp.MustCompile(`^([^ ]+) \d+ \d+:(.*)$`) + var minimumWord = regexp.MustCompile(`^[^ ]{3}`) + exitCode := 0 + for _, result := range types["&"].results { - fmt.Println("Строка " + fmt.Sprintf("%v", result.line) + ":" + result.word) + if minimumWord.MatchString(result.word) { + exitCode = 1 + fmt.Println("Строка " + fmt.Sprintf("%v", result.line) + ": " + dropCol.ReplaceAllString(result.word, "$1 >$2")) + } } - os.Exit(1) + os.Exit(exitCode) } } @@ -44,6 +53,7 @@ func parseHunspellOutput(scanner *bufio.Scanner) map[string]*TypeResult { line++; } else { resultType := text[0:1] + typeResult, ok := types[resultType] if !ok { @@ -51,7 +61,7 @@ func parseHunspellOutput(scanner *bufio.Scanner) map[string]*TypeResult { types[resultType] = typeResult } - typeResult.results = append(typeResult.results, Result{line: line, word: text[1:]}) + typeResult.results = append(typeResult.results, Result{line: line, word: strings.Trim(text[1:], " ")}) } }