-
Notifications
You must be signed in to change notification settings - Fork 118
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
Add lll linter to golangci-lint configuration #868
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.
Thanks for the effort!
Unfortunately, I think it was a bit premature. Mostly because I think this could also be solved with just a visual guide in the IDE, if the linter not being active is a blocker for your workflow (maybe this message got lost in chat yesterday). Secondly, the updated code should follow our lnd
formatting rules (which apply to all our projects), so you'll have to touch a large portion of the diff again...
address/encoding.go
Outdated
@@ -17,10 +17,21 @@ func compressedPubKeyEncoder(w io.Writer, val any, buf *[8]byte) error { | |||
return tlv.NewTypeForEncodingErr(val, "*btcec.PublicKey") | |||
} | |||
|
|||
func compressedPubKeyDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error { | |||
func compressedPubKeyDecoder( |
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'm not sure if spending time on this is really worth doing right now...
My suggestion would be to instead commit the .vscode/settings.json
file to the repo so a ruler is automatically shown (see https://github.com/lightningnetwork/lnd/tree/master/.vscode for example).
Also, please take a look at our formatting rules, we want a much more compact formatting of the function headers: https://github.com/lightningnetwork/lnd/blob/master/docs/code_formatting_rules.md
I have the visual guide active in the IDE. But that doesn't prevent little slip ups. There were literally hundreds of slip ups in the existing code base already. Also I'm aware of the formatting rules. The function headers you refer to were done automatically with https://github.com/segmentio/golines. Let me see if I can fix those automatically as well. Or if we choose not to, that's ok with me as well. I thought the consensus was that it was worth the effort. |
Yes, I know we have quite a few instances where we don't really adhere to the implicit rule. Though in some cases wrapping at 80 characters makes the code quite ugly and less readable. I guess in such cases we should use the
Unfortunately I haven't found a tool that can format the function definitions and calls exactly the way we want... If you do find one that can be configured to what we want, that would be fantastic.
After looking through the PR quickly and seeing how many instances there are (and how many of them I would've disagreed with and/or commented on), I think we perhaps should only fix the most ugly ones (where things are too long by a lot of charactesr) and for the rest just configure the linter to start enforcing from a certain commit onward... |
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.
Slightly offtopic for this PR: But our formatting rules state nothing about linebreaks after dots, e.g.:
unsupportedTapLeafVersion = txscript.
TapscriptLeafVersion(0xf0)
Allowed or heresy?
I would say allowed but I personally try to avoid that style at all cost, as it's quite hard to read IMO. |
8116524
to
15c0c64
Compare
This commit adds the lll linter to the golangci-lint configuration file. This forces the code to be formatted with a maximum line length of 80 and a tab width of 8. The `deadline` configuration is replaced with `timeout`. `deadline` is deprecated since v1.20 and will be removed in v1.57.0. The `new-from-rev` flag allows to run linters only on the files changed since the given revision. Since we can assume that the code adheres to linting standards before said revision there are no old errors that we now ignore and this ensures that new code adheres to the additional restrictions from `lll`.
When using `new-from-rev` the CI linting returns `can't prepare diff by revgrep` because of the shallow checkout.
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.
Nice, thanks for the update. I prefer this approach. We can still fix existing issues in follow-up PRs.
@@ -72,4 +72,4 @@ issues: | |||
- unused | |||
- deadcode | |||
- varcheck | |||
new-from-rev: c118c9095a3175d1d311fa9bf6555b44aa8d3912 | |||
new-from-rev: c723abd3c9db8a6a2f3f1eaa85ce5aefb52c8170 |
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.
nit: could be squashed with previous commit.
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.
LGTM, TIL new-from-rev
👍🏽
The lll linter forces the code to be formatted with a maximum line length of 80 and a tab width of 8.
The
deadline
configuration is replaced withtimeout
.deadline
is deprecated since v1.20 and will be removed in v1.57.0.All line lengths in the repo are fixed where necessary, or ignored by adding a
nolint:lll
directive.