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 to the building pipeline #30896

Merged
merged 21 commits into from
Mar 22, 2022
Merged

Add linter to the building pipeline #30896

merged 21 commits into from
Mar 22, 2022

Conversation

rdner
Copy link
Member

@rdner rdner commented Mar 17, 2022

What does this PR do?

  • Added the mage targets
  • Added the linting configuration
  • Added the steps to Jenkinsfile

WARNING! After merging this PR developers will be forced into fixing all linter issues in the entire files they change.

Why is it important?

The linter proved itself useful in the elastic-agent-libs repository and uncovered some bugs. This will allow us to catch certain problems (e.g. not checked error) before our customers report them.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
    - [ ] I have made corresponding changes to the documentation
    - [ ] I have made corresponding change to the default configuration files
    - [ ] I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

To run the linter on the entire repository (can take minutes to complete and would most likely emit a lot issues

mage lint

Or run against files touched by the difference of the current branch and main (lint last change).

mage llc

Related issues

@rdner rdner added enhancement Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team labels Mar 17, 2022
@rdner rdner requested review from cmacknz and kvch March 17, 2022 13:18
@rdner rdner requested review from a team as code owners March 17, 2022 13:18
@rdner rdner self-assigned this Mar 17, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label Team:Automation Label for the Observability productivity team and removed needs_team Indicates that the issue/PR needs a Team:* label labels Mar 17, 2022
@mergify
Copy link
Contributor

mergify bot commented Mar 17, 2022

This pull request does not have a backport label. Could you fix it @rdner? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 7./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Mar 17, 2022
.golangci.yml Show resolved Hide resolved
.golangci.yml Show resolved Hide resolved
.golangci.yml Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 17, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-03-22T08:41:12.615+0000

  • Duration: 106 min 46 sec

Test stats 🧪

Test Results
Failed 0
Passed 22523
Skipped 1940
Total 24463

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@mergify
Copy link
Contributor

mergify bot commented Mar 17, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b add-linter upstream/add-linter
git merge upstream/main
git push upstream add-linter

@cmacknz
Copy link
Member

cmacknz commented Mar 17, 2022

WARNING! After merging this PR developers will be forced into fixing all linter issues in the entire files they change.

We should communicate the impact of this change to everyone who works on beats, at least the beats-contrib mailing list. Maybe link the PR to show what linters will be enabled.

magefile.go Show resolved Hide resolved
@cmacknz cmacknz self-requested a review March 17, 2022 17:37
@rdner rdner requested a review from a team as a code owner March 18, 2022 14:36
@rdner rdner requested review from a team as code owners March 21, 2022 12:28
@mergify
Copy link
Contributor

mergify bot commented Mar 21, 2022

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b add-linter upstream/add-linter
git merge upstream/main
git push upstream add-linter

dev-tools/templates/.golangci.yml Show resolved Hide resolved
.golangci.yml Show resolved Hide resolved
# Select the Go version to target. The default is '1.13'.
go: "1.17.6"

stylecheck:
Copy link
Member

Choose a reason for hiding this comment

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

For stylecheck (or some other linter) could we check that godoc follows the https://staticcheck.io/docs/checks/#ST1020. Like if you are going to put effort into writing docs for your exported function then follow the Go conventions 😄. FWIW we have that check in go-libaudit (had to disable one of the default excludes).

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually thought it was the default behaviour, I used to see this errors before in one of my previous projects. I tested locally and even with checks: ["all"] for staticcheck and stylecheck it didn't return any errors for missing or malformed go doc strings. I'll investigate further.

Copy link
Member

Choose a reason for hiding this comment

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

It's probably one of the default rules for excluding issues listed in https://golangci-lint.run/usage/configuration#command-line-options. Like maybe EXC0014.

Adding something like this can workaround it:

issues:
  include:
   # If you're going to write a comment follow the conventions.
   # https://go.dev/doc/effective_go#commentary.
   # comment on exported (.+) should be of the form "(.+)..."
   - EXC0014

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add it later as a separate PR, since this is already stable and approved.

.golangci.yml Show resolved Hide resolved
@rdner rdner requested review from v1v, andrewkroh and efd6 March 21, 2022 16:52
@rdner rdner requested a review from cmacknz March 22, 2022 11:22
@matschaffer
Copy link
Contributor

I landed here after hitting lint errors regarding github.com/pkg/errors - looks like it's sufficient to replace calls to

errors.Wrap(err, "error message"))

with

fmt.Errorf("error message: %w", err))

Thought I'd mention it here for confirmation and incase it helps others resolve the replacement.

kush-elastic pushed a commit to kush-elastic/beats that referenced this pull request May 2, 2022
* Added the mage targets
* Added the linting configuration
* Added the steps to Jenkinsfile
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* Added the mage targets
* Added the linting configuration
* Added the steps to Jenkinsfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify enhancement Team:Automation Label for the Observability productivity team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add linting based on the elastic-agent-libs for Beats
8 participants