contrib/golang-ci-lint/main.go
File main.go
has 520 lines of code (exceeds 500 allowed). Consider refactoring. Open
Open
// Package main provides a tool for downloading and running specific versions of golangci-lint
// across different architectures and repositories. It supports version pinning through
// .golangci-version files and maintains a local cache of downloaded binaries.
//
// Security Features:
Function runLinter
has 9 return statements (exceeds 4 allowed). Open
Open
func runLinter(ctx context.Context, binaryPath, workDir string, args []string) error {
// Validate binary permissions before execution
info, err := os.Stat(binaryPath)
if err != nil {
return fmt.Errorf("checking binary before execution: %w", err)
Function run
has 7 return statements (exceeds 4 allowed). Open
Open
func run(ctx context.Context) error {
// Set secure permissions for file operations
cleanup, err := permissions.SetSecureUmask()
if err != nil {
return fmt.Errorf("failed to set secure permissions: %w", err)
Function extractBinary
has 6 return statements (exceeds 4 allowed). Open
Open
func extractBinary(_ context.Context, tarPath, destPath string) error {
// Validate paths before operations
if err := validatePath(tarPath, os.TempDir()); err != nil {
return fmt.Errorf("invalid tar file path: %w", err)
}
Function downloadFile
has 6 return statements (exceeds 4 allowed). Open
Open
func downloadFile(ctx context.Context, url string, tmpFile *os.File) error {
client := setupHTTPClient()
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return fmt.Errorf("failed to create request: %w", err)
Function createAndCopyBinary
has 5 return statements (exceeds 4 allowed). Open
Open
func createAndCopyBinary(tr *tar.Reader, tmpFile string) error {
var errs []error
// Validate path before file operations
if err := validatePath(tmpFile, os.TempDir()); err != nil {
Function downloadAndExtract
has 5 return statements (exceeds 4 allowed). Open
Open
func downloadAndExtract(ctx context.Context, version, osName, arch, destPath string) error {
tmpFile, err := os.CreateTemp("", "golangci-lint-*.tar.gz")
if err != nil {
return fmt.Errorf("failed to create temp file: %w", err)
}
Function validatePath
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
Open
func validatePath(path string, allowedDirs ...string) error {
// Get repository root using go-findroot
root, err := find.Repo()
if err == nil {
// Add repository root to allowed directories
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function setupLinter
has 5 return statements (exceeds 4 allowed). Open
Open
func setupLinter(ctx context.Context, version, osName, arch string) (string, error) {
root, err := find.Repo()
if err != nil {
return "", fmt.Errorf("failed to get repository root: %w", err)
}
Function validatePath
has 5 return statements (exceeds 4 allowed). Open
Open
func validatePath(path string, allowedDirs ...string) error {
// Get repository root using go-findroot
root, err := find.Repo()
if err == nil {
// Add repository root to allowed directories