-
Notifications
You must be signed in to change notification settings - Fork 11
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
golang-ci: Enable lll (long lines) linter and fix issues #615
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the addition, but there's some shady stuff in the diff. Can you take a double look at the corrections and make sure we don't have some weird formatting?
Set the long lines linter to block lines longer than 120 chars an fix the cases in which we were not respecting this limit. This was somewhat mentioned during the sprint, and I wanted to finally tackle it :)
39dfb18
to
b69a639
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #615 +/- ##
==========================================
- Coverage 82.99% 82.91% -0.08%
==========================================
Files 80 80
Lines 8584 8633 +49
Branches 75 75
==========================================
+ Hits 7124 7158 +34
- Misses 1129 1141 +12
- Partials 331 334 +3 ☔ View full report in Codecov by Sentry. |
I would prefer to not enforce the line length via the linter. I'm in favor of agreeing on a guideline regarding line length (e.g. "try to keep lines shorter than 120 chars, in multi-line comments shorter than 80") but there are common cases where I think a long line actually makes the code more readable than a introducing a line break. For example when printing log messages, I prefer: log.Warningf(context.Background(), "Failed to get current executable path, not adding it as a config dir: %v", err) over
And I very much prefer not wrapping the log message itself, because that makes it harder to find the code which prints a given message. Another case where I prefer longer lines is function signatures. For example, this PR contains this diff: -func (b *Broker) NewSession(ctx context.Context, username, lang, mode string) (sessionID, encryptionKey string, err error) {
+func (b *Broker) NewSession(ctx context.Context, username, lang, mode string) (
+ sessionID, encryptionKey string, err error) {
sessionID = uuid.New().String()
info := sessionInfo{ With that change, the second line of the function signature has the same indent as the function body, which makes it hard to recognize it as part of the function signature. |
I've not played too much with linter settings but I feel it could be possible to avoid specific cases. I can understand the functions signatures though, but I still feel that logging is better to read when split. In case you rely on grep using |
My grep doesn't know about a
Also I read and navigate code in an IDE, which does not find strings when they are separated by a newline (and other characters to concatenate the two substrings). |
I meant |
That doesn't help me when I have an error message
When I search for "You have insufficient privileges to access this resource", I won't find the code which prints it. |
Fully agreed this is a desired behaviour and my issue too with splitting such lines. |
Set the long lines linter to block lines longer than 120 chars an fix the cases in which we were not respecting this limit.
This was somewhat mentioned during the sprint, and I wanted to finally tackle it :)