2022-10-29 11:36:37 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-10-31 14:52:11 +00:00
|
|
|
"log"
|
2022-10-31 15:29:07 +00:00
|
|
|
"strings"
|
2022-10-31 14:52:11 +00:00
|
|
|
|
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
|
|
|
)
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
func GrammalecteCheckKeyFlag(flag *fic.FlagKey, raw string, exceptions *sync.CheckExceptions) (errs []error) {
|
2022-10-29 11:36:37 +00:00
|
|
|
label, _, _, _ := flag.AnalyzeFlagLabel()
|
2022-10-31 11:33:53 +00:00
|
|
|
for _, err := range grammalecte("label ", label, 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
|
|
|
|
}
|
|
|
|
|
|
|
|
errs = append(errs, err)
|
|
|
|
}
|
2022-10-29 11:36:37 +00:00
|
|
|
|
|
|
|
if len(flag.Help) > 0 {
|
2022-10-29 15:03:57 +00:00
|
|
|
errs = append(errs, grammalecte("help ", flag.Help, exceptions, &CommonOpts)...)
|
2022-10-29 11:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
func GrammalecteCheckFlagChoice(choice *fic.FlagChoice, exceptions *sync.CheckExceptions) (errs []error) {
|
|
|
|
errs = append(errs, grammalecte("label ", choice.Label, exceptions, &CommonOpts)...)
|
2022-10-29 11:36:37 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
func GrammalecteCheckHint(hint *fic.EHint, exceptions *sync.CheckExceptions) (errs []error) {
|
2022-10-29 11:36:37 +00:00
|
|
|
if len(hint.Title) > 0 {
|
2022-10-29 15:03:57 +00:00
|
|
|
errs = append(errs, grammalecte("title ", hint.Title, exceptions, &CommonOpts)...)
|
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
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
func GrammalecteCheckMDText(str string, exceptions *sync.CheckExceptions) (errs []error) {
|
2022-10-31 15:29:07 +00:00
|
|
|
if exceptions != nil {
|
|
|
|
for k := range *exceptions {
|
|
|
|
tmp := strings.SplitN(k, ":", 3)
|
|
|
|
if len(tmp) == 3 && tmp[1] == "quote" {
|
|
|
|
str = strings.Replace(str, tmp[3], "une citation a été remplacée ici", -1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-29 15:03:57 +00:00
|
|
|
errs = append(errs, grammalecte("", str, exceptions, &CommonOpts)...)
|
2022-10-29 11:36:37 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2022-10-31 14:52:11 +00:00
|
|
|
|
2022-10-31 16:00:09 +00:00
|
|
|
func GrammalecteCheckGrammar(data interface{}, exceptions *sync.CheckExceptions) []error {
|
2022-10-31 14:52:11 +00:00
|
|
|
if s, ok := data.(string); ok {
|
|
|
|
return grammalecte("", s, exceptions, &CommonOpts)
|
|
|
|
} else {
|
|
|
|
log.Printf("Unknown data given to GrammalecteCheckGrammar: %T", data)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|