synapsecns/sanguine

View on GitHub
contrib/golang-ci-lint/main.go

Summary

Maintainability
C
1 day
Test Coverage

File main.go has 520 lines of code (exceeds 500 allowed). Consider refactoring.
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:
Severity: Minor
Found in contrib/golang-ci-lint/main.go - About 2 hrs to fix

    Function runLinter has 9 return statements (exceeds 4 allowed).
    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)
    Severity: Major
    Found in contrib/golang-ci-lint/main.go - About 55 mins to fix

      Function run has 7 return statements (exceeds 4 allowed).
      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)
      Severity: Major
      Found in contrib/golang-ci-lint/main.go - About 45 mins to fix

        Function extractBinary has 6 return statements (exceeds 4 allowed).
        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)
            }
        Severity: Major
        Found in contrib/golang-ci-lint/main.go - About 40 mins to fix

          Function downloadFile has 6 return statements (exceeds 4 allowed).
          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)
          Severity: Major
          Found in contrib/golang-ci-lint/main.go - About 40 mins to fix

            Function createAndCopyBinary has 5 return statements (exceeds 4 allowed).
            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 {
            Severity: Major
            Found in contrib/golang-ci-lint/main.go - About 35 mins to fix

              Function downloadAndExtract has 5 return statements (exceeds 4 allowed).
              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)
                  }
              Severity: Major
              Found in contrib/golang-ci-lint/main.go - About 35 mins to fix

                Function validatePath has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
                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
                Severity: Minor
                Found in contrib/golang-ci-lint/main.go - About 35 mins to fix

                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

                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)
                    }
                Severity: Major
                Found in contrib/golang-ci-lint/main.go - About 35 mins to fix

                  Function validatePath has 5 return statements (exceeds 4 allowed).
                  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
                  Severity: Major
                  Found in contrib/golang-ci-lint/main.go - About 35 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status