An error message starts with a capital letter or ends with punctuation or a newline
What it finds
errors.New("Connection failed."): error messages are usually embedded in others, as in fmt.Errorf("sync: %w", err), which reads well only when each part starts in lower case and has no punctuation or line break at its end. Go's own packages write them that way, and so does most Go code.
The message must be a constant string of the file given to errors.New or as the format of fmt.Errorf. A first word that is capitalized because it is a name, an acronym or an identifier, recognized by a second capital letter, a digit or an underscore in it, is left alone, and so is a message that ends in ....
From the rule's source, error_message_style.rs.
package p import ( "errors" "fmt") var ( errA = errors.New("Something went wrong")tx0 reports: the error message starts with a capital letter errB = errors.New("something went wrong.")tx0 reports: the error message ends with punctuation errC = fmt.Errorf("read %s failed\n", "x")tx0 reports: the error message ends with a newline errD = errors.New("HTTP request failed") errE = errors.New("ReadFile: no such file") errF = errors.New("waiting...") errG = errors.New("something went wrong") errH = errors.New("I")) Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:error-message-style" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:error-message-style] reason="..."tx0 explain tx0/go:error-message-style shows the same in the terminal. Found a false positive? Report it.