repochecker/grammalecte: Check for forbidden strings (raw flags) in resolution.md
This commit is contained in:
parent
80422daffb
commit
3421286c9b
4 changed files with 38 additions and 3 deletions
|
@ -64,6 +64,17 @@ type ExerciceFlag struct {
|
||||||
NumberStep interface{} `toml:"step,omitempty"`
|
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).
|
// ExerciceFlagChoice holds informations about a choice (for MCQ and UCQ).
|
||||||
type ExerciceFlagChoice struct {
|
type ExerciceFlagChoice struct {
|
||||||
ExerciceFlag
|
ExerciceFlag
|
||||||
|
@ -83,6 +94,21 @@ type ExerciceParams struct {
|
||||||
FlagsUCQ []ExerciceFlag `toml:"flag_ucq"`
|
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.
|
// 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) {
|
func parseExerciceParams(i Importer, exPath string) (p ExerciceParams, md toml.MetaData, err error) {
|
||||||
var defs string
|
var defs string
|
||||||
|
|
|
@ -289,7 +289,7 @@ func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*
|
||||||
} else {
|
} else {
|
||||||
// Call checks hooks
|
// Call checks hooks
|
||||||
for _, h := range hooks.mdTextHooks {
|
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)))
|
errs = append(errs, NewExerciceError(e, fmt.Errorf("resolution.md: %w", err)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ type CheckFlagLabelHook func(*fic.FlagLabel, *CheckExceptions) []error
|
||||||
type CheckFlagMCQHook func(*fic.MCQ, []*fic.MCQ_entry, *CheckExceptions) []error
|
type CheckFlagMCQHook func(*fic.MCQ, []*fic.MCQ_entry, *CheckExceptions) []error
|
||||||
type CheckFileHook func(*fic.EFile, *CheckExceptions) []error
|
type CheckFileHook func(*fic.EFile, *CheckExceptions) []error
|
||||||
type CheckHintHook func(*fic.EHint, *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 CheckExerciceHook func(*fic.Exercice, *CheckExceptions) []error
|
||||||
type CustomCheckHook func(interface{}, *CheckExceptions) []error
|
type CustomCheckHook func(interface{}, *CheckExceptions) []error
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/admin/sync"
|
"srs.epita.fr/fic-server/admin/sync"
|
||||||
|
@ -15,7 +16,7 @@ import (
|
||||||
"github.com/yuin/goldmark/util"
|
"github.com/yuin/goldmark/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GrammalecteCheckMDText(str string, exceptions *sync.CheckExceptions) (errs []error) {
|
func GrammalecteCheckMDText(str string, exceptions *sync.CheckExceptions, forbiddenStrings ...string) (errs []error) {
|
||||||
if exceptions != nil {
|
if exceptions != nil {
|
||||||
for k := range *exceptions {
|
for k := range *exceptions {
|
||||||
tmp := strings.SplitN(k, ":", 3)
|
tmp := strings.SplitN(k, ":", 3)
|
||||||
|
@ -25,6 +26,14 @@ func GrammalecteCheckMDText(str string, exceptions *sync.CheckExceptions) (errs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, s := range forbiddenStrings {
|
||||||
|
if strings.Contains(str, s) {
|
||||||
|
if !exceptions.HasException(":not-forbidden-string:" + s) {
|
||||||
|
errs = append(errs, fmt.Errorf("Forbidden raw string %q included in file content, don't write it (:not-forbidden-string:%s)", s, s))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
checker := &grammarChecker{
|
checker := &grammarChecker{
|
||||||
exceptions: exceptions,
|
exceptions: exceptions,
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue