-
-
Notifications
You must be signed in to change notification settings - Fork 112
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 GolangCI Lint Configuration for Better Code Quality #1078
Conversation
Important Cloud Posse Engineering Team Review RequiredThis pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes. To expedite this process, reach out to us on Slack in the |
Let us add the makefile command for easy access on local dev environment |
📝 WalkthroughWalkthroughThe changes introduce a new GitHub Actions job to run Changes
Suggested labels
Possibly related PRs
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
🔇 Additional comments (7)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🔭 Outside diff range comments (1)
.github/workflows/test.yml (1)
492-499
:⚠️ Potential issueUpdate release job dependencies.
The release job's needs section should include the new 'lint-golangci' job.
Apply this change:
release: - needs: [test, lint, mock, k3s, localstack, docker, validate] + needs: [test, lint, mock, k3s, localstack, docker, validate, lint-golangci] if: github.event_name == 'push' uses: cloudposse/.github/.github/workflows/shared-go-auto-release.yml@main with: publish: false format: binary
🧹 Nitpick comments (2)
pkg/utils/log_utils.go (1)
32-86
: Consider consolidating deprecated functions.While marking functions as deprecated is good practice, consider consolidating these utility functions into a single deprecated wrapper that internally calls the new logging functions. This would reduce code duplication and make future removal easier.
Example consolidation:
// Deprecated: Use the log package directly. These utilities will be removed in a future release. type DeprecatedLogger struct{} func (d DeprecatedLogger) PrintErrorInColor(message string) { messageColor := theme.Colors.Error _, _ = messageColor.Fprint(os.Stderr, message) } func (d DeprecatedLogger) LogErrorAndExit(err error) { log.Error(err) var exitError *exec.ExitError if errors.As(err, &exitError) { os.Exit(exitError.ExitCode()) } os.Exit(1) } // ... other methods ... // Provide a single instance var Legacy = DeprecatedLogger{}.github/workflows/test.yml (1)
480-491
: Consider optimizing the lint job configuration.The lint job setup looks good, but a few optimizations could be made:
- Full history fetch might not be necessary for linting
- Consider adding a configuration file path
Suggested changes:
lint-golangci: name: runner / golangci-lint runs-on: ubuntu-latest steps: - name: Check out code into the Go module directory uses: actions/checkout@v4 - with: - fetch-depth: 0 - name: Lint with golangci-lint uses: reviewdog/action-golangci-lint@v2 + with: + golangci_lint_flags: "--config=.golangci.yml"
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.github/workflows/test.yml
(1 hunks)Brewfile
(1 hunks)pkg/utils/log_utils.go
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
- GitHub Check: [mock-macos] tests/fixtures/scenarios/complete
- GitHub Check: [mock-macos] examples/demo-vendoring
- GitHub Check: [mock-windows] tests/fixtures/scenarios/complete
- GitHub Check: [mock-windows] examples/demo-vendoring
- GitHub Check: [mock-windows] examples/demo-context
- GitHub Check: [mock-windows] examples/demo-component-versions
- GitHub Check: [mock-linux] examples/demo-vendoring
- GitHub Check: [localstack] demo-localstack
- GitHub Check: Acceptance Tests (macos-latest, macos)
- GitHub Check: Acceptance Tests (windows-latest, windows)
- GitHub Check: Acceptance Tests (ubuntu-latest, linux)
- GitHub Check: [k3s] demo-helmfile
- GitHub Check: Summary
🔇 Additional comments (2)
Brewfile (1)
2-2
: LGTM! Adding golangci-lint dependency.The addition of golangci-lint to the Brewfile ensures consistent linting tooling across development environments.
pkg/utils/log_utils.go (1)
10-10
: LGTM! More descriptive package alias.Changed from 'l' to 'log' which improves code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looking at timeout error for golang-ci. |
We definitely do not want to break website out. It's critical that every new feature is documented, and that doesn't happen when it requires 2 PRs. Can you elaborate on the problem? |
Agreed
I mean the problem is not so critical to be solved it was just more of linters, file watchers load reduction. But we have workarounds for that so all good. |
6c1b5ec
To run it locally, do one of: Lint files that have changed (for me it erroneously includes unstaged files)
Lint only go files in VCS:
Note, we have a lot of clean up to do. |
These changes were released in v1.163.0. |
what
This PR improves our
golangci-lint
configuration to enforce better coding standards, catch common mistakes, and ensure consistency in our Go codebase.Function Length Enforcement (
funlen
)Forbidden Function Calls (
forbidigo
)Enabling Additional Linters
gocritic
: Adds several static analysis checks for code quality.errcheck
: Ensures all errors are properly handled.gofumpt
: Standardizes formatting beyondgofmt
.govet
: Detects suspicious constructs.staticcheck
: Flags performance and correctness issues.revive
: A configurable linter for Go.misspell
: Detects common spelling mistakes.Custom
gocritic
ChecksrangeValCopy
: Detects unnecessary copies in range loops.hugeParam
: Warns on large parameters that should be passed by reference.commentedOutCode
: Finds commented-out code blocks.nestingReduce
: Suggests ways to reduce nesting complexity.preferFilepathJoin
: Enforces usingfilepath.Join()
instead of manual concatenation.Excludes Test Files from Function Length Check (
funlen
)_test.go
) are ignored for function length enforcement.Output Formatting Improved
Why
Summary by CodeRabbit