repochecker/grammalecte: Check for forbidden strings (raw flags) in resolution.md

This commit is contained in:
nemunaire 2022-11-24 13:11:21 +01:00
commit 3421286c9b
4 changed files with 38 additions and 3 deletions

View file

@ -64,6 +64,17 @@ type ExerciceFlag struct {
NumberStep interface{} `toml:"step,omitempty"`
}
func (f ExerciceFlag) RawString() []string {
switch f.Raw.(type) {
case string:
return []string{f.Raw.(string)}
case []string:
return f.Raw.([]string)
default:
return nil
}
}
// ExerciceFlagChoice holds informations about a choice (for MCQ and UCQ).
type ExerciceFlagChoice struct {
ExerciceFlag
@ -83,6 +94,21 @@ type ExerciceParams struct {
FlagsUCQ []ExerciceFlag `toml:"flag_ucq"`
}
func (p ExerciceParams) GetRawFlags() (ret []string) {
for _, f := range append(p.Flags, p.FlagsUCQ...) {
raw := f.RawString()
if len(raw) > 0 {
ret = append(ret, raw...)
}
}
for _, f := range p.FlagsMCQ {
for _, c := range f.Choice {
ret = append(ret, c.Label)
}
}
return
}
// parseExerciceParams reads challenge definitions from defines.txt and extract usefull data to set up the challenge.
func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, md toml.MetaData, err error) {
var defs string

View file

@ -289,7 +289,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
} else {
// Call checks hooks
for _, h := range hooks.mdTextHooks {
for _, err := range h(e.Resolution, exceptions.GetFileExceptions("resolution.md")) {
for _, err := range h(e.Resolution, exceptions.GetFileExceptions("resolution.md"), p.GetRawFlags()...) {
errs = append(errs, NewExerciceError(e, fmt.Errorf("resolution.md: %w", err)))
}
}

View file

@ -16,7 +16,7 @@ type CheckFlagLabelHook func(*fic.FlagLabel, *CheckExceptions) []error
type CheckFlagMCQHook func(*fic.MCQ, []*fic.MCQ_entry, *CheckExceptions) []error
type CheckFileHook func(*fic.EFile, *CheckExceptions) []error
type CheckHintHook func(*fic.EHint, *CheckExceptions) []error
type CheckMDTextHook func(string, *CheckExceptions) []error
type CheckMDTextHook func(string, *CheckExceptions, ...string) []error
type CheckExerciceHook func(*fic.Exercice, *CheckExceptions) []error
type CustomCheckHook func(interface{}, *CheckExceptions) []error