karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.47k stars 885 forks source link

Add go fmt to make verify Target to Ensure Code Formatting before commiting and pushing changes #5347

Open yashpandey06 opened 2 months ago

yashpandey06 commented 2 months ago

Title: Add go fmt to make verify Target to Ensure Code Formatting

Description:

To improve the development workflow and ensure consistent code formatting, I propose adding a step to run go fmt across the entire codebase within the make verify target. This change will automatically format Go source files, helping contributors avoid committing unformatted code, reducing unnecessary commit noise, and improving the overall code quality.

Motivation:

  1. Prevent Linting Errors: New contributors may occasionally forget to format their code before pushing commits. By running go fmt as part of make verify, we can ensure that code is consistently formatted, reducing the likelihood of linting errors related to formatting.
  2. Avoid Extra Commits: Automatically formatting code before committing prevents the need for extra "fix formatting" commits, leading to a cleaner commit history.
  3. Simplify Development Workflow: Developers won’t need to worry about formatting as a separate step, making the development process more seamless and allowing them to focus on writing code.

Proposed Changes:

Updated Makefile:


.PHONY: fmt verify

fmt:
    @echo "Formatting Go files..."
    go fmt ./...

verify: fmt
    @echo "Running verification tasks..."
    hack/verify-all.sh
yashpandey06 commented 2 months ago

@XiShanYongYe-Chang I've faced some challenges with code formatting as a contributor and believe this can be effectively addressed by enhancing our Makefile and automate formatting task. Specifically, I propose adding go fmt to the make verify target. This adjustment could streamline our workflow and ensure consistent code formatting.

If you find this approach promising, I'd appreciate discussing it further to work on a solution together.

XiShanYongYe-Chang commented 2 months ago

Hi @yashpandey06 thanks for your feedback. For developers, you only need to ensure that the current content submitted by yourself passes through go fmt. This can be achieved by configuring in the code editor. When the file is saved, go fmt is automatically performed. Performing go fmt on the entire repository will do a lot of useless work. These are some of my thoughts.

yashpandey06 commented 2 months ago

Hi @yashpandey06 thanks for your feedback. For developers, you only need to ensure that the current content submitted by yourself passes through go fmt. This can be achieved by configuring in the code editor. When the file is saved, go fmt is automatically performed. Performing go fmt on the entire repository will do a lot of useless work. These are some of my thoughts.

@XiShanYongYe-Chang well, noted that thanks for your kind suggestion .