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

Add linter check support #679

Merged
merged 20 commits into from
Oct 20, 2020
Merged

Add linter check support #679

merged 20 commits into from
Oct 20, 2020

Conversation

rahul2393
Copy link
Contributor

@codecov
Copy link

codecov bot commented Oct 11, 2020

Codecov Report

Merging #679 into master will increase coverage by 7.94%.
The diff coverage is 61.53%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #679      +/-   ##
==========================================
+ Coverage   55.69%   63.64%   +7.94%     
==========================================
  Files          48       48              
  Lines        2027     2027              
==========================================
+ Hits         1129     1290     +161     
+ Misses        766      605     -161     
  Partials      132      132              
Impacted Files Coverage Δ
internal/client/config/config.go 80.64% <ø> (ø)
internal/config/artifact.go 55.00% <0.00%> (ø)
internal/config/db.go 100.00% <ø> (ø)
internal/config/global.go 84.61% <ø> (ø)
internal/config/image.go 100.00% <ø> (ø)
internal/config/report.go 60.60% <ø> (ø)
pkg/detector/library/advisory.go 90.62% <ø> (ø)
pkg/detector/library/bundler/advisory.go 64.70% <ø> (ø)
pkg/detector/library/detect.go 0.00% <ø> (ø)
pkg/detector/ospkg/alpine/alpine.go 94.73% <ø> (ø)
... and 29 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4c3bfb8...eec01fb. Read the comment docs.

.golangci.yaml Show resolved Hide resolved
pkg/vulnerability/vulnerability.go Outdated Show resolved Hide resolved
pkg/vulnerability/vulnerability.go Outdated Show resolved Hide resolved
.github/workflows/test.yaml Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
integration/docker/docker.go Outdated Show resolved Hide resolved
internal/app.go Outdated Show resolved Hide resolved
internal/app.go Outdated Show resolved Hide resolved
pkg/types/vulnerability.go Outdated Show resolved Hide resolved
pkg/scanner/local/scan.go Outdated Show resolved Hide resolved
pkg/report/writer.go Outdated Show resolved Hide resolved
internal/client/run.go Outdated Show resolved Hide resolved
internal/artifact/run.go Outdated Show resolved Hide resolved
.golangci.yaml Outdated
misspell:
locale: US
goimports:
local-prefixes: github.com/rahul23/trivy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
local-prefixes: github.com/rahul23/trivy
local-prefixes: github.com/aquasecurity/trivy

Copy link
Contributor Author

@rahul2393 rahul2393 Oct 15, 2020

Choose a reason for hiding this comment

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

It was for running the linter check in workflow here, reverted

Copy link
Collaborator

@knqyf263 knqyf263 Oct 15, 2020

Choose a reason for hiding this comment

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

Reverted to rahul2393?

internal/artifact/run.go Outdated Show resolved Hide resolved
internal/client/run.go Outdated Show resolved Hide resolved
}
return d
log.Logger.Warnf("unsupported os : %s", osFamily)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... I prefer the previous one. If we follow the linter, return xxx.NewScanner() looks better.

.golangci.yaml Outdated
@@ -65,6 +65,9 @@ issues:
- linters:
- golint
text: "a blank import should be only in a main or test package"
- linters:
- govet
text: "shadow: declaration of"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done,

.golangci.yaml Outdated
misspell:
locale: US
goimports:
local-prefixes: github.com/rahul23/trivy
Copy link
Collaborator

@knqyf263 knqyf263 Oct 15, 2020

Choose a reason for hiding this comment

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

Reverted to rahul2393?

@rahul2393
Copy link
Contributor Author

@knqyf263 Done

@knqyf263
Copy link
Collaborator

@rahul2393 The linter test seems to be failing.

@rahul2393
Copy link
Contributor Author

As I said it will fail, but once merged it will succeed
#679 (comment)
@knqyf263

@rahul2393
Copy link
Contributor Author

Let me know what are next action items now

@knqyf263
Copy link
Collaborator

knqyf263 commented Oct 15, 2020

As I said it will fail

Could you clarify it? I don't get your point yet.

@rahul2393
Copy link
Contributor Author

@knqyf263 see the last commit linters passed here 601d126 so once I revert it, linters will fail but once merged it will pass

@knqyf263
Copy link
Collaborator

No, I meant why it needs to be rahul2393.

@rahul2393
Copy link
Contributor Author

Maybe because the workflow run my forked repo

@knqyf263
Copy link
Collaborator

I also thought so, but I didn't find the clue. And if so, it means PR always fails the linter test.

@rahul2393
Copy link
Contributor Author

@knqyf263 removed that config now I think its good.

@knqyf263
Copy link
Collaborator

We should find out what effect the option has and make sure it's okay to remove it. We have to avoid "we don't know why it fails, but it looks good after removing it" as much as possible.

@rahul2393
Copy link
Contributor Author

@knqyf263 this is to grouping the import in separate lines and disabling local prefixes will not cause issue.
https://stackoverflow.com/a/59964885

@rahul2393
Copy link
Contributor Author

@knqyf263 Check now, added back the local-prefixes goimport and linter issues fixed

@knqyf263
Copy link
Collaborator

knqyf263 commented Oct 18, 2020

Hmm. Please allow me to check that my understanding is correct or not. What you said as follows is not correct, right? Even after it is merged, the grouping still violates the policy, so the test will fail.
#679 (comment)

Also, can we specify github.com/aquasecurity, not github.com/aquasecurity/trivy? The repositories under github.com/aquasecurity are also developed by us, so we can call it local.

@rahul2393
Copy link
Contributor Author

@knqyf263 Done, make sense to add "github.com/aquasecurity" as local prefix.

@knqyf263
Copy link
Collaborator

@rahul2393 What about the first question? Is my understanding correct? I'd like to figure out what was wrong.

@rahul2393
Copy link
Contributor Author

rahul2393 commented Oct 19, 2020

Yes, I was wrong before, if its merged now it will work fine because in all the files the grouping is fine, e.g

  1. go internal packages
  2. third party packages
  3. acquasecurity libs
    all 3 separated by single space, earlier I was wrong because I put forked local prefix although it was passing it was wrong because it was considering "github.com/rahul2393" as local prefix

@knqyf263
Copy link
Collaborator

It makes sense. Thanks! I'll take a look at last.

pkg/detector/ospkg/debian/debian.go Outdated Show resolved Hide resolved
pkg/detector/ospkg/oracle/oracle.go Outdated Show resolved Hide resolved
pkg/detector/ospkg/redhat/redhat.go Outdated Show resolved Hide resolved
Comment on lines 6 to 8
"golang.org/x/xerrors"

"github.com/Masterminds/semver/v3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you group them?

Comment on lines 6 to 8
"golang.org/x/xerrors"

"github.com/Masterminds/semver/v3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines 7 to 11
"golang.org/x/xerrors"

"github.com/google/wire"

"github.com/Masterminds/semver/v3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines 6 to 8
"golang.org/x/xerrors"

"github.com/Masterminds/semver/v3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

Comment on lines 4 to +6
"github.com/urfave/cli/v2"

"github.com/aquasecurity/trivy/internal/config"
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@@ -56,31 +62,31 @@ func (d Detector) Detect(_, osFamily, osName string, _ time.Time, pkgs []ftypes.
return vulns, eosl, nil
}

// nolint: gocyclo
// TODO: fix cyclometic complexity by removing default
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like to know why gocyclo complains default. Is it only about default? Or, even if we remove default and add a new family, will gocyclo complain again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even if you replace the default with a different case, it will complain because by default cyclomatic complexity of 10, and for this function, default branch is adding up to 11

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, removing default doesn't address the root issue. Let's consider it carefully later.

Comment on lines 4 to 8
version "github.com/knqyf263/go-rpm-version"

"golang.org/x/xerrors"

"k8s.io/utils/clock"
Copy link
Collaborator

Choose a reason for hiding this comment

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

grouping

Comment on lines 13 to 16
"golang.org/x/oauth2"
"golang.org/x/xerrors"

"github.com/google/go-github/v28/github"
Copy link
Collaborator

Choose a reason for hiding this comment

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

grouping

Comment on lines 16 to 18
"golang.org/x/xerrors"

"github.com/olekukonko/tablewriter"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

pkg/rpc/retry.go Outdated
Comment on lines 6 to 8
"github.com/cenkalti/backoff"

"github.com/twitchtv/twirp"
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

@rahul2393
Copy link
Contributor Author

@knqyf263 I tried fixing all these issues

@@ -56,31 +62,31 @@ func (d Detector) Detect(_, osFamily, osName string, _ time.Time, pkgs []ftypes.
return vulns, eosl, nil
}

// nolint: gocyclo
// TODO: fix cyclometic complexity by removing default
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, removing default doesn't address the root issue. Let's consider it carefully later.

@knqyf263 knqyf263 merged commit 793a1aa into aquasecurity:master Oct 20, 2020
@knqyf263
Copy link
Collaborator

@rahul2393 Thanks.

liamg pushed a commit that referenced this pull request Jun 7, 2022
* add linter supports

* add only minor version

* use latest version

* Fix println with format issue

* Fix test

* Fix tests

* For slice with unknown length, preallocating the array

* fix code-coverage

* Removed linter rules

* Reverting linter fixes, adding TODO for later

* Ignore linter error for import

* Remove another err var.

* Ignore shadow error

* Fixes

* Fix issue

* Add back goimports local-prefixes

* Update local prefixes

* Removed extra spaces and merge the imports

* more refactoring

* Update photon.go

Co-authored-by: Teppei Fukuda <[email protected]>
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.

2 participants