sync: Replace []error by go.uber.org/multierr
This commit is contained in:
parent
9f49a689fd
commit
b6966d47ce
25 changed files with 380 additions and 348 deletions
|
|
@ -15,9 +15,10 @@ import (
|
|||
"github.com/yuin/goldmark/renderer"
|
||||
"github.com/yuin/goldmark/text"
|
||||
"github.com/yuin/goldmark/util"
|
||||
"go.uber.org/multierr"
|
||||
)
|
||||
|
||||
func GrammalecteCheckMDText(str string, lang string, exceptions *sync.CheckExceptions, forbiddenStrings ...string) (errs []error) {
|
||||
func GrammalecteCheckMDText(str string, lang string, exceptions *sync.CheckExceptions, forbiddenStrings ...string) (errs error) {
|
||||
if !isRecognizedLanguage(lang) {
|
||||
return
|
||||
}
|
||||
|
|
@ -34,7 +35,7 @@ func GrammalecteCheckMDText(str string, lang string, exceptions *sync.CheckExcep
|
|||
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))
|
||||
errs = multierr.Append(errs, fmt.Errorf("Forbidden raw string %q included in file content, don't write it (:not-forbidden-string:%s)", s, s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -62,13 +63,13 @@ func GrammalecteCheckMDText(str string, lang string, exceptions *sync.CheckExcep
|
|||
|
||||
var buf bytes.Buffer
|
||||
if err := markdown.Convert([]byte(str), &buf); err != nil {
|
||||
errs = append(errs, err)
|
||||
errs = multierr.Append(errs, err)
|
||||
}
|
||||
|
||||
errs = append(errs, checker.errs...)
|
||||
errs = append(errs, voidRenderer.Errors()...)
|
||||
errs = multierr.Append(errs, checker.errs)
|
||||
errs = multierr.Append(errs, voidRenderer.Errors())
|
||||
|
||||
for _, err := range grammalecte("", buf.String(), 0, exceptions, &CommonOpts) {
|
||||
for _, err := range multierr.Errors(grammalecte("", buf.String(), 0, exceptions, &CommonOpts)) {
|
||||
if gerror, ok := err.(lib.GrammarError); ok {
|
||||
if (gerror.RuleId == "redondances_paragraphe" || gerror.RuleId == "redondances_phrase") && gerror.GetPassage() == "SubstitutDeCode" {
|
||||
continue
|
||||
|
|
@ -79,7 +80,7 @@ func GrammalecteCheckMDText(str string, lang string, exceptions *sync.CheckExcep
|
|||
}
|
||||
}
|
||||
|
||||
errs = append(errs, err)
|
||||
errs = multierr.Append(errs, err)
|
||||
}
|
||||
|
||||
return
|
||||
|
|
@ -87,7 +88,7 @@ func GrammalecteCheckMDText(str string, lang string, exceptions *sync.CheckExcep
|
|||
|
||||
type grammarChecker struct {
|
||||
exceptions *sync.CheckExceptions
|
||||
errs []error
|
||||
errs error
|
||||
}
|
||||
|
||||
func (t *grammarChecker) Transform(doc *ast.Document, reader text.Reader, pc parser.Context) {
|
||||
|
|
@ -99,11 +100,11 @@ func (t *grammarChecker) Transform(doc *ast.Document, reader text.Reader, pc par
|
|||
switch child := node.(type) {
|
||||
case *ast.Image:
|
||||
if len(child.Title) > 0 {
|
||||
t.errs = append(t.errs, grammalecte("", string(child.Title), 0, t.exceptions, &CommonOpts)...)
|
||||
t.errs = multierr.Append(t.errs, grammalecte("", string(child.Title), 0, t.exceptions, &CommonOpts))
|
||||
}
|
||||
case *ast.Link:
|
||||
if len(child.Title) > 0 {
|
||||
t.errs = append(t.errs, grammalecte("", string(child.Title), 0, t.exceptions, &CommonOpts)...)
|
||||
t.errs = multierr.Append(t.errs, grammalecte("", string(child.Title), 0, t.exceptions, &CommonOpts))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue