repochecker/grammalecte: Overload grammar paragraph in some situations

This commit is contained in:
nemunaire 2022-11-06 22:21:55 +01:00
parent cd07bec05b
commit 7c2e97740f
2 changed files with 9 additions and 9 deletions

View File

@ -14,7 +14,7 @@ import (
func GrammalecteCheckKeyFlag(flag *fic.FlagKey, raw string, exceptions *sync.CheckExceptions) (errs []error) {
label, _, _, _ := flag.AnalyzeFlagLabel()
for _, err := range grammalecte("label ", label, exceptions, &CommonOpts) {
for _, err := range grammalecte("label ", label, -1, exceptions, &CommonOpts) {
if e, ok := err.(lib.GrammarError); ok && e.RuleId == "poncfin_règle1" {
continue
}
@ -23,14 +23,14 @@ func GrammalecteCheckKeyFlag(flag *fic.FlagKey, raw string, exceptions *sync.Che
}
if len(flag.Help) > 0 {
errs = append(errs, grammalecte("help ", flag.Help, exceptions, &CommonOpts)...)
errs = append(errs, grammalecte("help ", flag.Help, -1, exceptions, &CommonOpts)...)
}
return
}
func GrammalecteCheckFlagChoice(choice *fic.FlagChoice, exceptions *sync.CheckExceptions) (errs []error) {
errs = append(errs, grammalecte("label ", choice.Label, exceptions, &CommonOpts)...)
errs = append(errs, grammalecte("label ", choice.Label, -1, exceptions, &CommonOpts)...)
if len(errs) == 0 && !unicode.IsUpper(bytes.Runes([]byte(choice.Label))[0]) && !exceptions.HasException(":label_majuscule") {
errs = append(errs, fmt.Errorf("%q nécessite une majuscule (:label_majuscule)", choice.Label))
@ -41,7 +41,7 @@ func GrammalecteCheckFlagChoice(choice *fic.FlagChoice, exceptions *sync.CheckEx
func GrammalecteCheckHint(hint *fic.EHint, exceptions *sync.CheckExceptions) (errs []error) {
if len(hint.Title) > 0 {
errs = append(errs, grammalecte("title ", hint.Title, exceptions, &CommonOpts)...)
errs = append(errs, grammalecte("title ", hint.Title, -1, exceptions, &CommonOpts)...)
if len(errs) == 0 && !unicode.IsUpper(bytes.Runes([]byte(hint.Title))[0]) && !exceptions.HasException(":title_majuscule") {
errs = append(errs, fmt.Errorf("%q nécessite une majuscule (:title_majuscule)", hint.Title))
}
@ -62,14 +62,14 @@ func GrammalecteCheckMDText(str string, exceptions *sync.CheckExceptions) (errs
}
}
errs = append(errs, grammalecte("", str, exceptions, &CommonOpts)...)
errs = append(errs, grammalecte("", str, 0, exceptions, &CommonOpts)...)
return
}
func GrammalecteCheckGrammar(data interface{}, exceptions *sync.CheckExceptions) []error {
if s, ok := data.(string); ok {
return grammalecte("", s, exceptions, &CommonOpts)
return grammalecte("", s, 0, exceptions, &CommonOpts)
} else {
log.Printf("Unknown data given to GrammalecteCheckGrammar: %T", data)
return nil

View File

@ -119,7 +119,7 @@ var (
mdimg = regexp.MustCompile(`!\[([^\]]+)\]\([^)]+\)`)
)
func grammalecte(name string, text string, exceptions *sync.CheckExceptions, options *GrammalecteOptions) (errs []error) {
func grammalecte(name string, text string, paragraph int, exceptions *sync.CheckExceptions, options *GrammalecteOptions) (errs []error) {
// Remove Markdown elements
text = mdimg.ReplaceAllString(text, "Image : ${1}")
@ -187,11 +187,11 @@ func grammalecte(name string, text string, exceptions *sync.CheckExceptions, opt
continue
}
if gerror.RuleId == "mc_mot_composé" && gerror.End+1 < len(data.Text) && gerror.Start+1 < len(data.Text) && exceptions.HasException(fmt.Sprintf(":spelling:%s", data.Text[gerror.Start+1:gerror.End+1])) {
if gerror.RuleId == "mc_mot_composé" && ((gerror.End+1 < len(data.Text) && gerror.Start+1 < len(data.Text) && exceptions.HasException(fmt.Sprintf(":spelling:%s", data.Text[gerror.Start+1:gerror.End+1]))) || exceptions.HasException(fmt.Sprintf(":spelling:%s", data.Text[gerror.Start:gerror.End]))) {
continue
}
if exceptions.HasException(fmt.Sprintf(":%d:%s", data.Paragraph, gerror.RuleId)) {
if (paragraph == 0 && exceptions.HasException(fmt.Sprintf(":%d:%s", data.Paragraph, gerror.RuleId))) || (paragraph < 0 && exceptions.HasException(fmt.Sprintf(":%s", gerror.RuleId))) || (paragraph > 0 && exceptions.HasException(fmt.Sprintf(":%d:%s", paragraph, gerror.RuleId))) {
continue
}