mirror of https://github.com/dmarkham/enumer.git
stringer: Add logic to fail if transformer empties value
If the output of the transformer is '' means that something went wrong (if it had a value before) and so it needs to fail to not conntinue with silence errors
This commit is contained in:
parent
20d9792920
commit
cb6196db58
13
stringer.go
13
stringer.go
|
@ -377,8 +377,17 @@ func (g *Generator) transformValueNames(values []Value, transformMethod string)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range values {
|
for i, v := range values {
|
||||||
values[i].name = fn(values[i].name)
|
after := fn(v.name)
|
||||||
|
// If the original one was "" or the one before the transformation
|
||||||
|
// was "" (most commonly if linecomment defines it as empty) we
|
||||||
|
// do not care if it's empty.
|
||||||
|
// But if any of them was not empty before then it means that
|
||||||
|
// the transformed emptied the value
|
||||||
|
if v.originalName != "" && v.name != "" && after == "" {
|
||||||
|
log.Fatalf("transformation of %q (%s) got an empty result", v.name, v.originalName)
|
||||||
|
}
|
||||||
|
values[i].name = after
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue