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

fix: Clean up golangci-lint config #7194

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mateusoliveira43
Copy link
Contributor

@mateusoliveira43 mateusoliveira43 commented Dec 10, 2023

Please add a summary of your change

Clean up of golangci-lint config file:

Also:

  • Delete unnecessary scripts (golangci-lint already does that)
  • Update documentation around linter (which was outdated)
  • sorted things alphabetically to more easy read of the config

This PR would also change golangci-lint config file to default name and add golangci-lint github action, which was already done in 884bcbe and rebased on top of it.

Does your change fix a particular issue?

Related to #6023

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

Copy link

codecov bot commented Jan 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.20%. Comparing base (ba0dbb9) to head (66c51fb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7194   +/-   ##
=======================================
  Coverage   59.20%   59.20%           
=======================================
  Files         367      367           
  Lines       30838    30838           
=======================================
  Hits        18259    18259           
  Misses      11119    11119           
  Partials     1460     1460           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kaovilai
Copy link
Contributor

kaovilai commented Jan 9, 2024

Why use make lint-fix over make update?

@kaovilai
Copy link
Contributor

kaovilai commented Jan 9, 2024

make update is how we today make sure the format satisfy the ci lint. If make lint-fix is replacing that flow then note that in the PR description.

@kaovilai
Copy link
Contributor

kaovilai commented Jan 9, 2024

This PR breaks make update by removing hack/update-1fmt.sh that is relied upon by

update:
	@$(MAKE) shell CMD="-c 

> 'hack/update-all.sh'"

https://github.com/vmware-tanzu/velero/blob/dcd4392744b10cde4984de7d1a423aff3dd74fa5/Makefile#L234C1-L235C46

which runs

for f in ${HACK_DIR}/update-*.sh; do
  if [[ $f = "${HACK_DIR}/update-all.sh" ]]; then
    continue
  fi
  $f
done

https://github.com/vmware-tanzu/velero/blob/dcd4392744b10cde4984de7d1a423aff3dd74fa5/hack/update-all.sh

Correct me if I'm wrong but is this PR created because you were not aware of the make update?

If this PR merge, we now have to run make update lint-fix instead to fix lint and generate CRDs etc.

@mateusoliveira43
Copy link
Contributor Author

@kaovilai I did not intend to change make update at first. That command would run gofmt and goimports (which is a different thing then generating files) and generate files, right?

I removed hack/update-1fmt.sh because we would be doing the same thing twice (with the script and with golangci-lint). make-lint-fix only replaces the formatting script, still need to run make update for the scenarios described in documentation https://github.com/vmware-tanzu/velero/blob/main/site/content/docs/main/development.md#update-generated-files

Run make update to regenerate files if you make the following changes:

  • Add/edit/remove command line flags and/or their help text
  • Add/edit/remove commands or subcommands
  • Add new API types
  • Add/edit/remove plugin protobuf message or service definitions

So, removed the script for both semantic and performance.

Since update-all script runs a for loop, I just removed a item from the list, but it will still work (example is Pull Request CI Check for this PR).

No no, my intention was to clean up config file for golangci-lint. There was unused config (for example, linters-settings for linters not enabled, enabled linters without config, etc), found the other issues along the way. I would be ok to break the PR in smaller ones.

Added to PR description a note about removal of scripts.

@kaovilai
Copy link
Contributor

kaovilai commented Jan 9, 2024

I just removed a item from the list, but it will still work

Just in github actions because it's covered by golangci-lint? or also locally on dev machine for lint formatting.

Is the expectation that make update should still format lint on local dev machine?

@mateusoliveira43
Copy link
Contributor Author

@tiger oh no, make update will not format Go code anymore (but as it was, it would not run all linters defined in golangci-lint config file, only gofmt and goimport. So, in the past running make update would not guarantee CI would pass)

@kaovilai
Copy link
Contributor

make update will not format Go code anymore
So, in the past running make update would not guarantee CI would pass)

So now we run make update lint-fix before making PR to guarantee CRD generation and also lint right?

@mateusoliveira43
Copy link
Contributor Author

@kaovilai that's right!

hack/update-1fmt.sh Outdated Show resolved Hide resolved
@weshayutin
Copy link
Contributor

@reasonerjt @sseago as you have time can please weigh in on linting :)

@mateusoliveira43
Copy link
Contributor Author

@mmorel-35 could you please review?

hack/lint.sh Show resolved Hide resolved

Use `lint-all` to run the linter against the entire code base.
You can run `make lint-fix` to fix fixable issues found by `make lint`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would link fixable issues table here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is not such table

here https://golangci-lint.run/usage/linters/ shows all linters (but this is related only for last release) and those that have ✅ in AutoFix column, are the ones that can be fixable

@kaovilai kaovilai mentioned this pull request Mar 29, 2024
3 tasks
@mmorel-35
Copy link
Contributor

mmorel-35 commented Mar 30, 2024

@mmorel-35 could you please review?

I'll start with I believe will get this merged. Please move everything that it unrelated to most important scope of this PR.

For example, move golangci-lint config but don't change it's content. Also don't fix linters issues inside golang files.
You can create create a second PR to modify the content of golangci config and a third to address the fix of a linter.

After this is done. Things are going to be really easier for reviewers.

Do one thing at a time that will greatly help others follow your move.

This seems quite promising but is really too huge to not miss something for a reviewer

.golangci.yaml Outdated Show resolved Hide resolved
.golangci.yaml Outdated Show resolved Hide resolved
.golangci.yaml Outdated Show resolved Hide resolved
.golangci.yaml Outdated Show resolved Hide resolved
@$(MAKE) shell CMD="-c 'hack/lint.sh'"
endif

local-lint:
lint-fix:
Copy link
Contributor

@mmorel-35 mmorel-35 May 16, 2024

Choose a reason for hiding this comment

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

Isn’t it more common to use make fmt or make format instead ?

You can also define a make verify and reuse it as a prerequisite for lint and fmt targets , wdyt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since its inside an if, I think we will write less code by being explicit here instead of writing a new command verify-config and adding it to the 2 lint commands

From what I am familiar (example https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4/Makefile#L55) fmt command is commonly used to call go fmt. Since golangci-lint does more than that, and the non fix command already contains lint in its name, I think lint-fix would make more sense here

.golangci.yaml Outdated Show resolved Hide resolved
hack/verify-lint-config.sh Outdated Show resolved Hide resolved
Signed-off-by: Mateus Oliveira <[email protected]>
explicitly exclude pkg/plugin/generated

Signed-off-by: Mateus Oliveira <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants