-
Notifications
You must be signed in to change notification settings - Fork 90
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 a linter to catch fmt.Print* #4782
Conversation
WalkthroughThe pull request introduces a configuration change in the Changes
Poem
🪧 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
CodeRabbit Configuration File (
|
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
🧹 Nitpick comments (1)
.golangci.yml (1)
10-12
: Add documentation for the linting ruleWhile the pattern correctly catches all fmt.Print* variants, it would be helpful to add a description explaining why these functions are forbidden and what alternatives should be used instead.
forbidigo: forbid: - - 'fmt\.Print.*' # This will catch Printf, Println, Print + - p: 'fmt\.Print.*' + msg: "Please use zerolog instead of fmt.Print* for logging. See logging.md for guidelines."
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pkg/config/types/gen/generate.go
is excluded by!**/gen/**
📒 Files selected for processing (2)
.golangci.yml
(2 hunks)main.go
(0 hunks)
💤 Files with no reviewable changes (1)
- main.go
🔇 Additional comments (2)
.golangci.yml (2)
10-12
: Verify impact on existing codebase
The linter configuration looks good, but let's assess its impact on the existing codebase.
Run this script to find existing fmt.Print* usage that will be affected:
Also applies to: 76-76
✅ Verification successful
Let me check the specific usage context in these files to ensure they are only in test files.
Linter rule impact is limited to test files only
The fmt.Print*
usage appears exclusively in test files and test utilities:
- All occurrences are in files with
_test.go
suffix or in test integration utilities - Used primarily for debugging and test output purposes
- No production code is affected
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Find all fmt.Print* usage in the codebase to assess the impact
# Search for fmt.Print* usage
echo "Files containing fmt.Print* calls:"
rg -l 'fmt\.(Print|Printf|Println)\b' --type go
# Count total occurrences
echo -e "\nTotal occurrences by type:"
rg -c 'fmt\.(Print|Printf|Println)\b' --type go | grep -v ':0$'
Length of output: 635
Script:
#!/bin/bash
# Show the context of fmt.Print* usage in each file
echo "=== Checking usage context ==="
rg 'fmt\.(Print|Printf|Println)\b' --type go -C 2
Length of output: 3071
76-76
: LGTM! Verify linter compatibility
The forbidigo linter is correctly enabled and properly positioned in alphabetical order.
Let's verify if there are any potential conflicts with other enabled linters:
✅ Verification successful
Let me try a different approach to verify the linter compatibility.
Linter compatibility verified - no conflicts detected
The forbidigo linter is properly configured with a specific rule to forbid fmt.Print*
functions. The configuration is well-integrated with other linters, and there are no overlapping or conflicting rules with other enabled linters in the configuration. The linter's position in the enabled list and its configuration are both correct.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any known conflicts or issues between forbidigo and other enabled linters
# Search for any reported issues or conflicts
gh api graphql -f query='
{
search(query: "repo:golangci/golangci-lint forbidigo conflict", type: ISSUE, first: 5) {
nodes {
... on Issue {
title
url
state
}
}
}
}'
Length of output: 261
Script:
#!/bin/bash
# Check the current configuration and other enabled linters
cat .golangci.yml
# Also check if there are any specific configurations for forbidigo
rg -A 5 "forbidigo" .golangci.yml
Length of output: 4749
Summary by CodeRabbit
New Features
Bug Fixes
fmt
package usage to streamline output.