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

Linting #359

Merged
merged 38 commits into from
Aug 16, 2023
Merged

Linting #359

merged 38 commits into from
Aug 16, 2023

Conversation

Choraden
Copy link
Contributor

Fixes #340
Fixes #353

The linter checks if package imports are in a list of acceptable packages.
The linter requires config file `.depguard.yml`. We don't need this at this moment.
The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter. Replaced by unused.
The linter 'interfacer' is deprecated (since v1.38.0) due to: The repository of the linter has been archived by the owner.
The linter 'scopelint' is deprecated (since v1.39.0) due to: The repository of the linter has been deprecated by the owner. Replaced by exportloopref.
The linter 'golint' is deprecated (since v1.41.0) due to: The repository of the linter has been archived by the owner. Replaced by revive.
The linter 'ifshort' is deprecated (since v1.48.0) due to: The repository of the linter has been deprecated by the owner.
@Choraden Choraden force-pushed the hg/linting branch 3 times, most recently from 7ad2fcd to f615a6f Compare August 16, 2023 08:57
@Choraden Choraden force-pushed the hg/linting branch 2 times, most recently from 34a1488 to 2a6cb6d Compare August 16, 2023 10:00
The are many unchecked errors in the martian code. Most of are not dangerous e.g. come from messageview (printing http logs).
Checking all these errors will increase the code complexity and decrease code readability.
Some of the issues need some discussion before the fix:

internal/martian/proxy.go: G402: TLS MinVersion too low. (gosec)
       return &tls.Config{}

internal/martian/mitm/mitm.go: G505: Blocklisted import crypto/sha1: weak cryptographic primitive (gosec)
        "crypto/sha1"

internal/martian/mitm/mitm.go: G401: Use of weak cryptographic primitive (gosec)
        h := sha1.New()
Context key should have custom type to avoid collisions.
- increase number of func statements to 75
- increase allowed lines to 140
Function `func (a *adapter) Data(data []byte, streamEnded bool) error` from `martian/h2/grpc` has 49 complexity.
The linter wrongly interprets comments as code e.g.
// GET http://example.com/ HTTP/1.1
// Host: example.com
Function `func (p *Proxy) handleConnectRequest` has nested if with complexity level 10 - `if p.mitm != nil {...}`.
@Choraden Choraden marked this pull request as ready for review August 16, 2023 10:33
@Choraden
Copy link
Contributor Author

Choraden commented Aug 16, 2023

@mmatczuk I updated the linter and resolved its issues. I tried to split the work into specific commits in case we want to roll something back. If you feel the need to squash them somehow, let me know.

Some of the linters were disabled as they need some discussion before fix, I believe.
Here's the list of the commits. I will create an issue for each one of them, unless you want to say something now.
3edbdb9 - we could wait (e.g. forwarder 1.2) and check if the linter improved
c869381 - discuss how we fix it
ed51261 - separate issue to fix it
7af05d4 - discuss if we fix it
a2a90b7 - leave silenced?

@Choraden Choraden changed the title [WIP] Linting Linting Aug 16, 2023
@mmatczuk
Copy link
Contributor

LGTM

@mmatczuk mmatczuk merged commit f8058bf into main Aug 16, 2023
@mmatczuk mmatczuk deleted the hg/linting branch August 16, 2023 10:52
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.

update linter martian: run linter and modernize
2 participants