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

MF-1718 - Use static code analysis in CI #1729

Merged
merged 26 commits into from
Apr 22, 2023

Conversation

AryanGodara
Copy link
Contributor

What does this do?

This PR makes the golangci-lint test pass.

Which issue(s) does this PR fix/relate to?

Resolves #1718

List any changes that modify/break current functionality

Behaviour of some functions has changed, and has to be discussed before finalising

Have you included tests for your changes?

No new tests

Did you document any new/modified functionality?

N/A

Notes

N/A

@dborovcanin dborovcanin changed the title MF-1718 - GolangCI checks need to resolve MF-1718 - Use static code analysis in CI Feb 22, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 1, 2023

Codecov Report

Merging #1729 (39739e0) into master (ffd67ae) will decrease coverage by 0.24%.
The diff coverage is 45.67%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #1729      +/-   ##
==========================================
- Coverage   70.60%   70.37%   -0.24%     
==========================================
  Files         146      146              
  Lines       11421    11425       +4     
==========================================
- Hits         8064     8040      -24     
- Misses       2716     2733      +17     
- Partials      641      652      +11     
Impacted Files Coverage Δ
auth/keys.go 100.00% <ø> (ø)
auth/postgres/groups.go 61.52% <0.00%> (-0.81%) ⬇️
auth/service.go 74.39% <0.00%> (ø)
bootstrap/service.go 83.10% <ø> (ø)
lora/adapter.go 60.00% <0.00%> (ø)
pkg/sdk/go/keys.go 0.00% <ø> (ø)
readers/mongodb/messages.go 85.36% <0.00%> (-2.29%) ⬇️
readers/postgres/messages.go 83.49% <0.00%> (-1.80%) ⬇️
readers/timescale/messages.go 83.00% <0.00%> (-1.85%) ⬇️
things/postgres/things.go 67.34% <0.00%> (-1.13%) ⬇️
... and 14 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@AryanGodara AryanGodara marked this pull request as ready for review April 2, 2023 11:15
@AryanGodara AryanGodara requested a review from a team as a code owner April 2, 2023 11:15
auth/api/grpc/endpoint.go Outdated Show resolved Hide resolved
tools/mqtt-bench/results.go Outdated Show resolved Hide resolved
tools/mqtt-bench/bench.go Outdated Show resolved Hide resolved
tools/mqtt-bench/bench.go Outdated Show resolved Hide resolved
tools/mqtt-bench/bench.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@dborovcanin dborovcanin left a comment

Choose a reason for hiding this comment

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

Please update the linter version in CI script and extract it to the variable (like GOLANGCI_LINT_VERSION=v1.52.2). Also, please check the linter config here and find the best combination of linters for us.

@AryanGodara
Copy link
Contributor Author

AryanGodara commented Apr 3, 2023

Please update the linter version in CI script and extract it to the variable (like GOLANGCI_LINT_VERSION=v1.52.2). Also, please check the linter config here and find the best combination of linters for us.

Removing deadcode as it's abandoned by the user, and is replaced by unused
Adding errcheck to make sure no error is ignored (unless by choice)
goconst can be useful -> Find repeated strings that can be replaced with constant

These two can be useful :-
unconvert -> Reports unnecessary type conversions
unparam -> Reports unused function parameters
ineffassign -> check ineffectual assignments (May cause lots of failed CIs as this is very strict checker)

@AryanGodara AryanGodara force-pushed the golangci-resolve branch 3 times, most recently from fe294ae to 21c55cc Compare April 4, 2023 13:30
auth/api/grpc/setup_test.go Outdated Show resolved Hide resolved
auth/api/grpc/setup_test.go Outdated Show resolved Hide resolved
auth/api/grpc/setup_test.go Outdated Show resolved Hide resolved
auth/api/grpc/setup_test.go Outdated Show resolved Hide resolved
auth/postgres/groups.go Outdated Show resolved Hide resolved
readers/mongodb/messages.go Outdated Show resolved Hide resolved
readers/timescale/messages.go Outdated Show resolved Hide resolved
things/postgres/things.go Outdated Show resolved Hide resolved
tools/mqtt-bench/bench.go Outdated Show resolved Hide resolved
@AryanGodara AryanGodara force-pushed the golangci-resolve branch 2 times, most recently from 6020ca8 to 9aded14 Compare April 5, 2023 21:34
lora/mqtt/sub.go Outdated Show resolved Hide resolved
opcua/gopcua/subscribe.go Outdated Show resolved Hide resolved
readers/cassandra/messages.go Outdated Show resolved Hide resolved
readers/mocks/messages.go Outdated Show resolved Hide resolved
readers/postgres/messages.go Outdated Show resolved Hide resolved
things/redis/streams.go Outdated Show resolved Hide resolved
things/redis/streams.go Outdated Show resolved Hide resolved
things/redis/streams.go Outdated Show resolved Hide resolved
things/redis/streams.go Outdated Show resolved Hide resolved
tools/mqtt-bench/bench.go Outdated Show resolved Hide resolved
auth/api/grpc/setup_test.go Outdated Show resolved Hide resolved
auth/api/grpc/setup_test.go Outdated Show resolved Hide resolved
@@ -169,13 +169,14 @@ func loadCertificates(conf config, logger mflog.Logger) (tls.Certificate, *x509.
}

block, _ := pem.Decode(b)
if block == nil {
switch block {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Using if in this case is fine, preferable even. What was linter's remark?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was not happy with the block == nil {}, so I had to change the format to reverse the check to block != nil

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you, please, send me the exact golangci-lint command to test this? The command we have in CI script (golangci-lint run --no-config --disable-all --enable gosimple --enable errcheck --enable govet --enable unused --enable goconst --timeout 3m) does not show me any problems with original code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is no longer highlighted after updating the linter, so I've reverted back to original.
Maybe they fixed the linter in the update.
But when I use the original

        block, _ := pem.Decode(b)
	if block == nil {
		logger.Fatal("No PEM data found, failed to decode CA")
	}

	caCert, err = x509.ParseCertificate(block.Bytes)    <--- IDE warns here about possible nil pointer dereference even after checking for nil above
	if err != nil {
		return tlsCert, caCert, errors.Wrap(errFailedCertDecode, err)
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dborovcanin Should I leave this as it was(original code) or change to switch statement?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep it as it is.

@AryanGodara AryanGodara force-pushed the golangci-resolve branch 2 times, most recently from 4169b81 to 2ecced5 Compare April 12, 2023 22:17
tools/mqtt-bench/bench.go Outdated Show resolved Hide resolved
twins/api/http/endpoint_twins_test.go Outdated Show resolved Hide resolved
bootstrap/api/endpoint_test.go Outdated Show resolved Hide resolved
bootstrap/redis/producer/streams_test.go Outdated Show resolved Hide resolved
bootstrap/service.go Outdated Show resolved Hide resolved
scripts/ci.sh Outdated Show resolved Hide resolved
auth/service_test.go Show resolved Hide resolved
auth/jwt/tokenizer.go Outdated Show resolved Hide resolved
auth/postgres/groups.go Outdated Show resolved Hide resolved
auth/service.go Outdated Show resolved Hide resolved
auth/service_test.go Show resolved Hide resolved
bootstrap/redis/producer/streams.go Outdated Show resolved Hide resolved
@@ -169,13 +169,14 @@ func loadCertificates(conf config, logger mflog.Logger) (tls.Certificate, *x509.
}

block, _ := pem.Decode(b)
if block == nil {
switch block {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you, please, send me the exact golangci-lint command to test this? The command we have in CI script (golangci-lint run --no-config --disable-all --enable gosimple --enable errcheck --enable govet --enable unused --enable goconst --timeout 3m) does not show me any problems with original code.

readers/cassandra/messages.go Outdated Show resolved Hide resolved
readers/mocks/messages.go Outdated Show resolved Hide resolved
readers/timescale/messages.go Outdated Show resolved Hide resolved
@AryanGodara AryanGodara force-pushed the golangci-resolve branch 2 times, most recently from e5e6e2d to 3f7eddd Compare April 18, 2023 20:44
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Signed-off-by: aryan <aryangodara03@gmail.com>
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit 54c7518 into absmach:master Apr 22, 2023
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.

Use static code analysis in CI
5 participants