Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add linter for error/trace/log messages #102

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

nirupama7
Copy link

@nirupama7 nirupama7 commented Jan 13, 2023

What this PR does / why we need it

This PR adds linter for error/trace/log messages. This linter checks following-

  1. errors.New, trace.StartCall, trace.StartSpan, log.Warn, log.Error, log.Info, errors.Wrap, errors.Wrapf static messages for capitalization
  2. check ending of message string in above cases for valid ending (".", ":","!", "\n") not allowed as end character.

JIRA ID: XX-XX

Notes for your reviewers

TODO: test cases

@nirupama7 nirupama7 marked this pull request as ready for review January 13, 2023 02:27
@nirupama7 nirupama7 requested a review from a team as a code owner January 13, 2023 02:27
Copy link
Contributor

@george-e-shaw-iv george-e-shaw-iv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to wait to review the rest of the actual linter code until that one big comment about test/generated files still being linted against is addressed because I have a feeling it might change the structure of that linter's code a bit. It is definitely on its way and looking good though!!

internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
@george-e-shaw-iv
Copy link
Contributor

Oh also - if I don't say it then @jkinkead will haha, please write a few test (unit) cases to validate your linter is working as intended.

@@ -164,7 +164,7 @@ func (l *Lintroller) EnsureMinimums(desired *Lintroller) error { //nolint:funlen
l.Doculint.MinFunLen = desired.Doculint.MinFunLen
} else if l.Doculint.MinFunLen > desired.Doculint.MinFunLen || l.Doculint.MinFunLen < 0 {
return fmt.Errorf(
"deviation detected from tier minimum defaults in lintroller.doculint.minFunLen, minFunLen must be set within (0, %d]",
"deviation detected from tier minimum defaults in lintroller.doculint.minfunlen, minfunlen must be set within (0, %d]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 184 to 188
for _, ch := range msg {
if unicode.IsUpper(ch) {
isCap = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you just be checking the first character for capitalization?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to George's comment. This should only check the first letter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is where maybe other people's standards and ORCS standards diverge. We make the entire error message lowercase. What is the value in only the first letter being lowercase?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the things that come to my mind immediately are acronyms (ASCII, etc) and abbreviations (ID, etc) and initialisms (UUID, etc)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW i do see where you're going though if we forget about what i just mentioned above @clevelittlefield-outreach

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah people resist on the acronyms, but the whole goal of this is to always find that error in the code/logs and not worry about casing, the first letter alone doesnt provide value

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand where you're coming from. i'm not the owner of this repo anymore (i just know the most about it) and im not on DT, so ultimately I'm going to defer this one over to @jkinkead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea of having standardized style. I don't love the idea of having bespoke standardized style. For a widely-used linter, we should be adhering to established third-party standards.

Google's style guide (what I suggest we use, and what is linked in the linter) says:

Error strings should not be capitalized (unless beginning with an exported name, a proper noun or an acronym) and should not end with punctuation. This is because error strings usually appear within other context before being printed to the user.

It further says:

On the other hand, the style for the full displayed message (logging, test failure, API response, or other UI) depends, but should typically be capitalized.

I don't think this should deviate from this style guide, unless we can find an official Golang one that says something different.

Teams that want a different style that's still compatible with this (e.g. all characters lowercase), that's fine, but I don't think the linter should enforce that rule.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that exception will be hard to codify (unless beginning with an exported name, a proper noun or an acronym), and I dont think we want to have people do nolints to enforce that exception. That rule (not uppercase for first character only) honestly seem like arbitrary aesthetics rather than serving a clear purpose.

I do not understand the further part, we have one string here, how can it be all capitalized in another context?

Beyond that, I swore that gobox (back in go-outreach days) at one time in the readme asked for all lowercase errors. Using that starter guidance, but also building around that idea, is we want all strings of this sort to be able to be found going from code to datadog and from datadog to code. One of those at the time was case sensitive. I would have to test again to see if that is still the case. The point of leaving out casing it so avoid those accidental misses due to case.

If we decide this linter is not right for all of outreach, that is ok. I questioned that when we said it could be outreach wide in the first place because I have seen plenty of code that violates that. We will also have lots of violations when we build a linter for this guideline as well. Which circles back to the original question, how can we build and include in the ruleset a linter just for just the ORCS team?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkinkead thoughts?

Copy link
Contributor

@jkinkead jkinkead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some unit tests, like exist here?

internal/config/tiers.go Show resolved Hide resolved
internal/config/tiers.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/errorlint/errorlint.go Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
Comment on lines 184 to 188
for _, ch := range msg {
if unicode.IsUpper(ch) {
isCap = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to George's comment. This should only check the first letter.

internal/errorlint/errorlint.go Show resolved Hide resolved
internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
internal/config/tiers.go Show resolved Hide resolved
Comment on lines 184 to 188
for _, ch := range msg {
if unicode.IsUpper(ch) {
isCap = true
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is where maybe other people's standards and ORCS standards diverge. We make the entire error message lowercase. What is the value in only the first letter being lowercase?

@nirupama7 nirupama7 marked this pull request as draft January 19, 2023 00:36
Copy link
Contributor

@jkinkead jkinkead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few replies.

internal/config/tiers.go Outdated Show resolved Hide resolved
Comment on lines 184 to 188
for _, ch := range msg {
if unicode.IsUpper(ch) {
isCap = true
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love the idea of having standardized style. I don't love the idea of having bespoke standardized style. For a widely-used linter, we should be adhering to established third-party standards.

Google's style guide (what I suggest we use, and what is linked in the linter) says:

Error strings should not be capitalized (unless beginning with an exported name, a proper noun or an acronym) and should not end with punctuation. This is because error strings usually appear within other context before being printed to the user.

It further says:

On the other hand, the style for the full displayed message (logging, test failure, API response, or other UI) depends, but should typically be capitalized.

I don't think this should deviate from this style guide, unless we can find an official Golang one that says something different.

Teams that want a different style that's still compatible with this (e.g. all characters lowercase), that's fine, but I don't think the linter should enforce that rule.

internal/errorlint/errorlint.go Outdated Show resolved Hide resolved
@nirupama7 nirupama7 marked this pull request as ready for review January 27, 2023 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants