Use MustCompile for static regexp

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-08-25 16:49:31 +02:00
parent 8a9f367067
commit dd2f218226

View File

@ -154,10 +154,7 @@ func (t Toml) contents() ([]byte, error) {
// format fixes the comments for the config to ensure that they start in column // format fixes the comments for the config to ensure that they start in column
// 1 and are not followed by a space. // 1 and are not followed by a space.
func (t Toml) format(contents []byte) ([]byte, error) { func (t Toml) format(contents []byte) ([]byte, error) {
r, err := regexp.Compile(`(\n*)\s*?#\s*(\S.*)`) r := regexp.MustCompile(`(\n*)\s*?#\s*(\S.*)`)
if err != nil {
return nil, fmt.Errorf("unable to compile regexp: %v", err)
}
replaced := r.ReplaceAll(contents, []byte("$1#$2")) replaced := r.ReplaceAll(contents, []byte("$1#$2"))
return replaced, nil return replaced, nil