2022-10-29 11:36:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-10-31 22:33:42 +00:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2022-10-31 14:52:11 +00:00
|
|
|
"log"
|
2022-10-31 22:33:42 +00:00
|
|
|
"unicode"
|
2022-10-31 14:52:11 +00:00
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
"go.uber.org/multierr"
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
"srs.epita.fr/fic-server/admin/sync"
|
2022-10-29 11:36:37 +00:00
|
|
|
"srs.epita.fr/fic-server/libfic"
|
2022-10-31 16:00:09 +00:00
|
|
|
lib "srs.epita.fr/fic-server/repochecker/grammalecte/lib"
|
2022-10-29 11:36:37 +00:00
|
|
|
)
|
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
func GrammalecteCheckKeyFlag(flag *fic.FlagKey, raw string, exercice *fic.Exercice, exceptions *sync.CheckExceptions) (errs error) {
|
2023-01-17 17:26:04 +00:00
|
|
|
if !isRecognizedLanguage(exercice.Language) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-29 11:36:37 +00:00
|
|
|
label, _, _, _ := flag.AnalyzeFlagLabel()
|
2023-11-22 11:16:53 +00:00
|
|
|
for _, err := range multierr.Errors(grammalecte("label ", label, -1, exceptions, &CommonOpts)) {
|
2022-10-31 16:00:09 +00:00
|
|
|
if e, ok := err.(lib.GrammarError); ok && e.RuleId == "poncfin_règle1" {
|
2022-10-31 11:33:53 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, err)
|
2022-10-31 11:33:53 +00:00
|
|
|
}
|
2022-10-29 11:36:37 +00:00
|
|
|
|
2023-11-25 09:32:48 +00:00
|
|
|
// Flag help are checked through GrammalecteCheckMDText, no need to check them
|
2022-10-29 11:36:37 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
func GrammalecteCheckFlagChoice(choice *fic.FlagChoice, exercice *fic.Exercice, exceptions *sync.CheckExceptions) (errs error) {
|
2023-01-18 14:48:59 +00:00
|
|
|
if isRecognizedLanguage(exercice.Language) {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, grammalecte("label ", choice.Label, -1, exceptions, &CommonOpts))
|
2023-01-17 17:26:04 +00:00
|
|
|
}
|
|
|
|
|
2023-11-24 11:16:17 +00:00
|
|
|
if len(multierr.Errors(errs)) == 0 && unicode.IsLetter(bytes.Runes([]byte(choice.Label))[0]) && !unicode.IsUpper(bytes.Runes([]byte(choice.Label))[0]) && !exceptions.HasException(":label_majuscule") {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, fmt.Errorf("%q nécessite une majuscule (:label_majuscule)", choice.Label))
|
2022-10-31 22:33:42 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 11:36:37 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
func GrammalecteCheckHint(hint *fic.EHint, exercice *fic.Exercice, exceptions *sync.CheckExceptions) (errs error) {
|
2022-10-29 11:36:37 +00:00
|
|
|
if len(hint.Title) > 0 {
|
2023-01-18 14:48:59 +00:00
|
|
|
if isRecognizedLanguage(exercice.Language) {
|
2023-11-22 11:16:53 +00:00
|
|
|
errs = multierr.Append(errs, grammalecte("title ", hint.Title, -1, exceptions, &CommonOpts))
|
2023-01-18 14:48:59 +00:00
|
|
|
}
|
2023-11-22 11:16:53 +00:00
|
|
|
if len(multierr.Errors(errs)) == 0 && !unicode.IsUpper(bytes.Runes([]byte(hint.Title))[0]) && !exceptions.HasException(":title_majuscule") {
|
|
|
|
errs = multierr.Append(errs, fmt.Errorf("%q nécessite une majuscule (:title_majuscule)", hint.Title))
|
2022-10-31 22:33:42 +00:00
|
|
|
}
|
2022-10-29 11:36:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-31 15:29:07 +00:00
|
|
|
// Hint content are checked through GrammalecteCheckMDText, no need to check them
|
|
|
|
|
2022-10-29 11:36:37 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-22 11:16:53 +00:00
|
|
|
func GrammalecteCheckGrammar(data interface{}, exceptions *sync.CheckExceptions) error {
|
2023-01-17 17:26:04 +00:00
|
|
|
if s, ok := data.(struct {
|
|
|
|
Str string
|
|
|
|
Language string
|
|
|
|
}); ok {
|
2023-01-18 14:48:59 +00:00
|
|
|
if !isRecognizedLanguage(s.Language) {
|
2023-01-17 17:26:04 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return grammalecte("", s.Str, 0, exceptions, &CommonOpts)
|
2022-10-31 14:52:11 +00:00
|
|
|
} else {
|
|
|
|
log.Printf("Unknown data given to GrammalecteCheckGrammar: %T", data)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|